oculus1

diff libovr/Src/Kernel/OVR_SysFile.cpp @ 3:b069a5c27388

added a couple more stuff, fixed all the LibOVR line endings
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 15 Sep 2013 04:10:05 +0300
parents e2f9e4603129
children
line diff
     1.1 --- a/libovr/Src/Kernel/OVR_SysFile.cpp	Sat Sep 14 17:51:03 2013 +0300
     1.2 +++ b/libovr/Src/Kernel/OVR_SysFile.cpp	Sun Sep 15 04:10:05 2013 +0300
     1.3 @@ -1,1 +1,125 @@
     1.4 -/**************************************************************************
     1.5 
     1.6 Filename    :   OVR_SysFile.cpp
     1.7 Content     :   File wrapper class implementation (Win32)
     1.8 
     1.9 Created     :   April 5, 1999
    1.10 Authors     :   Michael Antonov
    1.11 
    1.12 Copyright   :   Copyright 2011 Oculus VR, Inc. All Rights reserved.
    1.13 
    1.14 Use of this software is subject to the terms of the Oculus license
    1.15 agreement provided at the time of installation or download, or which
    1.16 otherwise accompanies this software in either electronic or hard copy form.
    1.17 
    1.18 **************************************************************************/
    1.19 
    1.20 #define  GFILE_CXX
    1.21 
    1.22 // Standard C library (Captain Obvious guarantees!)
    1.23 #include <stdio.h>
    1.24 
    1.25 #include "OVR_SysFile.h"
    1.26 
    1.27 namespace OVR {
    1.28 
    1.29 // This is - a dummy file that fails on all calls.
    1.30 
    1.31 class UnopenedFile : public File
    1.32 {
    1.33 public:
    1.34     UnopenedFile()  { }
    1.35     ~UnopenedFile() { }
    1.36 
    1.37     virtual const char* GetFilePath()               { return 0; }
    1.38 
    1.39     // ** File Information
    1.40     virtual bool        IsValid()                   { return 0; }
    1.41     virtual bool        IsWritable()                { return 0; }
    1.42 
    1.43     // Return position / file size
    1.44     virtual int         Tell()                      { return 0; }
    1.45     virtual SInt64      LTell()                     { return 0; }
    1.46     virtual int         GetLength()                 { return 0; }
    1.47     virtual SInt64      LGetLength()                { return 0; }
    1.48 
    1.49 //  virtual bool        Stat(FileStats *pfs)        { return 0; }
    1.50     virtual int         GetErrorCode()              { return Error_FileNotFound; }
    1.51 
    1.52     // ** Stream implementation & I/O
    1.53     virtual int         Write(const UByte *pbuffer, int numBytes)     { return -1; OVR_UNUSED2(pbuffer, numBytes); }
    1.54     virtual int         Read(UByte *pbuffer, int numBytes)            { return -1; OVR_UNUSED2(pbuffer, numBytes); }
    1.55     virtual int         SkipBytes(int numBytes)                       { return 0;  OVR_UNUSED(numBytes); }
    1.56     virtual int         BytesAvailable()                              { return 0; }
    1.57     virtual bool        Flush()                                       { return 0; }
    1.58     virtual int         Seek(int offset, int origin)                  { return -1; OVR_UNUSED2(offset, origin); }
    1.59     virtual SInt64      LSeek(SInt64 offset, int origin)              { return -1; OVR_UNUSED2(offset, origin); }
    1.60     
    1.61     virtual int         CopyFromStream(File *pstream, int byteSize)   { return -1; OVR_UNUSED2(pstream, byteSize); }
    1.62     virtual bool        Close()                                       { return 0; }    
    1.63 };
    1.64 
    1.65 
    1.66 
    1.67 // ***** System File
    1.68 
    1.69 // System file is created to access objects on file system directly
    1.70 // This file can refer directly to path
    1.71 
    1.72 // ** Constructor
    1.73 SysFile::SysFile() : DelegatedFile(0)
    1.74 {
    1.75     pFile = *new UnopenedFile;
    1.76 }
    1.77 
    1.78 File* FileFILEOpen(const String& path, int flags, int mode);
    1.79 
    1.80 // Opens a file
    1.81 SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0)
    1.82 {
    1.83     Open(path, flags, mode);
    1.84 }
    1.85 
    1.86 
    1.87 // ** Open & management
    1.88 // Will fail if file's already open
    1.89 bool SysFile::Open(const String& path, int flags, int mode)
    1.90 {
    1.91     pFile = *FileFILEOpen(path, flags, mode);
    1.92     if ((!pFile) || (!pFile->IsValid()))
    1.93     {
    1.94         pFile = *new UnopenedFile;
    1.95         return 0;
    1.96     }
    1.97     //pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing
    1.98     if (flags & Open_Buffered)
    1.99         pFile = *new BufferedFile(pFile);
   1.100     return 1;
   1.101 }
   1.102 
   1.103 
   1.104 // ** Overrides
   1.105 
   1.106 int SysFile::GetErrorCode()
   1.107 {
   1.108     return pFile ? pFile->GetErrorCode() : Error_FileNotFound;
   1.109 }
   1.110 
   1.111 
   1.112 // Overrides to provide re-open support
   1.113 bool SysFile::IsValid()
   1.114 {
   1.115     return pFile && pFile->IsValid();
   1.116 }
   1.117 bool SysFile::Close()
   1.118 {
   1.119     if (IsValid())
   1.120     {
   1.121         DelegatedFile::Close();
   1.122         pFile = *new UnopenedFile;
   1.123         return 1;
   1.124     }
   1.125     return 0;
   1.126 }
   1.127 
   1.128 } // OVR
   1.129 \ No newline at end of file
   1.130 +/**************************************************************************
   1.131 +
   1.132 +Filename    :   OVR_SysFile.cpp
   1.133 +Content     :   File wrapper class implementation (Win32)
   1.134 +
   1.135 +Created     :   April 5, 1999
   1.136 +Authors     :   Michael Antonov
   1.137 +
   1.138 +Copyright   :   Copyright 2011 Oculus VR, Inc. All Rights reserved.
   1.139 +
   1.140 +Use of this software is subject to the terms of the Oculus license
   1.141 +agreement provided at the time of installation or download, or which
   1.142 +otherwise accompanies this software in either electronic or hard copy form.
   1.143 +
   1.144 +**************************************************************************/
   1.145 +
   1.146 +#define  GFILE_CXX
   1.147 +
   1.148 +// Standard C library (Captain Obvious guarantees!)
   1.149 +#include <stdio.h>
   1.150 +
   1.151 +#include "OVR_SysFile.h"
   1.152 +
   1.153 +namespace OVR {
   1.154 +
   1.155 +// This is - a dummy file that fails on all calls.
   1.156 +
   1.157 +class UnopenedFile : public File
   1.158 +{
   1.159 +public:
   1.160 +    UnopenedFile()  { }
   1.161 +    ~UnopenedFile() { }
   1.162 +
   1.163 +    virtual const char* GetFilePath()               { return 0; }
   1.164 +
   1.165 +    // ** File Information
   1.166 +    virtual bool        IsValid()                   { return 0; }
   1.167 +    virtual bool        IsWritable()                { return 0; }
   1.168 +
   1.169 +    // Return position / file size
   1.170 +    virtual int         Tell()                      { return 0; }
   1.171 +    virtual SInt64      LTell()                     { return 0; }
   1.172 +    virtual int         GetLength()                 { return 0; }
   1.173 +    virtual SInt64      LGetLength()                { return 0; }
   1.174 +
   1.175 +//  virtual bool        Stat(FileStats *pfs)        { return 0; }
   1.176 +    virtual int         GetErrorCode()              { return Error_FileNotFound; }
   1.177 +
   1.178 +    // ** Stream implementation & I/O
   1.179 +    virtual int         Write(const UByte *pbuffer, int numBytes)     { return -1; OVR_UNUSED2(pbuffer, numBytes); }
   1.180 +    virtual int         Read(UByte *pbuffer, int numBytes)            { return -1; OVR_UNUSED2(pbuffer, numBytes); }
   1.181 +    virtual int         SkipBytes(int numBytes)                       { return 0;  OVR_UNUSED(numBytes); }
   1.182 +    virtual int         BytesAvailable()                              { return 0; }
   1.183 +    virtual bool        Flush()                                       { return 0; }
   1.184 +    virtual int         Seek(int offset, int origin)                  { return -1; OVR_UNUSED2(offset, origin); }
   1.185 +    virtual SInt64      LSeek(SInt64 offset, int origin)              { return -1; OVR_UNUSED2(offset, origin); }
   1.186 +    
   1.187 +    virtual int         CopyFromStream(File *pstream, int byteSize)   { return -1; OVR_UNUSED2(pstream, byteSize); }
   1.188 +    virtual bool        Close()                                       { return 0; }    
   1.189 +};
   1.190 +
   1.191 +
   1.192 +
   1.193 +// ***** System File
   1.194 +
   1.195 +// System file is created to access objects on file system directly
   1.196 +// This file can refer directly to path
   1.197 +
   1.198 +// ** Constructor
   1.199 +SysFile::SysFile() : DelegatedFile(0)
   1.200 +{
   1.201 +    pFile = *new UnopenedFile;
   1.202 +}
   1.203 +
   1.204 +File* FileFILEOpen(const String& path, int flags, int mode);
   1.205 +
   1.206 +// Opens a file
   1.207 +SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0)
   1.208 +{
   1.209 +    Open(path, flags, mode);
   1.210 +}
   1.211 +
   1.212 +
   1.213 +// ** Open & management
   1.214 +// Will fail if file's already open
   1.215 +bool SysFile::Open(const String& path, int flags, int mode)
   1.216 +{
   1.217 +    pFile = *FileFILEOpen(path, flags, mode);
   1.218 +    if ((!pFile) || (!pFile->IsValid()))
   1.219 +    {
   1.220 +        pFile = *new UnopenedFile;
   1.221 +        return 0;
   1.222 +    }
   1.223 +    //pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing
   1.224 +    if (flags & Open_Buffered)
   1.225 +        pFile = *new BufferedFile(pFile);
   1.226 +    return 1;
   1.227 +}
   1.228 +
   1.229 +
   1.230 +// ** Overrides
   1.231 +
   1.232 +int SysFile::GetErrorCode()
   1.233 +{
   1.234 +    return pFile ? pFile->GetErrorCode() : Error_FileNotFound;
   1.235 +}
   1.236 +
   1.237 +
   1.238 +// Overrides to provide re-open support
   1.239 +bool SysFile::IsValid()
   1.240 +{
   1.241 +    return pFile && pFile->IsValid();
   1.242 +}
   1.243 +bool SysFile::Close()
   1.244 +{
   1.245 +    if (IsValid())
   1.246 +    {
   1.247 +        DelegatedFile::Close();
   1.248 +        pFile = *new UnopenedFile;
   1.249 +        return 1;
   1.250 +    }
   1.251 +    return 0;
   1.252 +}
   1.253 +
   1.254 +} // OVR