TFile Class Reference

This class encapsulates reading and writing from file. More...

#include <File.h>

Inheritance diagram for TFile:

Inheritance graph
[legend]
Collaboration diagram for TFile:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TFile (void)
 Constructor.
 ~TFile (void)
 Destructor.
 TFile (const TFile &orig)
 fake copy constructor
void operator= (const TFile &orig)
 fake assignment operator
const TStringGetName (void) const
 Return relative filename (relative path + filename) of opened file.
BOOL IsBinary (void) const
 Determines whether file is opened as binary, if return FALSE file is opened in translated mode.
BOOL IsOpened (void) const
 Determines whether file is opened.
BOOL Open (const TString &name, BOOL binary)
 Open specified file.
BOOL Close (void)
 Close opened file.
DWORD Read (void *buffer, const DWORD &size)
 Reads data from file into buffer.
DWORD Write (const void *buffer, const DWORD &size)
 Writes data to file from buffer.
int GetChar (void)
 Return character from file.
int PutChar (const int &character)
 Put character into file.
BOOL Write (const TString &str)
 Writes string into file.
BOOL Seek (const DWORD &position)
 Move pointer in file to specified location from begin of file.
BOOL SeekRelative (const LONG &position)
 Move pointer into file to specified location relative to actual position.
BOOL SeekToEnd (void)
 Move pointer to end of this file.
void Rewind (void)
 Rewind this file to begin.
LONG Tell (void)
 Returns actual position in file.
BOOL Eof (void)
 Tests for end of file (for READ operations only).
BOOL Erase (void)
 Erase contents of file.
BOOL Flush (void)
 Flushes actually buffered data from stream to file on disk.
DWORD GetSize (void)
 Return file size in bytes.
BOOL FindChar (int ch)
 Find next character in file.
BOOL SkipNextBlock (void)
 Find first block "{...}" and skip it.
BOOL ReadUntil (int ch, TString &res)
 Read file until specified character and store it into string.
BOOL ReadString (TString &text)
 Read next string - "..".
BOOL ReadWord (TString &text)
 Read next word from file.

Static Public Member Functions

static BOOL IsExists (const char *filename)
 This method determines whether specified file exists.

Detailed Description

This class encapsulates reading and writing from file.

File is opened for reading and writing together, but between these operations Flush() method should be called for safe storing buffered data.

File is opened after calling TFile::Open method, constructor only prepares object.

Because each mode (read,write) are defined for opened file if file not exists it will be created, thus if you need perform READ operation you should use static method IsExists which check file existence (if you don't this then empty file will be created and you read 0 bytes in you reading loop).

Definition at line 35 of file File.h.


Constructor & Destructor Documentation

TFile::TFile void   ) 
 

Constructor.

This method doesnt open file!!!

Definition at line 23 of file File.cpp.

References FALSE.

TFile::~TFile void   ) 
 

Destructor.

Automatically close opened file - if exists.

Definition at line 33 of file File.cpp.

References FALSE.

TFile::TFile const TFile orig  ) 
 

fake copy constructor


Member Function Documentation

BOOL TFile::Close void   ) 
 

Close opened file.

Definition at line 84 of file File.cpp.

References DBGCNDTRACEF, and FALSE.

Referenced by NSXLoader::TXLoader::LoadFile(), Open(), and NSXLoader::TXLoader::~TXLoader().

BOOL TFile::Eof void   )  [inline]
 

Tests for end of file (for READ operations only).

Definition at line 201 of file File.h.

References DBGASSERT.

BOOL TFile::Erase void   ) 
 

Erase contents of file.

After this operation is possible write to empty file.

Definition at line 103 of file File.cpp.

References DBGASSERT, FALSE, TString::GetString(), and TRUE.

Here is the call graph for this function:

BOOL TFile::FindChar int  ch  ) 
 

Find next character in file.

File would be in translated mode for calling this method!

If returns TRUE chracter was found and file is at position after this character.

Parameters:
ch [in] character to find

Definition at line 143 of file File.cpp.

References DBGASSERT, DBGCNDTRACEF, FALSE, and TRUE.

BOOL TFile::Flush void   )  [inline]
 

Flushes actually buffered data from stream to file on disk.

This operation should be called between read and write operation.

Definition at line 192 of file File.h.

References DBGASSERT.

int TFile::GetChar void   )  [inline]
 

Return character from file.

Behavior of this method is identical to fgetc from CRT.

Definition at line 211 of file File.h.

References DBGASSERT.

const TString & TFile::GetName void   )  const [inline]
 

Return relative filename (relative path + filename) of opened file.

Definition at line 92 of file File.h.

DWORD TFile::GetSize void   ) 
 

Return file size in bytes.

This method automaticaly flushes data from buffer to stream.

Definition at line 122 of file File.cpp.

References DBGASSERT.

BOOL TFile::IsBinary void   )  const [inline]
 

Determines whether file is opened as binary, if return FALSE file is opened in translated mode.

Definition at line 99 of file File.h.

BOOL TFile::IsExists const char *  filename  )  [static]
 

This method determines whether specified file exists.

Parameters:
filename [in] name of file to check

Definition at line 303 of file File.cpp.

BOOL TFile::IsOpened void   )  const [inline]
 

Determines whether file is opened.

