OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
owl::TBufferedFile Class Reference

The TBufferedFile class is derived from TFile encapsulates standard file characteristics and operations using buffered I/O. More...

#include <owl/file.h>

Inheritance diagram for owl::TBufferedFile:
owl::TFile owl::TQtFile owl::TRiffFile owl::TTextFile

Public Types

enum  { DefaultBufferSize = 2048 }
 The initial size of the buffer. More...
 
- Public Types inherited from owl::TFile
enum  TSeekDir { beg = 0 , cur = 1 , end = 2 }
 
enum  TOpenMode {
  ReadOnly = 0x0001 , WriteOnly = 0x0002 , ReadWrite = WriteOnly|ReadOnly , PermWrite = 0x0010 , PermRead = 0x0020 , PermReadWrite = PermWrite|PermRead , PermExclusive = 0x0040 , PermNone = 0x0080 , CreateNew = 0x0100 , CreateAlways = 0x0200 ,
  OpenExisting = 0x0400 , TruncateExist = 0x0800 , Text = 0x1000
}
 Open mode -> remapped into OS specific value internally. More...
 
enum  TAttribute { Normal = 0x00 , RdOnly = 0x01 , Hidden = 0x02 , System = 0x04 , Volume = 0x08 , Directory = 0x10 , Archive = 0x20 , Temporary = 0x40 }
 file attributes -> internally remapped into OS values More...
 
enum  TBinType { TypeChar , TypeShort , TypeLong , TypeFloat , TypeDouble , TypeLong64 , TypePoint , TypeRect }
 Binary data type enumerations. More...
 

Public Member Functions

 TBufferedFile ()
 Creates a TBufferedFile object with a file handle of FileNull and allocated a buffer of DefaultBufferSize bytes.
 
 TBufferedFile (const tstring &fileName, const uint32 mode=ReadOnly|PermRead|OpenExisting)
 Creates a TBufferedFile object and opens file name with the given attributes.
 
 TBufferedFile (const TBufferedFile &file)
 
 TBufferedFile (TFileHandle *handle, bool shouldClose)
 Creates a TBufferedFile object with a file handle of handle.
 
virtual ~TBufferedFile ()
 The buffer is flushed. If ShouldDelete is true the buffer is deleted.
 
virtual bool Close ()
 Flushes the buffer and closes the file.
 
virtual bool Length (uint64 newLen)
 Flushes the buffer and then resizes file to newLen.
 
virtual uint64 Position64 () const
 Returns the current position of the file pointer.
 
virtual uint64 Length64 () const
 Returns the file length plus the length of unwritten data in the buffer.
 
virtual uint32 Position () const
 Returns the current position of the file pointer.
 
virtual uint32 Length () const
 Returns the file length plus the length of unwritten data in the buffer.
 
virtual bool Length (uint32 newLen)
 Flushes the buffer and then resizes file to newLen.
 
virtual uint64 Seek (int64 offset, TSeekDir origin=beg)
 Repositions the file pointer to offset bytes from the specified origin.
 
virtual uint32 Seek (long offset, TSeekDir origin=beg)
 Repositions the file pointer to offset bytes from the specified origin.
 
virtual uint32 Read (void *buffer, uint32 numBytes)
 Reads numBytes from the file into buffer. The number of bytes read is returned.
 
virtual bool Write (const void *buffer, uint32 numBytes)
 Writes numBytes of buffer to the file.
 
virtual bool Flush ()
 Writes any data in the buffer to file and then resets the buffer.
 
virtual void SetBuffer (uint8 *buffer, uint size, bool shouldDelete=true)
 Flushes the current buffer and then deletes it if ShouldDelete is true.
 
- Public Member Functions inherited from owl::TFile
 TFile ()
 Creates a TFile object with a file handle of FileNull.
 
 TFile (const tstring &fileName, const uint32 mode=ReadOnly|PermRead|OpenExisting)
 Creates a TFile object and opens file name with the given attributes.
 
 TFile (TFileHandle *handle, bool shouldClose)
 Creates a TFile object with a file handle of handle.
 
 TFile (const TFile &file)
 
virtual ~TFile ()
 If ShouldClose is true the file is closed.
 
virtual TFileHandleGetHandle () const
 Returns Handle.
 
const tstring GetName () const
 Returns Name.
 
virtual bool Open (const tstring &fileName, const uint32 mode=ReadOnly|PermRead|OpenExisting)
 Opens file name with the given mode.
 
uint64 SeekToBegin64 ()
 Repositions the file pointer to the beginning of the file.
 
