oculus1

view 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 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 2011 Oculus VR, Inc. All Rights reserved.
11 Use of this software is subject to the terms of the Oculus license
12 agreement provided at the time of installation or download, or which
13 otherwise accompanies this software in either electronic or hard copy form.
15 **************************************************************************/
17 #define GFILE_CXX
19 // Standard C library (Captain Obvious guarantees!)
20 #include <stdio.h>
22 #include "OVR_SysFile.h"
24 namespace OVR {
26 // This is - a dummy file that fails on all calls.
28 class UnopenedFile : public File
29 {
30 public:
31 UnopenedFile() { }
32 ~UnopenedFile() { }
34 virtual const char* GetFilePath() { return 0; }
36 // ** File Information
37 virtual bool IsValid() { return 0; }
38 virtual bool IsWritable() { return 0; }
40 // Return position / file size
41 virtual int Tell() { return 0; }
42 virtual SInt64 LTell() { return 0; }
43 virtual int GetLength() { return 0; }
44 virtual SInt64 LGetLength() { return 0; }
46 // virtual bool Stat(FileStats *pfs) { return 0; }
47 virtual int GetErrorCode() { return Error_FileNotFound; }
49 // ** Stream implementation & I/O
50 virtual int Write(const UByte *pbuffer, int numBytes) { return -1; OVR_UNUSED2(pbuffer, numBytes); }
51 virtual int Read(UByte *pbuffer, int numBytes) { return -1; OVR_UNUSED2(pbuffer, numBytes); }
52 virtual int SkipBytes(int numBytes) { return 0; OVR_UNUSED(numBytes); }
53 virtual int BytesAvailable() { return 0; }
54 virtual bool Flush() { return 0; }
55 virtual int Seek(int offset, int origin) { return -1; OVR_UNUSED2(offset, origin); }
56 virtual SInt64 LSeek(SInt64 offset, int origin) { return -1; OVR_UNUSED2(offset, origin); }
58 virtual int CopyFromStream(File *pstream, int byteSize) { return -1; OVR_UNUSED2(pstream, byteSize); }
59 virtual bool Close() { return 0; }
60 };
64 // ***** System File
66 // System file is created to access objects on file system directly
67 // This file can refer directly to path
69 // ** Constructor
70 SysFile::SysFile() : DelegatedFile(0)
71 {
72 pFile = *new UnopenedFile;
73 }
75 File* FileFILEOpen(const String& path, int flags, int mode);
77 // Opens a file
78 SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0)
79 {
80 Open(path, flags, mode);
81 }
84 // ** Open & management
85 // Will fail if file's already open
86 bool SysFile::Open(const String& path, int flags, int mode)
87 {
88 pFile = *FileFILEOpen(path, flags, mode);
89 if ((!pFile) || (!pFile->IsValid()))
90 {
91 pFile = *new UnopenedFile;
92 return 0;
93 }
94 //pFile = *OVR_NEW DelegatedFile(pFile); // MA Testing
95 if (flags & Open_Buffered)
96 pFile = *new BufferedFile(pFile);
97 return 1;
98 }
101 // ** Overrides
103 int SysFile::GetErrorCode()
104 {
105 return pFile ? pFile->GetErrorCode() : Error_FileNotFound;
106 }
109 // Overrides to provide re-open support
110 bool SysFile::IsValid()
111 {
112 return pFile && pFile->IsValid();
113 }
114 bool SysFile::Close()
115 {
116 if (IsValid())
117 {
118 DelegatedFile::Close();
119 pFile = *new UnopenedFile;
120 return 1;
121 }
122 return 0;
123 }
125 } // OVR