Bike-X  0.8
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
OVR_SysFile.cpp
Go to the documentation of this file.
1 /**************************************************************************
2 
3 Filename : OVR_SysFile.cpp
4 Content : File wrapper class implementation (Win32)
5 
6 Created : April 5, 1999
7 Authors : Michael Antonov
8 
9 Copyright : Copyright 2014 Oculus VR, Inc. All Rights reserved.
10 
11 Licensed under the Oculus VR Rift SDK License Version 3.1 (the "License");
12 you may not use the Oculus VR Rift SDK except in compliance with the License,
13 which is provided at the time of installation or download, or which
14 otherwise accompanies this software in either electronic or hard copy form.
15 
16 You may obtain a copy of the License at
17 
18 http://www.oculusvr.com/licenses/LICENSE-3.1
19 
20 Unless required by applicable law or agreed to in writing, the Oculus VR SDK
21 distributed under the License is distributed on an "AS IS" BASIS,
22 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 See the License for the specific language governing permissions and
24 limitations under the License.
25 
26 **************************************************************************/
27 
28 #define GFILE_CXX
29 
30 // Standard C library (Captain Obvious guarantees!)
31 #include <stdio.h>
32 
33 #include "OVR_SysFile.h"
34 #include "OVR_Log.h"
35 
36 namespace OVR {
37 
38 // This is - a dummy file that fails on all calls.
39 
40 class UnopenedFile : public File
41 {
42 public:
45 
46  virtual const char* GetFilePath() { return 0; }
47 
48  // ** File Information
49  virtual bool IsValid() { return 0; }
50  virtual bool IsWritable() { return 0; }
51 
52  // Return position / file size
53  virtual int Tell() { return 0; }
54  virtual SInt64 LTell() { return 0; }
55  virtual int GetLength() { return 0; }
56  virtual SInt64 LGetLength() { return 0; }
57 
58 // virtual bool Stat(FileStats *pfs) { return 0; }
59  virtual int GetErrorCode() { return Error_FileNotFound; }
60 
61  // ** Stream implementation & I/O
62  virtual int Write(const UByte *pbuffer, int numBytes) { return -1; OVR_UNUSED2(pbuffer, numBytes); }
63  virtual int Read(UByte *pbuffer, int numBytes) { return -1; OVR_UNUSED2(pbuffer, numBytes); }
64  virtual int SkipBytes(int numBytes) { return 0; OVR_UNUSED(numBytes); }
65  virtual int BytesAvailable() { return 0; }
66  virtual bool Flush() { return 0; }
67  virtual int Seek(int offset, int origin) { return -1; OVR_UNUSED2(offset, origin); }
68  virtual SInt64 LSeek(SInt64 offset, int origin) { return -1; OVR_UNUSED2(offset, origin); }
69 
70  virtual int CopyFromStream(File *pstream, int byteSize) { return -1; OVR_UNUSED2(pstream, byteSize); }
71  virtual bool Close() { return 0; }
72 };
73 
74 
75 
76 // ***** System File
77 
78 // System file is created to access objects on file system directly
79 // This file can refer directly to path
80 
81 // ** Constructor
83 {
84  pFile = *new UnopenedFile;
85 }
86 
87 Ptr<File> FileFILEOpen(const String& path, int flags, int mode);
88 
89 // Opens a file
90 SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0)
91 {
92  Open(path, flags, mode);
93 }
94 
95 
96 // ** Open & management
97 // Will fail if file's already open
98 bool SysFile::Open(const String& path, int flags, int mode)
99 {
100  pFile = FileFILEOpen(path, flags, mode);
101  if ((!pFile) || (!pFile->IsValid()))
102  {
103  pFile = *new UnopenedFile;
104  OVR_DEBUG_LOG(("Failed to open file: %s", path.ToCStr()));
105  return 0;
106  }
107  //pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing
108  if (flags & Open_Buffered)
109  pFile = *new BufferedFile(pFile);
110  return 1;
111 }
112 
113 
114 // ** Overrides
115 
117 {
118  return pFile ? pFile->GetErrorCode() : Error_FileNotFound;
119 }
120 
121 
122 // Overrides to provide re-open support
124 {
125  return pFile && pFile->IsValid();
126 }
128 {
129  if (IsValid())
130  {
132  pFile = *new UnopenedFile;
133  return 1;
134  }
135  return 0;
136 }
137 
138 } // OVR
virtual int Seek(int offset, int origin)
Definition: OVR_SysFile.cpp:67
Ptr< File > FileFILEOpen(const String &path, int flags, int mode)
virtual int Write(const UByte *pbuffer, int numBytes)
Definition: OVR_SysFile.cpp:62
virtual int BytesAvailable()
Definition: OVR_SysFile.cpp:65
virtual int GetLength()
Definition: OVR_SysFile.cpp:55
virtual SInt64 LTell()
Definition: OVR_SysFile.cpp:54
virtual bool IsWritable()
Definition: OVR_SysFile.cpp:50
#define OVR_UNUSED(a)
uint8_t UByte
Definition: OVR_Types.h:249
virtual int Read(UByte *pbuffer, int numBytes)
Definition: OVR_SysFile.cpp:63
virtual bool Close()
Definition: OVR_File.h:323
const char * ToCStr() const
Definition: OVR_String.h:186
virtual int GetErrorCode()
virtual SInt64 LSeek(SInt64 offset, int origin)
Definition: OVR_SysFile.cpp:68
int64_t SInt64
Definition: OVR_Types.h:254
virtual SInt64 LGetLength()
Definition: OVR_SysFile.cpp:56
virtual bool Close()
Definition: OVR_SysFile.cpp:71
virtual int SkipBytes(int numBytes)
Definition: OVR_SysFile.cpp:64
Ptr< File > pFile
Definition: OVR_File.h:279
virtual bool Flush()
Definition: OVR_SysFile.cpp:66
bool Open(const String &path, int flags=Open_Read|Open_Buffered, int mode=Mode_ReadWrite)
Definition: OVR_SysFile.cpp:98
virtual const char * GetFilePath()
Definition: OVR_SysFile.cpp:46
virtual int CopyFromStream(File *pstream, int byteSize)
Definition: OVR_SysFile.cpp:70
virtual int Tell()
Definition: OVR_SysFile.cpp:53
virtual bool IsValid()
Definition: OVR_SysFile.cpp:49
virtual bool Close()
#define OVR_DEBUG_LOG(args)
Definition: OVR_Log.h:196
virtual int GetErrorCode()
Definition: OVR_SysFile.cpp:59
#define OVR_UNUSED2(a1, a2)
virtual bool IsValid()