File Class Reference
[Kernel Module]

#include <file.h>

List of all members.


Detailed Description

Wrapper class for accessing file system files. Provides functions for reading and writing files.

Public Types

enum  SeekType { ST_CURRENT, ST_START, ST_END }
 Start point for seeking in file. More...

Public Member Functions

virtual ~File ()
bool Open (const string &fileName, const char *accessMode)
void Close ()
bool Eof () const
long GetSize () const
bool IsOpened () const
bool IsBinary () const
int GetLine () const
const string & GetFilePath () const
long Tell () const
bool Seek (long offset, SeekType origin)
bool Flush ()
size_t Write (const void *buffer, size_t size)
size_t Read (void *buffer, size_t size)
byte_tReadAll ()
char * ReadAllToString ()
bool WriteLine (const string &line)
bool PrintF (const char *format,...)
bool ReadLine (string &line)
size_t WriteInt (int val)
size_t WriteShort (short val)
size_t WriteLong (long val)
size_t WriteChar (char val)
size_t WriteUInt (unsigned int val)
size_t WriteUShort (unsigned short val)
size_t WriteULong (unsigned long val)
size_t WriteUChar (unsigned char val)
size_t WriteFloat (float val)
size_t WriteDouble (double val)
int ReadInt ()
short ReadShort ()
long ReadLong ()
char ReadChar ()
unsigned int ReadUInt ()
unsigned short ReadUShort ()
unsigned long ReadULong ()
unsigned char ReadUChar ()
float ReadFloat ()
double ReadDouble ()

Static Public Member Functions

static size_t OnRead (void *ptr, size_t size, size_t nmemb, void *source)
static size_t OnWrite (const void *ptr, size_t size, size_t count, void *source)
static int OnSeek (void *source, long offset, int whence)
static int OnSeek64 (void *source, __int64 offset, int whence)
static long OnTell (void *source)
static int OnClose (void *source)
static int OnFlush (void *source)

Protected Member Functions

 File ()
 File (FILE *file, const char *file_path, bool binary)

Protected Attributes

ushort_t act_line
 Actual line number.
bool opened
 Whether file is opened.
bool binary
 Whether file was opend as binary;.
FILE * file
 Ansi C file pointer.
string file_path
 Path to the file.

Friends

class FileServer

Member Enumeration Documentation

enum File::SeekType

Start point for seeking in file.

Enumerator:
ST_CURRENT 
ST_START 
ST_END 


Constructor & Destructor Documentation

File::~File (  )  [virtual]

Destructor.

File::File (  )  [protected]

Constructor. It is private because only FileServer may create objects.

File::File ( FILE *  file,
const char *  file_path,
bool  binary 
) [protected]

Given file stream will be set directly. Used in FileServer to wraps standart streams.

Parameters:
file Opened file stream.
file_path Name and full path of the stream.
binary Whether the stream is binary.
Returns:
True if success.


Member Function Documentation

bool File::Open ( const string &  file_path,
const char *  access_mode 
)

Opens the specified file.

Parameters:
file_path The full name of the file to open.
access_mode The access mode ("(r|w|a)[+]").
Returns:
True if success.

void File::Close (  ) 

Closes the file.

bool File::Eof (  )  const

Is the file at the end.

long File::GetSize (  )  const

Returns size of file in bytes.

Returns:
Byte-size of file.

bool File::IsOpened (  )  const [inline]

Determines whether the file is opened.

bool File::IsBinary (  )  const [inline]

Determines whether the file was opened with binary flag.

int File::GetLine (  )  const [inline]

Gets current line number (incremented by WriteLine() and ReadLine())

Returns:
The current line number.

const string & File::GetFilePath (  )  const [inline]

Gets full file name and path.

Returns:
File path.

long File::Tell (  )  const

Gets current position of file pointer.

Returns:
Position of pointer.

bool File::Seek ( long  offset,
SeekType  origin 
)

Sets the file pointer to given absolute or relative position.

Parameters:
offset The offset.
origin Position from which to count.
Returns:
Success.

bool File::Flush (  )  [inline]

Flushes a stream.

size_t File::Write ( const void *  buffer,
size_t  size 
)

Writes a number of bytes to the file.

Parameters:
buffer Buffer with data.
size Number of bytes to write.
Returns:
Number of bytes written.

size_t File::Read ( void *  buffer,
size_t  size 
)

Reads a number of bytes from the file.

Parameters:
buffer Buffer for data.
size Number of bytes to read.
Returns:
Number of bytes read.

byte_t * File::ReadAll (  ) 

Reads whole file into memory buffer.

This function does not depend on current position in the file. This position will not be changed. Buffer is creted using NEW operator so user has to delete it hisself.

Returns:
Buffer with file data. If error occures or file is empty, NULL is returned.

char * File::ReadAllToString (  ) 

bool File::WriteLine ( const string &  line  ) 

Writes a string to the file.

Parameters:
line The string to write.
Returns:
Success.

bool File::PrintF ( const char *  format,
  ... 
)

Writes a formatted string to the file.

Parameters:
format Standart format string like in printf.
Returns:
Success.

bool File::ReadLine ( string &  line  ) 

Reads one line from the file up to the first newline character or up to the end of the buffer.

