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

The TFile class encapsulates standard file characteristics and operations. More...

#include <owl/file.h>

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

Public Types

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

 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.
 
virtual bool Close ()
 Closes the file. Returns true if successful, false otherwise.
 
virtual bool Length (uint64 newLen)
 Resizes file to newLen.
 
virtual uint64 Position64 () const
 32 Bit Only: Returns the current position of the file pointer.
 
virtual uint64 Length64 () const
 Returns the file length.
 
virtual bool Length (uint32 newLen)
 Resizes file to newLen.
 
virtual uint32 Position () const
 Returns the current position of the file pointer.
 
virtual uint32 Length () const
 Returns the file length.
 
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.
 
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.
 
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 ()
 Performs any pending I/O functions. Returns true if successful; false otherwise.
 
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 *)
 

Static Public Member Functions

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.
 

Protected Attributes

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.
 

Detailed Description

The TFile class encapsulates standard file characteristics and operations.

Definition at line 120 of file file.h.

Member Enumeration Documentation

◆ TAttribute

file attributes -> internally remapped into OS values

Enumerator
Normal 
RdOnly 
Hidden 
System 
Volume 
Directory 
Archive 
Temporary 

Definition at line 163 of file file.h.

◆ TBinType

Binary data type enumerations.

Enumerator
TypeChar 
TypeShort 
TypeLong 
TypeFloat 
TypeDouble 
TypeLong64 
TypePoint 
TypeRect 

Definition at line 175 of file file.h.

◆ TOpenMode

Open mode -> remapped into OS specific value internally.

Enumerator
ReadOnly 
WriteOnly 
ReadWrite 
PermWrite 

Subsequent open operations on the object will succeed only if write access is requested.

PermRead 

Subsequent open operations on the object will succeed only if read access is requested.

PermReadWrite 
PermExclusive 
PermNone 
CreateNew 

Creates a new file. The function fails if the specified file already exists.

CreateAlways 

Creates a new file. The function overwrites the file if it exists.

OpenExisting 

Opens the file. The function fails if the file does not exist.

TruncateExist 

Opens the file.

Once opened, the file is truncated so that its size is zero bytes. The calling process must open the file with at least WriteOnly access. The function fails if the file does not exist.

Text 

type Text are used in derived classes only default type is Binary

Definition at line 129 of file file.h.

◆ TSeekDir

Enumerator
beg 

Seek from the beginning of the file.

cur 

Seek from the current position in the file.

end 

Seek from the end of the file.

Definition at line 122 of file file.h.

Constructor & Destructor Documentation

◆ TFile() [1/4]

owl::TFile::TFile ( )
inline

Creates a TFile object with a file handle of FileNull.

Definition at line 715 of file file.h.

◆ TFile() [2/4]

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

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

Definition at line 724 of file file.h.

References Open().

◆ TFile() [3/4]

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

Creates a TFile 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 736 of file file.h.

◆ TFile() [4/4]

owl::TFile::TFile ( const TFile & file)

Definition at line 411 of file file.cpp.

References CHECK, Close(), FileNull, Handle, owl::TXNotSupportedCall::Raise(), and ShouldClose.

◆ ~TFile()

owl::TFile::~TFile ( )
virtual

If ShouldClose is true the file is closed.

If the Handle is not FileNull Handle is deleted. Buffer is deleted.

Definition at line 400 of file file.cpp.

References Buffer, Close(), FileNull, Handle, and ShouldClose.

Member Function Documentation

◆ Close()

bool owl::TFile::Close ( )
virtual

Closes the file. Returns true if successful, false otherwise.

Reimplemented in owl::TBufferedFile.

Definition at line 445 of file file.cpp.

References owl::TFileHandle::Close(), FileNull, Handle, IsOpen(), and ShouldClose.

◆ Flush()

bool owl::TFile::Flush ( )
virtual

Performs any pending I/O functions. Returns true if successful; false otherwise.

Reimplemented in owl::TBufferedFile.

Definition at line 460 of file file.cpp.

References owl::TFileHandle::Flush(), Handle, and PRECONDITION.

◆ GetHandle()

TFileHandle * owl::TFile::GetHandle ( ) const
inlinevirtual

Returns Handle.

Definition at line 743 of file file.h.

References Handle.

◆ GetName()

const tstring owl::TFile::GetName ( ) const
inline

Returns Name.

Definition at line 748 of file file.h.

References owl::TFileHandle::GetName(), Handle, and PRECONDITION.

◆ GetOpenMode()

uint32 owl::TFile::GetOpenMode ( ) const
inline

Returns OpenMode.

Definition at line 760 of file file.h.

References owl::TFileHandle::GetOpenMode(), Handle, and PRECONDITION.

◆ GetStatus()

bool owl::TFile::GetStatus ( TFileStatus & status) const
inline

Fills status with the current file status.

Returns true if successful, false otherwise.

Definition at line 899 of file file.h.

References owl::TFileHandle::GetStatus(), Handle, and PRECONDITION.

◆ IsOpen()

bool owl::TFile::IsOpen ( ) const
inline

Returns true if the file is open, false otherwise.

Definition at line 755 of file file.h.

References FileNull, and Handle.

◆ LastError()

uint32 owl::TFile::LastError ( )
inline

Returns the last error.

Under Windows 9x/NT this is a call to GetLastError().

Definition at line 798 of file file.h.

References Handle, owl::TFileHandle::LastError(), and PRECONDITION.

◆ Length() [1/3]

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

Returns the file length.

Reimplemented in owl::TBufferedFile.

Definition at line 828 of file file.h.

References Handle, owl::TFileHandle::Length(), and PRECONDITION.

◆ Length() [2/3]

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

Resizes file to newLen.

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

Reimplemented in owl::TBufferedFile.

Definition at line 836 of file file.h.

References Handle, owl::TFileHandle::Length(), and PRECONDITION.

◆ Length() [3/3]

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

Resizes file to newLen.

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

Reimplemented in owl::TBufferedFile.

Definition at line 853 of file file.h.

References Handle, owl::TFileHandle::Length(), and PRECONDITION.

◆ Length64()

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

Returns the file length.

Reimplemented in owl::TBufferedFile.

Definition at line 867 of file file.h.

References Handle, owl::TFileHandle::Length64(), and PRECONDITION.

◆ LockRange() [1/2]

bool owl::TFile::LockRange ( uint32 position,
uint32 count )
virtual

Locks count bytes, beginning at position of the file.

Returns true if successful; false otherwise.

Definition at line 469 of file file.cpp.

References Handle, owl::TFileHandle::LockRange(), and PRECONDITION.

◆ LockRange() [2/2]

bool owl::TFile::LockRange ( uint64 position,
uint64 count )
inlinevirtual

Locks count bytes, beginning at position of the file.

Returns true if successful; false otherwise.

Definition at line 883 of file file.h.

References Handle, owl::TFileHandle::LockRange(), and PRECONDITION.

◆ Open()

bool owl::TFile::Open ( const tstring & fileName,
const uint32 openMode = ReadOnly|PermRead|OpenExisting )
virtual

Opens file name with the given mode.

Returns true if successful, false otherwise. Calling Open when the file is already open will fail.

Reimplemented in owl::TStreamFile.

Definition at line 429 of file file.cpp.

References FileNull, Handle, IsOpen(), owl::TFileHandle::IsOpen(), and ShouldClose.

◆ Position()

uint32 owl::TFile::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 in owl::TBufferedFile.

Definition at line 821 of file file.h.

References Handle, owl::TFileHandle::Position(), and PRECONDITION.

◆ Position64()

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

32 Bit Only: Returns the current position of the file pointer.

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

Reimplemented in owl::TBufferedFile.

Definition at line 861 of file file.h.

References Handle, owl::TFileHandle::Position64(), and PRECONDITION.

◆ Read()

uint32 owl::TFile::Read ( void * buffer,
uint32 numBytes )
inlinevirtual

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

Reimplemented in owl::TBufferedFile.

Definition at line 805 of file file.h.

References Handle, PRECONDITION, and owl::TFileHandle::Read().

◆ readDouble()

double owl::TFile::readDouble ( )
virtual

Reimplemented in owl::TTextFile.

Definition at line 997 of file file.cpp.

References owl::boLittle_Endian, ReadStruct(), and TypeDouble.

◆ readFloat()

float owl::TFile::readFloat ( )
virtual

Reimplemented in owl::TTextFile.

Definition at line 988 of file file.cpp.

References owl::boLittle_Endian, ReadStruct(), and TypeFloat.

◆ readString()

