9#if !defined(OWL_FILE_H)
13#if defined(BI_HAS_PRAGMA_ONCE)
89#define BINNTYPE (varLastMember+1)
105#define TFILE_ERROR static_cast<uint32>(-1)
108#define FileNull nullptr
110#define TFILE64_ERROR uint64(0xFFFFFFFF)
196 virtual bool Open(
const tstring& fileName,
const uint32 mode = ReadOnly|PermRead|OpenExisting);
197 virtual bool Close();
199 virtual bool Length(
uint64 newLen);
200 virtual uint64 Position64()
const;
201 virtual uint64 Length64()
const;
202 virtual bool Length(
uint32 newLen);
203 virtual uint32 Position()
const;
204 virtual uint32 Length()
const;
206 virtual uint64 Seek(
int64 offset, TSeekDir origin = beg);
207 virtual uint32 Seek(
long offset, TSeekDir origin = beg);
215 uint32 GetOpenMode()
const;
219 virtual bool Write(
const void * buffer,
uint32 numBytes);
220 virtual bool Flush();
225 static uint ReadStruct(
uint8 * readBuf,
void * buffer,
230 static uint WriteStruct(
uint8 * writeBuf,
void * buffer,
236 virtual bool UnlockRange(
uint32 position,
uint32 count);
238 virtual bool UnlockRange(
uint64 position,
uint64 count);
240#if defined(OWL5_COMPAT)
242 static bool GetStatus(LPCTSTR name,
TFileStatus & status);
244 static bool SetStatus(LPCTSTR name,
const TFileStatus & status);
249 virtual uint8 readUint8();
250 virtual uint16 readUint16();
251 virtual uint32 readUint32();
252 virtual uint64 readUint64();
253 virtual float readFloat();
254 virtual double readDouble();
255 virtual LPTSTR readString(
tchar *);
257 virtual void writeUint8(
const uint8 );
258 virtual void writeUint16(
const uint16 );
259 virtual void writeUint32(
const uint32 );
260 virtual void writeUint64(
const uint64 );
261 virtual void writeFloat(
const float );
262 virtual void writeDouble(
const double );
263 virtual void writeString(
const tchar *);
331 virtual uint32 LastError();
334 virtual bool Close();
336 virtual bool Write(
const void * buffer,
uint32 numBytes);
337 virtual bool Length(
uint64 newLen);
338 virtual uint64 Position64()
const;
339 virtual uint64 Length64()
const;
340 virtual bool Length(
uint32 newLen);
341 virtual uint32 Position()
const;
342 virtual uint32 Length()
const;
345 virtual bool Flush();
347 virtual bool UnlockRange(
uint32 position,
uint32 count);
349 virtual bool UnlockRange(
uint64 position,
uint64 count);
350 virtual bool GetStatus(
TFileStatus & status)
const;
382 virtual bool Close();
383 virtual bool Length(
uint64 newLen);
384 virtual uint64 Position64()
const;
385 virtual uint64 Length64()
const;
386 virtual uint32 Position()
const;
387 virtual uint32 Length()
const;
388 virtual bool Length(
uint32 newLen);
390 virtual uint64 Seek(
int64 offset, TSeekDir origin = beg);
391 virtual uint32 Seek(
long offset, TSeekDir origin = beg);
394 virtual bool Write(
const void* buffer,
uint32 numBytes);
395 virtual bool Flush();
398 virtual void SetBuffer(
uint8* buffer,
uint size,
bool shouldDelete =
true);
402 virtual void InitBuffer(
uint size = DefaultBufferSize);
403 virtual bool FlushBuffer();
449 virtual uint8 readUint8();
450 virtual uint16 readUint16();
451 virtual uint32 readUint32();
452 virtual uint64 readUint64();
453 virtual float readFloat();
454 virtual double readDouble();
455 virtual LPTSTR readString(
tchar *);
457 virtual void writeUint8(
const uint8 );
458 virtual void writeUint16(
const uint16 );
459 virtual void writeUint32(
const uint32 );
460 virtual void writeUint64(
const uint64 );
461 virtual void writeFloat(
const float );
462 virtual void writeDouble(
const double );
463 virtual void writeString(
const tchar *);
477 const tchar* operator *()
const;
478 operator const tchar*()
const;
479 const tchar* operator ++();
525# define owlFCC(ch4) (((static_cast<DWORD>(ch4) & 0xFF) << 24) | \
526 ((static_cast<DWORD>(ch4) & 0xFF00) << 8) | \
527 ((static_cast<DWORD>(ch4) & 0xFF0000) >> 8) | \
528 ((static_cast<DWORD>(ch4) & 0xFF000000) >> 24))
531# define owlFCC(ch0, ch1, ch2, ch3) \
532 (static_cast<uint32>(static_cast<uint8>(ch0)) | (static_cast<uint32>(static_cast<uint8>(ch1)) << 8) | \
533 (static_cast<uint32>(static_cast<uint8>(ch2)) << 16) | (static_cast<uint32>(static_cast<uint8>(ch3)) << 24 ))
584 bool CreateChunk(
TCkInfo& info,
const TCreateFlags = cfCreateChunk);
586 bool Descent(
TCkInfo& info,
TCkInfo* parent = 0,
const TFindFlags = ffFindAny);
626 const TFindFlags = TFindFlags(ffFindChunk|ffReset));
627 bool CreateChunk(
TQtInfo & info);
656 virtual uint32 LastError();
658 virtual bool IsOpen();
662 virtual bool Close();
664 virtual bool Write(
const void * buffer,
uint32 numBytes);
665 virtual bool Length(
uint64 newLen);
666 virtual uint64 Position64()
const;
667 virtual uint64 Length64()
const;
668 virtual bool Length(
uint32 newLen);
669 virtual uint32 Position()
const;
670 virtual uint32 Length()
const;
673 virtual bool Flush();
675 virtual bool UnlockRange(
uint32 position,
uint32 count);
677 virtual bool UnlockRange(
uint64 position,
uint64 count);
678 virtual bool GetStatus(
TFileStatus & status)
const;
700 virtual bool Open(
const tstring& fileName,
const uint32 mode = ReadOnly|PermRead|OpenExisting);
728 Open(fileName, mode);
938 i =
static_cast<signed int>(file.
readUint32());
1038 size_t size = s.length();
1040 file.
Write(s.c_str(),
static_cast<int>(size));
1065:
TFile(handle, shouldClose)
1073:
TFile(fileName, mode)
1187inline TFileLineIterator::operator
const tchar*()
const{
1283:
TFile(handle, shouldClose)
1288 Open(filename, mode);
#define PRECONDITION(condition)
The TBufferedFile class is derived from TFile encapsulates standard file characteristics and operatio...
TBufferedFile()
Creates a TBufferedFile object with a file handle of FileNull and allocated a buffer of DefaultBuffer...
virtual uint32 Length() const
Returns the file length plus the length of unwritten data in the buffer.
virtual bool Write(const void *buffer, uint32 numBytes)
Writes numBytes of buffer to the file.
uint32 EndPos
Offset in file to the last data byte in the buffer.
virtual bool FlushBuffer()
Flushes the buffer by writing any unwritten data to the file.
uint8 * CurByte
Pointer to current position in the buffer.
virtual uint64 Length64() const
Returns the file length plus the length of unwritten data in the buffer.
virtual void InitBuffer(uint size=DefaultBufferSize)
Allocates a buffer of size bytes.
uint FileBufSize
Size of FileBuffer in bytes.
uint8 * FileBuffer
Buffer used to store data in.
bool BufferEmpty
True if the buffer is empty; false otherwise.
virtual uint64 Position64() const
Returns the current position of the file pointer.
virtual bool Close()
Flushes the buffer and closes the file.
uint32 StartPos
Offset in file to byte 0 of the buffer.
virtual bool Flush()
Writes any data in the buffer to file and then resets the buffer.
virtual uint32 Position() const
Returns the current position of the file pointer.
uint32 CurPos
Offset in file to current position.
bool ShouldDelete
True if the buffer should be deleted.
TDiskFileHandle * Clone() const
virtual const tstring GetName()
virtual uint GetOpenMode()
TDiskFileHandle(const tstring &fileName, uint32 mode)
virtual uint32 Length() const =0
virtual bool LockRange(uint32 position, uint32 count)=0
virtual bool Length(uint64 newLen)=0
virtual TFileHandle * Clone() const =0
virtual bool GetStatus(TFileStatus &status) const =0
virtual bool UnlockRange(uint32 position, uint32 count)=0
virtual bool Write(const void *buffer, uint32 numBytes)=0
virtual uint32 LastError()=0
virtual uint64 Position64() const =0
virtual uint32 Seek(long offset, TFile::TSeekDir origin=TFile::beg)=0
virtual uint GetOpenMode()=0
virtual uint32 Read(void *buffer, uint32 numBytes)=0
virtual uint64 Seek(int64 offset, TFile::TSeekDir origin=TFile::beg)=0
virtual bool LockRange(uint64 position, uint64 count)=0
virtual bool UnlockRange(uint64 position, uint64 count)=0
virtual uint32 Position() const =0
virtual const tstring GetName()=0
virtual uint64 Length64() const =0
virtual bool Length(uint32 newLen)=0
The TFile class encapsulates standard file characteristics and operations.
virtual bool Open(const tstring &fileName, const uint32 mode=ReadOnly|PermRead|OpenExisting)
Opens file name with the given mode.
bool IsOpen() const
Returns true if the file is open, false otherwise.
virtual uint32 Length() const
Returns the file length.
virtual uint64 readUint64()
uint BufSize
Size of Buffer used with structure read/write.
virtual uint64 Seek(int64 offset, TSeekDir origin=beg)
Repositions the file pointer to offset bytes from the specified origin.
bool ShouldClose
Should C++ object close file on dtor.
TOpenMode
Open mode -> remapped into OS specific value internally.
@ Text
type Text are used in derived classes only default type is Binary
@ PermWrite
Subsequent open operations on the object will succeed only if write access is requested.
@ CreateNew
Creates a new file. The function fails if the specified file already exists.
@ TruncateExist
Opens the file.
@ OpenExisting
Opens the file. The function fails if the file does not exist.
@ PermRead
Subsequent open operations on the object will succeed only if read access is requested.
@ CreateAlways
Creates a new file. The function overwrites the file if it exists.
uint8 * Buffer
Buffer used with structure read/write.
virtual TCHAR * readString(tchar *)
virtual bool Flush()
Performs any pending I/O functions. Returns true if successful; false otherwise.
virtual double readDouble()
virtual void writeString(const tchar *)
uint64 SeekToEnd64()
Repositions the file pointer to the end of the file.
virtual bool LockRange(uint32 position, uint32 count)
Locks count bytes, beginning at position of the file.
virtual void writeUint8(const uint8)
virtual uint32 Read(void *buffer, uint32 numBytes)
Reads numBytes from the file into buffer. The number of bytes read is returned.
virtual float readFloat()
virtual uint64 Length64() const
Returns the file length.
virtual void writeFloat(const float)
virtual uint16 readUint16()
virtual uint32 readUint32()
uint64 SeekToBegin64()
Repositions the file pointer to the beginning of the file.
TFileHandle * Handle
Low-level C file handle.
virtual bool Write(const void *buffer, uint32 numBytes)
Writes numbytes of buffer to the file.
virtual bool UnlockRange(uint32 position, uint32 count)
Unlocks the range at the given Position.
virtual void writeDouble(const double)
uint32 GetOpenMode() const
Returns OpenMode.
TAttribute
file attributes -> internally remapped into OS values
uint32 SeekToEnd()
Repositions the file pointer to the end of the file.
uint32 SeekToBegin()
Repositions the file pointer to the beginning of the file.
const tstring GetName() const
Returns Name.
virtual uint8 readUint8()
TFile()
Creates a TFile object with a file handle of FileNull.
virtual void writeUint16(const uint16)
TBinType
Binary data type enumerations.
virtual void writeUint32(const uint32)
virtual TFileHandle * GetHandle() const
Returns Handle.
uint32 LastError()
Returns the last error.
@ cur
Seek from the current position in the file.
@ end
Seek from the end of the file.
@ beg
Seek from the beginning of the file.
virtual uint32 Position() const
Returns the current position of the file pointer.
virtual bool Close()
Closes the file. Returns true if successful, false otherwise.
virtual void writeUint64(const uint64)
bool GetStatus(TFileStatus &status) const
Fills status with the current file status.
virtual uint64 Position64() const
32 Bit Only: Returns the current position of the file pointer.
virtual bool NextLine()
Loads the next line in the file. Returns true if successful; false otherwise.
TFileLineIterator()
Protected default constructor. Intializes everything to 0.
TCHAR * LineBuffer
Buffer lines of text are loaded into.
const tchar * operator*() const
Returns a pointer to the start of the buffer if the file has not been completely iterated through; ot...
uint Line() const
Returns the current line number.
uint BuffSize
Size of the buffer allocated for loading a line of text.
uint LineNumber
Current line number in buffer. Line numbering starts at 1.
const tchar * Current() const
Returns a pointer to the start of the buffer if the file has not been completely iterated through; ot...
TTextFile * File
Pointer to the file being iterated through.
const tchar * operator++()
Loads the next line in the file and then returns a pointer to the start of the buffer if the file has...
TFileLineIterator(TTextFile &file, uint bufsize=260)
Constructor for iterating through file.
The TQtFile class is used for reading and writing QuickTime files.
TQtFile()
Default constructor.
The TRiffFile class is used for reading and writing RIFF files.
TRiffFile()
Default constructor.
virtual bool Open(const tstring &fileName, const uint32 mode=ReadOnly|PermRead|OpenExisting)
TStreamFile(TStreamFile &file)
TStreamHandle(TStreamFile *parent, const tstring &filename, uint32 mode)
virtual const tstring GetName()
virtual uint GetOpenMode()
The TTextFile class is derived from TBufferedFile and encapsulates standard file characteristics and ...
bool WriteString(const tstring &str)
virtual void writeString(const tchar *)
virtual TCHAR * readString(tchar *)
TTextFile()
Creates a TTextFile object with a file handle of FileNull and allocated a buffer of DefaultBufferSize...
virtual TCHAR * GetString(TCHAR *buffer, uint32 size)
Reads up to size characters and places them in buffer.
virtual bool WriteString(LPCTSTR str)
Writes the NULL terminated character string in buffer to the file and adds a terminating \r\n charact...
The TTime class encapsulates time functions and characteristics.
TXOwl(const tstring &msg, uint resId=0)
An OWL exception with a given message for displaying and an unsigned Id that can be used for identifi...
TByteOrderType
The byte order type.
TVarType
These identify host program variable types and let the binary I/O package read and write routines kno...
#define FileNull
Represents a NULL file handle.
TByteOrderType EndianType()
@ boLittle_Endian
LSB at lowest address: Intel //.
@ boBig_Endian
MSB at lowest address: Motorola //.
Object Windows Library (OWLNext Core).
owl::opstream & operator<<(owl::opstream &os, const TColor &c)
Insert the color value into a persistent output stream.
owl::ipstream & operator>>(owl::ipstream &is, TColor &c)
Extract the color value from a persistent input stream.
ObjectWindows exception class & function definitions.
The TBinField struct describes a group of like-typed fields in a structure to be read or written usin...
TVarType Type
Declared type of struct field.
RIFF chunk information data structure.
uint32 Flags
flags used by MMIO functions
uint32 Offset
offset of data portion of chunk
uint32 Type
form type or list type
tchar fullName[_MAX_PATH]
QuickTime atom information data structure.
uint32 Type
chunk identifier