OVR_SysFile.cpp
Go to the documentation of this file.
00001 /**************************************************************************
00002 
00003 Filename    :   OVR_SysFile.cpp
00004 Content     :   File wrapper class implementation (Win32)
00005 
00006 Created     :   April 5, 1999
00007 Authors     :   Michael Antonov
00008 
00009 Copyright   :   Copyright 2011 Oculus VR, Inc. All Rights reserved.
00010 
00011 Use of this software is subject to the terms of the Oculus license
00012 agreement provided at the time of installation or download, or which
00013 otherwise accompanies this software in either electronic or hard copy form.
00014 
00015 **************************************************************************/
00016 
00017 #define  GFILE_CXX
00018 
00019 // Standard C library (Captain Obvious guarantees!)
00020 #include <stdio.h>
00021 
00022 #include "OVR_SysFile.h"
00023 
00024 namespace OVR {
00025 
00026 // This is - a dummy file that fails on all calls.
00027 
00028 class UnopenedFile : public File
00029 {
00030 public:
00031     UnopenedFile()  { }
00032     ~UnopenedFile() { }
00033 
00034     virtual const char* GetFilePath()               { return 0; }
00035 
00036     // ** File Information
00037     virtual bool        IsValid()                   { return 0; }
00038     virtual bool        IsWritable()                { return 0; }
00039 
00040     // Return position / file size
00041     virtual int         Tell()                      { return 0; }
00042     virtual SInt64      LTell()                     { return 0; }
00043     virtual int         GetLength()                 { return 0; }
00044     virtual SInt64      LGetLength()                { return 0; }
00045 
00046 //  virtual bool        Stat(FileStats *pfs)        { return 0; }
00047     virtual int         GetErrorCode()              { return Error_FileNotFound; }
00048 
00049     // ** Stream implementation & I/O
00050     virtual int         Write(const UByte *pbuffer, int numBytes)     { return -1; OVR_UNUSED2(pbuffer, numBytes); }
00051     virtual int         Read(UByte *pbuffer, int numBytes)            { return -1; OVR_UNUSED2(pbuffer, numBytes); }
00052     virtual int         SkipBytes(int numBytes)                       { return 0;  OVR_UNUSED(numBytes); }
00053     virtual int         BytesAvailable()                              { return 0; }
00054     virtual bool        Flush()                                       { return 0; }
00055     virtual int         Seek(int offset, int origin)                  { return -1; OVR_UNUSED2(offset, origin); }
00056     virtual SInt64      LSeek(SInt64 offset, int origin)              { return -1; OVR_UNUSED2(offset, origin); }
00057     
00058     virtual int         CopyFromStream(File *pstream, int byteSize)   { return -1; OVR_UNUSED2(pstream, byteSize); }
00059     virtual bool        Close()                                       { return 0; }    
00060 };
00061 
00062 
00063 
00064 // ***** System File
00065 
00066 // System file is created to access objects on file system directly
00067 // This file can refer directly to path
00068 
00069 // ** Constructor
00070 SysFile::SysFile() : DelegatedFile(0)
00071 {
00072     pFile = *new UnopenedFile;
00073 }
00074 
00075 File* FileFILEOpen(const String& path, int flags, int mode);
00076 
00077 // Opens a file
00078 SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0)
00079 {
00080     Open(path, flags, mode);
00081 }
00082 
00083 
00084 // ** Open & management
00085 // Will fail if file's already open
00086 bool SysFile::Open(const String& path, int flags, int mode)
00087 {
00088     pFile = *FileFILEOpen(path, flags, mode);
00089     if ((!pFile) || (!pFile->IsValid()))
00090     {
00091         pFile = *new UnopenedFile;
00092         return 0;
00093     }
00094     //pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing
00095     if (flags & Open_Buffered)
00096         pFile = *new BufferedFile(pFile);
00097     return 1;
00098 }
00099 
00100 
00101 // ** Overrides
00102 
00103 int SysFile::GetErrorCode()
00104 {
00105     return pFile ? pFile->GetErrorCode() : Error_FileNotFound;
00106 }
00107 
00108 
00109 // Overrides to provide re-open support
00110 bool SysFile::IsValid()
00111 {
00112     return pFile && pFile->IsValid();
00113 }
00114 bool SysFile::Close()
00115 {
00116     if (IsValid())
00117     {
00118         DelegatedFile::Close();
00119         pFile = *new UnopenedFile;
00120         return 1;
00121     }
00122     return 0;
00123 }
00124 
00125 } // OVR


oculus_sdk
Author(s):
autogenerated on Mon Oct 6 2014 03:01:19