75 Error_FileNotFound = 0x1001,
76 Error_Access = 0x1002,
77 Error_IOError = 0x1003,
78 Error_DiskFull = 0x1004
87 class File :
public RefCountBase<File, Stat_Default_Mem>,
public FileConstants
96 virtual const char* GetFilePath() = 0;
101 virtual bool IsValid() = 0;
103 virtual bool IsWritable() = 0;
106 virtual int Tell() = 0;
107 virtual SInt64 LTell() = 0;
110 virtual int GetLength() = 0;
111 virtual SInt64 LGetLength() = 0;
115 virtual int GetErrorCode() = 0;
122 virtual int Write(
const UByte* pbufer,
int numBytes) = 0;
128 virtual int Read(
UByte* pbufer,
int numBytes) = 0;
132 virtual int SkipBytes(
int numBytes) = 0;
136 virtual int BytesAvailable() = 0;
140 virtual bool Flush() = 0;
143 KY_INLINE
bool IsEOF() {
return !BytesAvailable(); }
147 virtual int Seek(
int offset,
int origin = Seek_Set) = 0;
148 virtual SInt64 LSeek(
SInt64 offset,
int origin = Seek_Set) = 0;
151 virtual int SeekToBegin() {
return Seek(0); }
152 int SeekToEnd() {
return Seek(0, Seek_End); }
153 int Skip(
int numBytes) {
return Seek(numBytes, Seek_Cur); }
157 virtual bool ChangeSize(
int newSize) = 0;
161 virtual int CopyFromStream(File* pstream,
int byteSize) = 0;
165 virtual bool Close() = 0;
198 void PWrite8(
UInt8 v) { Write((
UByte*)&v, 1); }
202 inline void WriteUByte(
UByte v) { PWrite8((
UInt8)Alg::ByteUtil::SystemToLE(v)); }
203 inline void WriteSByte(
SByte v) { PWrite8((
UInt8)Alg::ByteUtil::SystemToLE(v)); }
204 inline void WriteUInt8(
UInt8 v) { PWrite8((
UInt8)Alg::ByteUtil::SystemToLE(v)); }
205 inline void WriteSInt8(
SInt8 v) { PWrite8((
UInt8)Alg::ByteUtil::SystemToLE(v)); }
206 inline void WriteUInt16(
UInt16 v) { PWrite16((
UInt16)Alg::ByteUtil::SystemToLE(v)); }
207 inline void WriteSInt16(
SInt16 v) { PWrite16((
UInt16)Alg::ByteUtil::SystemToLE(v)); }
208 inline void WriteUInt32(
UInt32 v) { PWrite32((
UInt32)Alg::ByteUtil::SystemToLE(v)); }
209 inline void WriteSInt32(
SInt32 v) { PWrite32((
UInt32)Alg::ByteUtil::SystemToLE(v)); }
210 inline void WriteUInt64(
UInt64 v) { PWrite64((
UInt64)Alg::ByteUtil::SystemToLE(v)); }
211 inline void WriteSInt64(
SInt64 v) { PWrite64((
UInt64)Alg::ByteUtil::SystemToLE(v)); }
212 inline void WriteFloat(
float v)
214 v = Alg::ByteUtil::SystemToLE(v);
215 Write((
UByte*)&v, 4);
217 inline void WriteDouble(
double v)
219 v = Alg::ByteUtil::SystemToLE(v);
220 Write((
UByte*)&v, 8);
223 inline void WriteUByteBE(
UByte v) { PWrite8((
UInt8)Alg::ByteUtil::SystemToBE(v)); }
224 inline void WriteSByteBE(
SByte v) { PWrite8((
UInt8)Alg::ByteUtil::SystemToBE(v)); }
225 inline void WriteUInt8BE(
UInt16 v) { PWrite8((
UInt8)Alg::ByteUtil::SystemToBE(v)); }
226 inline void WriteSInt8BE(
SInt16 v) { PWrite8((
UInt8)Alg::ByteUtil::SystemToBE(v)); }
227 inline void WriteUInt16BE(
UInt16 v) { PWrite16((
UInt16)Alg::ByteUtil::SystemToBE(v)); }
228 inline void WriteSInt16BE(
UInt16 v) { PWrite16((
UInt16)Alg::ByteUtil::SystemToBE(v)); }
229 inline void WriteUInt32BE(
UInt32 v) { PWrite32((
UInt32)Alg::ByteUtil::SystemToBE(v)); }
230 inline void WriteSInt32BE(
UInt32 v) { PWrite32((
UInt32)Alg::ByteUtil::SystemToBE(v)); }
231 inline void WriteUInt64BE(
UInt64 v) { PWrite64((
UInt64)Alg::ByteUtil::SystemToBE(v)); }
232 inline void WriteSInt64BE(
UInt64 v) { PWrite64((
UInt64)Alg::ByteUtil::SystemToBE(v)); }
233 inline void WriteFloatBE(
float v)
235 v = Alg::ByteUtil::SystemToBE(v);
236 Write((
UByte*)&v, 4);
238 inline void WriteDoubleBE(
double v)
240 v = Alg::ByteUtil::SystemToBE(v);
241 Write((
UByte*)&v, 8);
245 inline UByte ReadUByte() {
return (
UByte)Alg::ByteUtil::LEToSystem(PRead8()); }
246 inline SByte ReadSByte() {
return (
SByte)Alg::ByteUtil::LEToSystem(PRead8()); }
247 inline UInt8 ReadUInt8() {
return (
UInt8)Alg::ByteUtil::LEToSystem(PRead8()); }
248 inline SInt8 ReadSInt8() {
return (
SInt8)Alg::ByteUtil::LEToSystem(PRead8()); }
249 inline UInt16 ReadUInt16() {
return (
UInt16)Alg::ByteUtil::LEToSystem(PRead16()); }
250 inline SInt16 ReadSInt16() {
return (
SInt16)Alg::ByteUtil::LEToSystem(PRead16()); }
251 inline UInt32 ReadUInt32() {
return (
UInt32)Alg::ByteUtil::LEToSystem(PRead32()); }
252 inline SInt32 ReadSInt32() {
return (
SInt32)Alg::ByteUtil::LEToSystem(PRead32()); }
253 inline UInt64 ReadUInt64() {
return (
UInt64)Alg::ByteUtil::LEToSystem(PRead64()); }
254 inline SInt64 ReadSInt64() {
return (
SInt64)Alg::ByteUtil::LEToSystem(PRead64()); }
255 inline float ReadFloat()
259 return Alg::ByteUtil::LEToSystem(v);
261 inline double ReadDouble()
265 return Alg::ByteUtil::LEToSystem(v);
268 inline UByte ReadUByteBE() {
return (
UByte)Alg::ByteUtil::BEToSystem(PRead8()); }
269 inline SByte ReadSByteBE() {
return (
SByte)Alg::ByteUtil::BEToSystem(PRead8()); }
270 inline UInt8 ReadUInt8BE() {
return (
UInt8)Alg::ByteUtil::BEToSystem(PRead8()); }
271 inline SInt8 ReadSInt8BE() {
return (
SInt8)Alg::ByteUtil::BEToSystem(PRead8()); }
272 inline UInt16 ReadUInt16BE() {
return (
UInt16)Alg::ByteUtil::BEToSystem(PRead16()); }
273 inline SInt16 ReadSInt16BE() {
return (
SInt16)Alg::ByteUtil::BEToSystem(PRead16()); }
274 inline UInt32 ReadUInt32BE() {
return (
UInt32)Alg::ByteUtil::BEToSystem(PRead32()); }
275 inline SInt32 ReadSInt32BE() {
return (
SInt32)Alg::ByteUtil::BEToSystem(PRead32()); }
276 inline UInt64 ReadUInt64BE() {
return (
UInt64)Alg::ByteUtil::BEToSystem(PRead64()); }
277 inline SInt64 ReadSInt64BE() {
return (
SInt64)Alg::ByteUtil::BEToSystem(PRead64()); }
278 inline float ReadFloatBE()
282 return Alg::ByteUtil::BEToSystem(v);
284 inline double ReadDoubleBE()
288 return Alg::ByteUtil::BEToSystem(v);
294 class DelegatedFile :
public File
301 DelegatedFile() : pFile(0) {}
302 DelegatedFile(
const DelegatedFile& source) : File() { KY_UNUSED(source); }
306 DelegatedFile(File* pfile) : pFile(pfile) {}
309 virtual const char* GetFilePath() {
return pFile->GetFilePath(); }
312 virtual bool IsValid() {
return pFile && pFile->IsValid(); }
313 virtual bool IsWritable() {
return pFile->IsWritable(); }
315 virtual int Tell() {
return pFile->Tell(); }
316 virtual SInt64 LTell() {
return pFile->LTell(); }
318 virtual int GetLength() {
return pFile->GetLength(); }
319 virtual SInt64 LGetLength() {
return pFile->LGetLength(); }
321 virtual int GetErrorCode() {
return pFile->GetErrorCode(); }
324 virtual int Write(
const UByte* pbuffer,
int numBytes) {
return pFile->Write(pbuffer, numBytes); }
325 virtual int Read(
UByte* pbuffer,
int numBytes) {
return pFile->Read(pbuffer, numBytes); }
327 virtual int SkipBytes(
int numBytes) {
return pFile->SkipBytes(numBytes); }
329 virtual int BytesAvailable() {
return pFile->BytesAvailable(); }
331 virtual bool Flush() {
return pFile->Flush(); }
334 virtual int Seek(
int offset,
int origin = Seek_Set) {
return pFile->Seek(offset, origin); }
335 virtual SInt64 LSeek(
SInt64 offset,
int origin = Seek_Set) {
return pFile->LSeek(offset, origin); }
338 virtual bool ChangeSize(
int newSize) {
return pFile->ChangeSize(newSize); }
339 virtual int CopyFromStream(File* pstream,
int byteSize) {
return pFile->CopyFromStream(pstream, byteSize); }
342 virtual bool Close() {
return pFile->Close(); }
351 class BufferedFile :
public DelegatedFile
363 BufferModeType BufferMode;
369 bool SetBufferMode(BufferModeType mode);
381 inline BufferedFile(
const BufferedFile& source) : DelegatedFile() { KY_UNUSED(source); }
384 static int FILEBUFFER_SIZE;
385 static int FILEBUFFER_TOLERANCE;
389 BufferedFile(File* pfile);
399 virtual int GetLength();
400 virtual SInt64 LGetLength();
404 virtual int Write(
const UByte* pbufer,
int numBytes);
405 virtual int Read(
UByte* pbufer,
int numBytes);
407 virtual int SkipBytes(
int numBytes);
409 virtual int BytesAvailable();
411 virtual bool Flush();
413 virtual int Seek(
int offset,
int origin = Seek_Set);
414 virtual SInt64 LSeek(
SInt64 offset,
int origin = Seek_Set);
416 virtual bool ChangeSize(
int newSize);
417 virtual int CopyFromStream(File* pstream,
int byteSize);
419 virtual bool Close();
424 class MemoryFile :
public File
427 const char* GetFilePath() {
return FilePath.ToCStr(); }
429 bool IsValid() {
return Valid; }
430 bool IsWritable() {
return false; }
432 bool Flush() {
return true; }
433 int GetErrorCode() {
return 0; }
435 int Tell() {
return FileIndex; }
438 int GetLength() {
return FileSize; }
447 int CopyFromStream(File* pstream,
int byteSize)
449 KY_UNUSED2(pstream, byteSize);
453 int Write(
const UByte* pbuffer,
int numBytes)
455 KY_UNUSED2(pbuffer, numBytes);
459 int Read(
UByte* pbufer,
int numBytes)
461 if (FileIndex + numBytes > FileSize)
463 numBytes = FileSize - FileIndex;
468 ::memcpy(pbufer, &FileData[FileIndex], numBytes);
470 FileIndex += numBytes;
476 int SkipBytes(
int numBytes)
478 if (FileIndex + numBytes > FileSize)
480 numBytes = FileSize - FileIndex;
483 FileIndex += numBytes;
488 int BytesAvailable() {
return (FileSize - FileIndex); }
490 int Seek(
int offset,
int origin = Seek_Set)
494 case Seek_Set: FileIndex = offset;
break;
495 case Seek_Cur: FileIndex += offset;
break;
496 case Seek_End: FileIndex = FileSize - offset;
break;
502 SInt64 LSeek(
SInt64 offset,
int origin = Seek_Set) {
return (
SInt64)Seek((
int)offset, origin); }
504 bool ChangeSize(
int newSize)
511 MemoryFile(
const String& fileName,
const UByte* pBuffer,
int buffSize) : FilePath(fileName)
516 Valid = (!fileName.IsEmpty() && pBuffer && buffSize > 0) ?
true :
false;
520 MemoryFile(
const char* pfileName,
const UByte* pBuffer,
int buffSize) : FilePath(pfileName)
525 Valid = (pfileName && pBuffer && buffSize > 0) ?
true :
false;
530 const UByte* FileData;
539 const char* GetShortFilename(
const char* purl);
std::int64_t SInt64
int64_t
Definition: SF_Types.h:132
std::uint16_t UInt16
uint16_t
Definition: SF_Types.h:136
std::uint8_t UByte
uint8_t
Definition: SF_Types.h:134
std::int32_t SInt32
int32_t
Definition: SF_Types.h:131
std::uint32_t UInt32
uint32_t
Definition: SF_Types.h:137
std::int8_t SInt8
int8_t
Definition: SF_Types.h:129
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
std::uint8_t UInt8
uint8_t
Definition: SF_Types.h:135
std::int8_t SByte
uint8_t
Definition: SF_Types.h:128
std::uint64_t UInt64
uint64_t
Definition: SF_Types.h:138
std::int16_t SInt16
int16_t
Definition: SF_Types.h:130