ovr_sdk
view LibOVR/Src/Kernel/OVR_SysFile.cpp @ 3:f12a8f74fe1f
added the Xcode project
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 21 Jan 2015 11:37:50 +0200 |
parents | |
children |
line source
1 /**************************************************************************
3 Filename : OVR_SysFile.cpp
4 Content : File wrapper class implementation (Win32)
6 Created : April 5, 1999
7 Authors : Michael Antonov
9 Copyright : Copyright 2014 Oculus VR, LLC All Rights reserved.
11 Licensed under the Oculus VR Rift SDK License Version 3.2 (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.
16 You may obtain a copy of the License at
18 http://www.oculusvr.com/licenses/LICENSE-3.2
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.
26 **************************************************************************/
28 #define GFILE_CXX
30 // Standard C library (Captain Obvious guarantees!)
31 #include <stdio.h>
33 #include "OVR_SysFile.h"
34 #include "OVR_Log.h"
36 namespace OVR {
38 // This is - a dummy file that fails on all calls.
40 class UnopenedFile : public File
41 {
42 public:
43 UnopenedFile() { }
44 ~UnopenedFile() { }
46 virtual const char* GetFilePath() { return 0; }
48 // ** File Information
49 virtual bool IsValid() { return 0; }
50 virtual bool IsWritable() { return 0; }
52 // Return position / file size
53 virtual int Tell() { return 0; }
54 virtual int64_t LTell() { return 0; }
55 virtual int GetLength() { return 0; }
56 virtual int64_t LGetLength() { return 0; }
58 // virtual bool Stat(FileStats *pfs) { return 0; }
59 virtual int GetErrorCode() { return Error_FileNotFound; }
61 // ** Stream implementation & I/O
62 virtual int Write(const uint8_t * /*pbuffer*/, int /*numBytes*/) { return -1; }
63 virtual int Read(uint8_t * /*pbuffer*/, int /*numBytes*/) { return -1; }
64 virtual int SkipBytes(int /*numBytes*/) { return 0; }
65 virtual int BytesAvailable() { return 0; }
66 virtual bool Flush() { return 0; }
67 virtual int Seek(int /*offset*/, int /*origin*/) { return -1; }
68 virtual int64_t LSeek(int64_t /*offset*/, int /*origin*/) { return -1; }
70 virtual int CopyFromStream(File * /*pstream*/, int /*byteSize*/) { return -1; }
71 virtual bool Close() { return 0; }
72 };
76 // ***** System File
78 // System file is created to access objects on file system directly
79 // This file can refer directly to path
81 // ** Constructor
82 SysFile::SysFile() : DelegatedFile(0)
83 {
84 pFile = *new UnopenedFile;
85 }
87 Ptr<File> FileFILEOpen(const String& path, int flags, int mode);
89 // Opens a file
90 SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0)
91 {
92 Open(path, flags, mode);
93 }
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 }
114 // ** Overrides
116 int SysFile::GetErrorCode()
117 {
118 return pFile ? pFile->GetErrorCode() : Error_FileNotFound;
119 }
122 // Overrides to provide re-open support
123 bool SysFile::IsValid()
124 {
125 return pFile && pFile->IsValid();
126 }
127 bool SysFile::Close()
128 {
129 if (IsValid())
130 {
131 DelegatedFile::Close();
132 pFile = *new UnopenedFile;
133 return 1;
134 }
135 return 0;
136 }
138 } // OVR