Parameters:
line Buffer for line.
Returns:
False if eof is reached.

size_t File::WriteInt ( int  val  )  [inline]

Writes a 32bit integer to the file.

Parameters:
val A 32 bit int value.
Returns:
Number of bytes written.

size_t File::WriteShort ( short  val  )  [inline]

Writes a 16bit integer to the file.

Parameters:
val A 16 bit int value.
Returns:
Number of bytes written.

size_t File::WriteLong ( long  val  )  [inline]

Writes a 64bit integer to the file.

Parameters:
val A 64 bit int value.
Returns:
Number of bytes written.

size_t File::WriteChar ( char  val  )  [inline]

Writes a 8bit integer to the file.

Parameters:
val A 8 bit int value.
Returns:
Number of bytes written.

size_t File::WriteUInt ( unsigned int  val  )  [inline]

Writes a unsigned 32bit integer to the file.

Parameters:
val A 32 unsigned bit int value.
Returns:
Number of bytes written.

size_t File::WriteUShort ( unsigned short  val  )  [inline]

Writes a unsigned 16bit integer to the file.

Parameters:
val A unsigned 16 bit int value.
Returns:
Number of bytes written.

size_t File::WriteULong ( unsigned long  val  )  [inline]

Writes a unsigned 64bit integer to the file.

Parameters:
val A unsigned 64 bit int value.
Returns:
Number of bytes written.

size_t File::WriteUChar ( unsigned char  val  )  [inline]

Writes a unsigned 8bit integer to the file.

Parameters:
val A unsigned 8 bit int value.
Returns:
Number of bytes written.

size_t File::WriteFloat ( float  val  )  [inline]

Writes a float to the file.

Parameters:
val A 32 bit float value.
Returns:
Number of bytes written.

size_t File::WriteDouble ( double  val  )  [inline]

Writes a double to the file.

Parameters:
val A 64 bit double value.
Returns:
Number of bytes written.

int File::ReadInt (  )  [inline]

Reads a 32 bit integer from the file.

Returns:
The value.

short File::ReadShort (  )  [inline]

Reads a 16 bit integer from the file.

Returns:
The value.

long File::ReadLong (  )  [inline]

Reads a 64 bit integer from the file.

Returns:
The value.

char File::ReadChar (  )  [inline]

Reads a 8 bit integer from the file.

Returns:
The value.

unsigned int File::ReadUInt (  )  [inline]

Reads a unsigned 32 bit integer from the file.

Returns:
The value.

unsigned short File::ReadUShort (  )  [inline]

Reads a unsigned 16 bit integer from the file.

Returns:
The value.

unsigned long File::ReadULong (  )  [inline]

Reads a unsigned 64 bit integer from the file.

Returns:
The value.

unsigned char File::ReadUChar (  )  [inline]

Reads a 8 unsigned bit integer from the file.

Returns:
The value.

float File::ReadFloat (  )  [inline]

Reads a float from the file.

Returns:
The value.

double File::ReadDouble (  )  [inline]

Reads a double from the file.

Returns:
The value.

size_t File::OnRead ( void *  ptr,
size_t  size,
size_t  count,
void *  source 
) [inline, static]

Wraps our file access into callback function used in external libraries.

Parameters:
ptr Pointer to memory buffer.
size Size of block.
count Number of blocks we want to read.
source Pointer to File object.
Returns:
Size of read data.

size_t File::OnWrite ( const void *  ptr,
size_t  size,
size_t  count,
void *  source 
) [inline, static]

Wraps our file access into callback function used in external libraries.

Parameters:
ptr Pointer to memory buffer.
size Size of block.
count Number of blocks we want to write.
source Pointer to File object.
Returns:
Size of written data.

int File::OnSeek ( void *  source,
long  offset,
int  whence 
) [inline, static]

Wraps our file access into callback function used in external libraries.

Parameters:
source Pointer to File object.
offset Offset for seeking.
whence Start point for seeking.
Returns:
0 if successful.

int File::OnSeek64 ( void *  source,
__int64  offset,
int  whence 
) [inline, static]

Wraps our file access into callback function used in external libraries.

Parameters:
source Pointer to File object.
offset Offset for seeking.
whence Start point for seeking.
Returns:
0 if successful.

long File::OnTell ( void *  source  )  [inline, static]

Wraps our file access into callback function used in external libraries.

Parameters:
source Pointer to File object.
Returns:
Actual position in the file.

int File::OnClose ( void *  source  )  [inline, static]

Wraps our file access into callback function used in external libraries.

Parameters:
source Pointer to File object.
Returns:
0 if successful.

int File::OnFlush ( void *  source  )  [inline, static]

Wraps our file access into callback function used in external libraries.

Parameters:
source Pointer to File object.
Returns:
0 if successful.


Friends And Related Function Documentation

friend class FileServer [friend]


Member Data Documentation

ushort_t File::act_line [protected]

Actual line number.

bool File::opened [protected]

Whether file is opened.

bool File::binary [protected]

Whether file was opend as binary;.

FILE* File::file [protected]

Ansi C file pointer.

string File::file_path [protected]

Path to the file.


The documentation for this class was generated from the following files:
Generated on Sat Oct 20 14:47:31 2007 for Dark Oberon by  doxygen 1.5.3