uint64 SeekToEnd64 ()
 Repositions the file pointer to the end of the file.
 
uint32 SeekToBegin ()
 Repositions the file pointer to the beginning of the file.
 
uint32 SeekToEnd ()
 Repositions the file pointer to the end of the file.
 
bool IsOpen () const
 Returns true if the file is open, false otherwise.
 
uint32 GetOpenMode () const
 Returns OpenMode.
 
uint32 LastError ()
 Returns the last error.
 
uint ReadStruct (void *buffer, TBinType btype, TByteOrderType type)
 Read binary predefined structure from file.
 
uint ReadStruct (void *buffer, TBinField *fields, TByteOrderType type)
 Read binary structure from file.
 
uint WriteStruct (void *buffer, TBinType btype, TByteOrderType type)
 Writes predefined structures to binary file.
 
uint WriteStruct (void *buffer, TBinField *fields, TByteOrderType type)
 Writes structures to binary file based on fields description.
 
virtual bool LockRange (uint32 position, uint32 count)
 Locks count bytes, beginning at position of the file.
 
virtual bool UnlockRange (uint32 position, uint32 count)
 Unlocks the range at the given Position.
 
virtual bool LockRange (uint64 position, uint64 count)
 Locks count bytes, beginning at position of the file.
 
virtual bool UnlockRange (uint64 position, uint64 count)
 32 Bit Only: Unlocks the range at the given Position.
 
bool GetStatus (TFileStatus &status) const
 Fills status with the current file status.
 
virtual uint8 readUint8 ()
 
virtual uint16 readUint16 ()
 
virtual uint32 readUint32 ()
 
virtual uint64 readUint64 ()
 
virtual float readFloat ()
 
virtual double readDouble ()
 
virtual TCHARreadString (tchar *)
 
virtual void writeUint8 (const uint8)
 
virtual void writeUint16 (const uint16)
 
virtual void writeUint32 (const uint32)
 
virtual void writeUint64 (const uint64)
 
virtual void writeFloat (const float)
 
virtual void writeDouble (const double)
 
virtual void writeString (const tchar *)
 

Protected Member Functions

virtual void InitBuffer (uint size=DefaultBufferSize)
 Allocates a buffer of size bytes.
 
virtual bool FlushBuffer ()
 Flushes the buffer by writing any unwritten data to the file.
 

Protected Attributes

uint8FileBuffer
 Buffer used to store data in.
 
bool ShouldDelete
 True if the buffer should be deleted.
 
uint FileBufSize
 Size of FileBuffer in bytes.
 
uint8CurByte
 Pointer to current position in the buffer.
 
uint32 CurPos
 Offset in file to current position.
 
uint32 StartPos
 Offset in file to byte 0 of the buffer.
 
uint32 EndPos
 Offset in file to the last data byte in the buffer.
 
bool BufferEmpty
 True if the buffer is empty; false otherwise.
 
- Protected Attributes inherited from owl::TFile
TFileHandleHandle
 Low-level C file handle.
 
bool ShouldClose
 Should C++ object close file on dtor.
 
uint8Buffer
 Buffer used with structure read/write.
 
uint BufSize
 Size of Buffer used with structure read/write.
 

Additional Inherited Members

- Static Public Member Functions inherited from owl::TFile
static uint ReadStruct (uint8 *readBuf, void *buffer, TBinField *fields, TByteOrderType type)
 Read binary structure from buffer.
 
static uint WriteStruct (uint8 *writeBuf, void *buffer, TBinField *fields, TByteOrderType type)
 Writes structures to buffer based on fields description.
 
static uint StructSize (TBinField *fields)
 Returns the number of bytes in a binary data structure.
 

Detailed Description

The TBufferedFile class is derived from TFile encapsulates standard file characteristics and operations using buffered I/O.

Definition at line 369 of file file.h.

Member Enumeration Documentation

◆ anonymous enum

The initial size of the buffer.

Enumerator
DefaultBufferSize 

Definition at line 372 of file file.h.

Constructor & Destructor Documentation

◆ TBufferedFile() [1/4]

owl::TBufferedFile::TBufferedFile ( )
inline

Creates a TBufferedFile object with a file handle of FileNull and allocated a buffer of DefaultBufferSize bytes.

Definition at line 1051 of file file.h.

References InitBuffer().

◆ TBufferedFile() [2/4]

owl::TBufferedFile::TBufferedFile ( const tstring & fileName,
const uint32 mode = ReadOnly|PermRead|OpenExisting )
inline