Definition at line 106 of file File.h.

Referenced by NSXLoader::TXLoader::LoadFile(), and NSXLoader::TXLoader::~TXLoader().

BOOL TFile::Open const TString name,
BOOL  binary
 

Open specified file.

Parameters:
name [in] name of file to open
binary [in] specifies whether file should be opened as binary(TRUE) or in translated mode(FALSE)
Returns:
TRUE if file was successfully opened, otherwise return FALSE

Definition at line 51 of file File.cpp.

References Close(), FALSE, TString::GetString(), and TString::Set().

Referenced by TCRC::ComputeFileCRC32(), NSConfigFile::TConfigFile::LoadConfigFile(), NSXLoader::TXLoader::LoadFile(), NSFileSystem::TFSCabinetTable::LoadTableFromFile(), and NSConfigFile::TConfigFile::SaveConfigFile().

Here is the call graph for this function:

void TFile::operator= const TFile orig  ) 
 

fake assignment operator

int TFile::PutChar const int &  character  )  [inline]
 

Put character into file.

Behavior of this method is identical to fputc from CRT.

Parameters:
character [in] written character

Definition at line 223 of file File.h.

References DBGASSERT.

Referenced by NSConfigFile::TConfigFileSection::WriteToFile().

DWORD TFile::Read void *  buffer,
const DWORD size
[inline]
 

Reads data from file into buffer.

Parameters:
buffer [out] buffer for readed data (there must be enaugh allocated bytes - minimal SIZE - see next parameter)
size [in] number of bytes to read
Returns:
number of readed bytes

Definition at line 118 of file File.h.

References DBGASSERT.

BOOL TFile::ReadString TString text  ) 
 

Read next string - "..".

Method founds first character '"' and then reads string until next ". Final string doesnt contain begin and end character '"'. String parameter TEXT is always cleared.

After returning TRUE position in file is set to first character after end of string (after '"');

Readed string musnt contains symbol '"' - escape characters arent recognized too.

Parameters:
text [out] output string
Returns:
TRUE if an string was found, FALSE otherwise.

Definition at line 235 of file File.cpp.

References TString::Add(), TString::Clear(), DBGASSERT, FALSE, and TRUE.

Here is the call graph for this function:

BOOL TFile::ReadUntil int  ch,
TString res
 

Read file until specified character and store it into string.

Terminal character is not included in result string.

String RES is automatically clearer in function.

Parameters:
ch [in] terminal string
res [out] output string
Returns:
TRUE if specified character was found, FALSE otherwise (EOF was reached and terminal character was not found)

Definition at line 205 of file File.cpp.

References TString::Add(), TString::Clear(), DBGASSERT, FALSE, and TRUE.

Here is the call graph for this function:

BOOL TFile::ReadWord TString text  ) 
 

Read next word from file.

Word is end with white space (according to isspace macro) or EOF. White spaces before word are ommited.

Method search first non-white space and continue until next white space. Result is stored in parameter only if TRUE is returned.

String parameter TEXT is always cleared.

Parameters:
text [out] output string

Definition at line 270 of file File.cpp.

References TString::Add(), TString::Clear(), DBGASSERT, FALSE, and TRUE.

Here is the call graph for this function:

void TFile::Rewind void   )  [inline]
 

Rewind this file to begin.

Definition at line 173 of file File.h.

References DBGASSERT.

BOOL TFile::Seek const DWORD position  )  [inline]
 

Move pointer in file to specified location from begin of file.

Position must be in range of file size!!!

Parameters:
position [in] new position of pointer from begin

Definition at line 144 of file File.h.

References DBGASSERT.

BOOL TFile::SeekRelative const LONG position  )  [inline]
 

Move pointer into file to specified location relative to actual position.

Parameters:
position [in] offset of actual position

Definition at line 155 of file File.h.

References DBGASSERT.

BOOL TFile::SeekToEnd void   )  [inline]
 

Move pointer to end of this file.

Definition at line 164 of file File.h.

References DBGASSERT.

BOOL TFile::SkipNextBlock void   ) 
 

Find first block "{...}" and skip it.

File would be in translated mode for calling this method!

Inner blocks are skiped too.

Returns TRUE if block was successfully skipped, FALSE otherwise (probably EOF).

Definition at line 163 of file File.cpp.

References DBGASSERT, DBGCNDTRACEF, FALSE, and TRUE.

LONG TFile::Tell void   )  [inline]
 

Returns actual position in file.

Definition at line 182 of file File.h.

References DBGASSERT.

BOOL TFile::Write const TString str  )  [inline]
 

Writes string into file.

Parameters:
str [in] string to write

Definition at line 234 of file File.h.

References TString::c_str().

Here is the call graph for this function:

DWORD TFile::Write const void *  buffer,
const DWORD size
[inline]
 

Writes data to file from buffer.

Parameters:
buffer [in] buffer with data for writing (there must be enaugh allocated bytes - minimal SIZE - see next parameter)
size [in] number of bytes to write
Returns:
number of writet bytes

Definition at line 132 of file File.h.

References DBGASSERT.

Referenced by NSConfigFile::TConfigFileSection::WriteToFile().


The documentation for this class was generated from the following files:
Generated on Wed Nov 28 22:42:13 2007 for Joy4D by  doxygen 1.4.6-NO