TCHAR * owl::TFile::readString ( tchar * str)
inlinevirtual

Reimplemented in owl::TTextFile.

Definition at line 906 of file file.h.

References Read(), and TFILE_ERROR.

◆ ReadStruct() [1/3]

uint owl::TFile::ReadStruct ( uint8 * ReadBuf,
void * buffer,
TBinField * fields,
TByteOrderType type )
static

Read binary structure from buffer.

Returns # of bytes read

Definition at line 775 of file file.cpp.

References BINCHECKNBYTES, BINCHECKRTYPE, owl::boBig_Endian, owl::EndianType(), and StructSize().

◆ ReadStruct() [2/3]

uint owl::TFile::ReadStruct ( void * buffer,
TBinField * fields,
TByteOrderType type )

Read binary structure from file.

Returns # of bytes read

Definition at line 667 of file file.cpp.

References BINCHECKNBYTES, BINCHECKRTYPE, owl::boBig_Endian, Buffer, BufSize, owl::EndianType(), Read(), and StructSize().

◆ ReadStruct() [3/3]

uint owl::TFile::ReadStruct ( void * buffer,
TBinType btype,
TByteOrderType type )

Read binary predefined structure from file.

Returns # of bytes read

Definition at line 908 of file file.cpp.

References ReadStruct().

◆ readUint16()

uint16 owl::TFile::readUint16 ( )
virtual

Reimplemented in owl::TTextFile.

Definition at line 962 of file file.cpp.

References owl::boLittle_Endian, ReadStruct(), and TypeShort.

◆ readUint32()

uint32 owl::TFile::readUint32 ( )
virtual

Reimplemented in owl::TTextFile.

Definition at line 972 of file file.cpp.

References owl::boLittle_Endian, ReadStruct(), and TypeLong.

◆ readUint64()

uint64 owl::TFile::readUint64 ( )
virtual

Reimplemented in owl::TTextFile.

Definition at line 980 of file file.cpp.

References owl::boLittle_Endian, ReadStruct(), and TypeLong64.

◆ readUint8()

uint8 owl::TFile::readUint8 ( )
virtual

Reimplemented in owl::TTextFile.

Definition at line 953 of file file.cpp.

References Read().

◆ Seek() [1/2]

uint64 owl::TFile::Seek ( int64 offset,
TSeekDir origin = beg )
inlinevirtual

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

Returns the position moved to or TFILE64_ERROR on error. To get extended error information, call LastError.

Reimplemented in owl::TBufferedFile.

Definition at line 875 of file file.h.

References Handle, PRECONDITION, and owl::TFileHandle::Seek().

◆ Seek() [2/2]

uint32 owl::TFile::Seek ( long offset,
TSeekDir origin = beg )
inlinevirtual

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

Returns the position moved to or TFILE_ERROR on error. To get extended error information, call LastError.

Reimplemented in owl::TBufferedFile.

Definition at line 845 of file file.h.

References Handle, PRECONDITION, and owl::TFileHandle::Seek().

◆ SeekToBegin()

uint32 owl::TFile::SeekToBegin ( )
inline

Repositions the file pointer to the beginning of the file.

Returns the position moved to or TFILE_ERROR on error. To get extended error information, call LastError.

Definition at line 769 of file file.h.

References beg, and Seek().

◆ SeekToBegin64()

uint64 owl::TFile::SeekToBegin64 ( )
inline

Repositions the file pointer to the beginning of the file.

Returns the position moved to or TFILE64_ERROR on error. To get extended error information, call LastError.

Definition at line 782 of file file.h.

References beg, and Seek().

◆ SeekToEnd()

uint32 owl::TFile::SeekToEnd ( )
inline

Repositions the file pointer to the end of the file.

Returns the position moved to or TFILE_ERROR on error. To get extended error information, call LastError.

Definition at line 775 of file file.h.

References end, and Seek().

◆ SeekToEnd64()

uint64 owl::TFile::SeekToEnd64 ( )
inline

Repositions the file pointer to the end of the file.

Returns the position moved to or TFILE64_ERROR on error. To get extended error information, call LastError.

Definition at line 789 of file file.h.

References end, and Seek().

◆ StructSize()

uint owl::TFile::StructSize ( TBinField * fields)
static

Returns the number of bytes in a binary data structure.

Definition at line 657 of file file.cpp.

◆ UnlockRange() [1/2]