Creates a TBufferedFile object and opens file name with the given attributes.

Definition at line 1072 of file file.h.

References InitBuffer().

◆ TBufferedFile() [3/4]

owl::TBufferedFile::TBufferedFile ( const TBufferedFile & file)
inline

Definition at line 1054 of file file.h.

References InitBuffer().

◆ TBufferedFile() [4/4]

owl::TBufferedFile::TBufferedFile ( TFileHandle * handle,
bool shouldClose )
inline

Creates a TBufferedFile object with a file handle of handle.

Set shouldClose true if the file should be closed on deletion

Note
this function can only be used within file.cpp.

Definition at line 1064 of file file.h.

References InitBuffer().

◆ ~TBufferedFile()

owl::TBufferedFile::~TBufferedFile ( )
virtual

The buffer is flushed. If ShouldDelete is true the buffer is deleted.

Definition at line 1053 of file file.cpp.

References FileBuffer, FlushBuffer(), and ShouldDelete.

Member Function Documentation

◆ Close()

bool owl::TBufferedFile::Close ( )
inlinevirtual

Flushes the buffer and closes the file.

Returns true if successful, false otherwise.

Reimplemented from owl::TFile.

Definition at line 1082 of file file.h.

References owl::TFile::Close(), and FlushBuffer().

◆ Flush()

bool owl::TBufferedFile::Flush ( )
inlinevirtual

Writes any data in the buffer to file and then resets the buffer.

Returns true if successful; false otherwise.

Reimplemented from owl::TFile.

Definition at line 1124 of file file.h.

References owl::TFile::Flush(), and FlushBuffer().

◆ FlushBuffer()

bool owl::TBufferedFile::FlushBuffer ( )
protectedvirtual

Flushes the buffer by writing any unwritten data to the file.

This function is called by Flush() before the operating system is called to flush its buffers.

Definition at line 1073 of file file.cpp.

References BufferEmpty, CurByte, CurPos, EndPos, FileBuffer, FileBufSize, owl::TFile::GetHandle(), owl::TFile::GetOpenMode(), StartPos, WARNX, owl::TFile::Write(), and owl::TFile::WriteOnly.

◆ InitBuffer()

void owl::TBufferedFile::InitBuffer ( uint size = DefaultBufferSize)
protectedvirtual

Allocates a buffer of size bytes.

Definition at line 1062 of file file.cpp.

References BufferEmpty, CurByte, CurPos, EndPos, FileBuffer, FileBufSize, ShouldDelete, and StartPos.

◆ Length() [1/3]

uint32 owl::TBufferedFile::Length ( ) const
inlinevirtual

Returns the file length plus the length of unwritten data in the buffer.

Reimplemented from owl::TFile.

Definition at line 1110 of file file.h.

References CurPos, owl::TFile::Length(), and StartPos.

◆ Length() [2/3]

bool owl::TBufferedFile::Length ( uint32 newLen)
inlinevirtual

Flushes the buffer and then resizes file to newLen.

Returns true if successful, false otherwise. The file must first be opened for success.

Reimplemented from owl::TFile.

Definition at line 1115 of file file.h.

References FlushBuffer(), and owl::TFile::Length().

◆ Length() [3/3]

bool owl::TBufferedFile::Length ( uint64 newLen)
inlinevirtual

Flushes the buffer and then resizes file to newLen.

Returns true if successful, false otherwise. The file must first be opened for success.

Reimplemented from owl::TFile.

Definition at line 1090 of file file.h.

References FlushBuffer(), and owl::TFile::Length().

◆ Length64()

uint64 owl::TBufferedFile::Length64 ( ) const
inlinevirtual

Returns the file length plus the length of unwritten data in the buffer.

Reimplemented from owl::TFile.

Definition at line 1096 of file file.h.

References CurPos, owl::TFile::Length64(), and StartPos.

◆ Position()

uint32 owl::TBufferedFile::Position ( ) const
inlinevirtual

Returns the current position of the file pointer.

Returns TFILE_ERROR to indicate an error. To get extended error information, call LastError.

Reimplemented from owl::TFile.

Definition at line 1106 of file file.h.

References CurPos.

◆ Position64()

uint64 owl::TBufferedFile::Position64 ( ) const
inlinevirtual

Returns the current position of the file pointer.

Returns TFILE64_ERROR to indicate an error. To get extended error information, call LastError.

Reimplemented from owl::TFile.

Definition at line 1101 of file file.h.

References CurPos.

◆ Read()

uint32 owl::TBufferedFile::Read ( void * buffer,
uint32 numBytes )
virtual

