Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #define GFILE_CXX
00018
00019
00020 #include <stdio.h>
00021
00022 #include "OVR_SysFile.h"
00023
00024 namespace OVR {
00025
00026
00027
00028 class UnopenedFile : public File
00029 {
00030 public:
00031 UnopenedFile() { }
00032 ~UnopenedFile() { }
00033
00034 virtual const char* GetFilePath() { return 0; }
00035
00036
00037 virtual bool IsValid() { return 0; }
00038 virtual bool IsWritable() { return 0; }
00039
00040
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
00047 virtual int GetErrorCode() { return Error_FileNotFound; }
00048
00049
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
00065
00066
00067
00068
00069
00070 SysFile::SysFile() : DelegatedFile(0)
00071 {
00072 pFile = *new UnopenedFile;
00073 }
00074
00075 File* FileFILEOpen(const String& path, int flags, int mode);
00076
00077
00078 SysFile::SysFile(const String& path, int flags, int mode) : DelegatedFile(0)
00079 {
00080 Open(path, flags, mode);
00081 }
00082
00083
00084
00085
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
00095 if (flags & Open_Buffered)
00096 pFile = *new BufferedFile(pFile);
00097 return 1;
00098 }
00099
00100
00101
00102
00103 int SysFile::GetErrorCode()
00104 {
00105 return pFile ? pFile->GetErrorCode() : Error_FileNotFound;
00106 }
00107
00108
00109
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 }