bool owl::TFile::UnlockRange ( uint32 position,
uint32 count )
virtual

Unlocks the range at the given Position.

Returns true if successful; false otherwise.

Definition at line 477 of file file.cpp.

References Handle, PRECONDITION, and owl::TFileHandle::UnlockRange().

◆ UnlockRange() [2/2]

bool owl::TFile::UnlockRange ( uint64 position,
uint64 count )
inlinevirtual

32 Bit Only: Unlocks the range at the given Position.

Returns true if successful; false otherwise.

Definition at line 891 of file file.h.

References Handle, PRECONDITION, and owl::TFileHandle::UnlockRange().

◆ Write()

bool owl::TFile::Write ( const void * buffer,
uint32 numBytes )
inlinevirtual

Writes numbytes of buffer to the file.

Returns true if the operation is successful; false otherwise.

Reimplemented in owl::TBufferedFile.

Definition at line 813 of file file.h.

References Handle, PRECONDITION, and owl::TFileHandle::Write().

◆ writeDouble()

void owl::TFile::writeDouble ( const double d)
virtual

Reimplemented in owl::TTextFile.

Definition at line 1039 of file file.cpp.

References owl::boLittle_Endian, TypeDouble, and WriteStruct().

◆ writeFloat()

void owl::TFile::writeFloat ( const float f)
virtual

Reimplemented in owl::TTextFile.

Definition at line 1032 of file file.cpp.

References owl::boLittle_Endian, TypeFloat, and WriteStruct().

◆ writeString()

void owl::TFile::writeString ( const tchar * str)
inlinevirtual

Reimplemented in owl::TTextFile.

Definition at line 913 of file file.h.

References _tcslen, and Write().

◆ WriteStruct() [1/3]

uint owl::TFile::WriteStruct ( uint8 * OutBuf,
void * buffer,
TBinField * fields,
TByteOrderType type )
static

Writes structures to buffer based on fields description.

Returns # of bytes written

Definition at line 820 of file file.cpp.

References BINCHECKNBYTES, BINCHECKRTYPE, owl::boBig_Endian, owl::EndianType(), and StructSize().

◆ WriteStruct() [2/3]

uint owl::TFile::WriteStruct ( void * buffer,
TBinField * fields,
TByteOrderType type )

Writes structures to binary file based on fields description.

Returns # of bytes written

Definition at line 723 of file file.cpp.

References BINCHECKNBYTES, BINCHECKRTYPE, owl::boBig_Endian, Buffer, BufSize, owl::EndianType(), StructSize(), and Write().

◆ WriteStruct() [3/3]

uint owl::TFile::WriteStruct ( void * buffer,
TBinType btype,
TByteOrderType type )

Writes predefined structures to binary file.

Definition at line 914 of file file.cpp.

References WriteStruct().

◆ writeUint16()

void owl::TFile::writeUint16 ( const uint16 i)
virtual

Reimplemented in owl::TTextFile.

Definition at line 1011 of file file.cpp.

References owl::boLittle_Endian, TypeShort, and WriteStruct().

◆ writeUint32()

void owl::TFile::writeUint32 ( const uint32 i)
virtual

Reimplemented in owl::TTextFile.

Definition at line 1018 of file file.cpp.

References owl::boLittle_Endian, TypeLong, and WriteStruct().

◆ writeUint64()

void owl::TFile::writeUint64 ( const uint64 i)
virtual

Reimplemented in owl::TTextFile.

Definition at line 1025 of file file.cpp.

References owl::boLittle_Endian, TypeLong64, and WriteStruct().

◆ writeUint8()

void owl::TFile::writeUint8 ( const uint8 c)
virtual

Reimplemented in owl::TTextFile.

Definition at line 1005 of file file.cpp.

References Write().

Member Data Documentation

◆ Buffer

uint8* owl::TFile::Buffer
protected

Buffer used with structure read/write.

Definition at line 272 of file file.h.

◆ BufSize

uint owl::TFile::BufSize
protected

Size of Buffer used with structure read/write.

Definition at line 275 of file file.h.

◆ Handle

TFileHandle* owl::TFile::Handle
protected

Low-level C file handle.

Definition at line 266 of file file.h.

◆ ShouldClose

bool owl::TFile::ShouldClose
protected

Should C++ object close file on dtor.

Definition at line 267 of file file.h.


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