Reads numBytes from the file into buffer. The number of bytes read is returned.

Reimplemented from owl::TFile.

Definition at line 1203 of file file.cpp.

References BufferEmpty, CurByte, CurPos, EndPos, FileBuffer, FileBufSize, owl::TFile::GetHandle(), Position(), PRECONDITION, owl::TFile::Read(), StartPos, TFILE_ERROR, and WARNX.

◆ Seek() [1/2]

uint64 owl::TBufferedFile::Seek ( int64 offset,
TSeekDir origin = beg )
virtual

Repositions the file pointer to offset bytes from the specified origin.

If the position moved to is outside of the buffer, the buffer is flushed. Returns the position moved to or TFILE64_ERROR on error. To get extended error information, call LastError.

Reimplemented from owl::TFile.

Definition at line 1120 of file file.cpp.

References BufferEmpty, owl::TFile::cur, CurByte, CurPos, owl::TFile::end, EndPos, FileBuffer, FileBufSize, FlushBuffer(), owl::TFile::GetHandle(), Length64(), PRECONDITION, owl::TFile::Seek(), StartPos, TFILE64_ERROR, and WARNX.

◆ Seek() [2/2]

uint32 owl::TBufferedFile::Seek ( long offset,
TSeekDir origin = beg )
virtual

Repositions the file pointer to offset bytes from the specified origin.

If the position moved to is outside of the buffer, the buffer is flushed. Returns the position moved to or TFILE_ERROR on error. To get extended error information, call LastError.

Reimplemented from owl::TFile.

Definition at line 1163 of file file.cpp.

References BufferEmpty, owl::TFile::cur, CurByte, CurPos, owl::TFile::end, EndPos, FileBuffer, FileBufSize, FlushBuffer(), owl::TFile::GetHandle(), Length(), PRECONDITION, owl::TFile::Seek(), StartPos, TFILE_ERROR, and WARNX.

◆ SetBuffer()

void owl::TBufferedFile::SetBuffer ( uint8 * buffer,
uint size,
bool shouldDelete = true )
virtual

Flushes the current buffer and then deletes it if ShouldDelete is true.

If buffer is not NULL it is assigned to FileBuffer; otherwise FileBuffer is allocated size bytes. ShouldDelete is then set.

Definition at line 1096 of file file.cpp.

References CurByte, EndPos, FileBuffer, FileBufSize, FlushBuffer(), ShouldDelete, and StartPos.

◆ Write()

bool owl::TBufferedFile::Write ( const void * buffer,
uint32 numBytes )
virtual

Writes numBytes of buffer to the file.

If numBytes is greater than the size of the buffer the buffer is flushed and the data is written directly to the file; if the amount of data in the buffer plus numBytes is greater than the capacity of the buffer the buffer is filled and written to the file and the remaining data is placed in the buffer; otherwise the data is appended to the buffer. Returns true if the operation is successful; false otherwise.

Reimplemented from owl::TFile.

Definition at line 1281 of file file.cpp.

References CurByte, CurPos, EndPos, FileBuffer, FileBufSize, FlushBuffer(), owl::TFile::GetHandle(), Position(), PRECONDITION, StartPos, WARNX, and owl::TFile::Write().

Member Data Documentation

◆ BufferEmpty

bool owl::TBufferedFile::BufferEmpty
protected

True if the buffer is empty; false otherwise.

Definition at line 428 of file file.h.

◆ CurByte

uint8* owl::TBufferedFile::CurByte
protected

Pointer to current position in the buffer.

Definition at line 416 of file file.h.

◆ CurPos

uint32 owl::TBufferedFile::CurPos
protected

Offset in file to current position.

Definition at line 419 of file file.h.

◆ EndPos

uint32 owl::TBufferedFile::EndPos
protected

Offset in file to the last data byte in the buffer.

Definition at line 425 of file file.h.

◆ FileBuffer

uint8* owl::TBufferedFile::FileBuffer
protected

Buffer used to store data in.

Definition at line 407 of file file.h.

◆ FileBufSize

uint owl::TBufferedFile::FileBufSize
protected

Size of FileBuffer in bytes.

Definition at line 413 of file file.h.

◆ ShouldDelete

bool owl::TBufferedFile::ShouldDelete
protected

True if the buffer should be deleted.

Definition at line 410 of file file.h.

◆ StartPos

uint32 owl::TBufferedFile::StartPos
protected

Offset in file to byte 0 of the buffer.

Definition at line 422 of file file.h.


The documentation for this class was generated from the following files: