oculus1

diff libovr/Src/Kernel/OVR_SysFile.cpp @ 1:e2f9e4603129

added LibOVR and started a simple vr wrapper.
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Sep 2013 16:14:59 +0300
parents
children b069a5c27388
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libovr/Src/Kernel/OVR_SysFile.cpp	Sat Sep 14 16:14:59 2013 +0300
     1.3 @@ -0,0 +1,1 @@
     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