LDK::VFile Class Reference
[File and filesystem virtualisation]

Base class for all files. More...

#include <LDK/VFile.h>

Inheritance diagram for LDK::VFile:

Inheritance graph
[legend]
Collaboration diagram for LDK::VFile:

Collaboration graph
[legend]

Public Member Functions

 VFile ()
 Constructor.
virtual ~VFile () throw ()
 Destructor. Closes this file if it was open.
const char * name ()
virtual void openRead (const char *fileName, bool text=false)=0
virtual void openWrite (const char *fileName, bool text=false)=0
virtual void openAppend (const char *fileName, bool text=false)=0
virtual void close ()=0
virtual int64 length ()=0
virtual bool eof ()=0
virtual int64 tell ()=0
virtual int64 seek (int64 offset, int whence)=0
virtual void flush ()=0
virtual int64 read (void *buffer, uint32 objCount, uint32 objSize=1)=0
virtual int32 getc ()=0
virtual int32 ungetc (char c)=0
virtual uint32 getString (char *buffer, uint32 size)
virtual const char * gets (char *buffer, uint32 size)=0
int16 readSLE16 ()
uint16 readULE16 ()
int16 readSBE16 ()
uint16 readUBE16 ()
int32 readSLE32 ()
uint32 readULE32 ()
int32 readSBE32 ()
uint32 readUBE32 ()
int64 readSLE64 ()
uint64 readULE64 ()
int64 readSBE64 ()
uint64 readUBE64 ()
virtual int64 write (const void *buffer, uint32 objCount, uint32 objSize=1)=0
virtual int32 putc (char c)=0
virtual int32 puts (const char *str)=0
virtual int32 printf (const char *format,...)=0
virtual int32 vprintf (const char *format, va_list ap)=0
void writeSLE16 (int16 dat)
void writeULE16 (uint16 dat)
void writeSBE16 (int16 dat)
void writeUBE16 (uint16 dat)
void writeSLE32 (int32 dat)
void writeULE32 (uint32 dat)
void writeSBE32 (int32 dat)
void writeUBE32 (uint32 dat)
void writeSLE64 (int64 dat)
void writeULE64 (uint64 dat)
void writeSBE64 (int64 dat)
void writeUBE64 (uint64 dat)
bool writeable ()
 Returns true if the file is writable, false if readable.

Protected Attributes

bool mTextMode
bool mWriteable
String mName

Detailed Description

Nasty, slow, extra level of virtualisation for files. Has a strong resemblence to an OO version of a normal C FILE, and should be easy to use in place of them (eg in YACC/BISON generated parsers). All error conditions are reported via exceptions rather than return values. Does not have any equivalent to scanf :( Makes it very simple to redirect stdio from/to program windows (just derive a class and fill in the pure virtual methods).

See also:
VFileSystem

StdFile

PhysFSFile

Definition at line 71 of file VFile.h.


Member Function Documentation

const char* LDK::VFile::name (  )  [inline]

Get the name of this file.

Returns:
The name.

Definition at line 87 of file VFile.h.

virtual void LDK::VFile::openRead ( const char *  fileName,
bool  text = false 
) [pure virtual]

Open a file for reading. Genrally only called by the user for re-opening files.

Parameters:
fileName The name of the file to open.
text Open this file in text (true) or binary (false) mode.
Exceptions:
IOError if this file cannot be opened.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual void LDK::VFile::openWrite ( const char *  fileName,
bool  text = false 
) [pure virtual]

Open a file for writing. Genrally only called by the user for re-opening files.

Parameters:
fileName The name of the file to open.
text Open this file in text (true) or binary (false) mode.
Exceptions:
IOError if this file cannot be opened.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual void LDK::VFile::openAppend ( const char *  fileName,
bool  text = false 
) [pure virtual]

Open a file for appending (writing at the end). Genrally only called by the user for re-opening files.

Parameters:
fileName The name of the file to open.
text Open this file in text (true) or binary (false) mode.
Exceptions:
IOError if this file cannot be opened.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual void LDK::VFile::close (  )  [pure virtual]

Close this file.

Exceptions:
IOError If this file was not open or the underlying file handle is invalid.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual int64 LDK::VFile::length (  )  [pure virtual]

Gets the length of the file in bytes. Use with care in text mode, as may not take into account strange line terminations like on windows.

Returns:
The length of the file in bytes or -1 if it can't be detrmined for some reason.
Exceptions:
IOError If this file was not open or the underlying file handle is invalid.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual bool LDK::VFile::eof (  )  [pure virtual]

Test for end of file condition.

Returns:
true if at the end of the file, else false.
Exceptions:
IOError If the file handle is invalid.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual int64 LDK::VFile::tell (  )  [pure virtual]

Determine the current file position.

Returns:
the current position.
Exceptions:
IOError if the file handle is invalid or an error occurred.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual int64 LDK::VFile::seek ( int64  offset,
int  whence 
) [pure virtual]

Seek to a new position within this file.

Parameters:
offset The distance to seek.
whence May be SEEK_CUR (seek from current pos) or SEEK_END (seek from the end of the file). Anything else means seek from the beginning.
Exceptions:
IOError If the file handle is invalid or an error occurred.
EofError On an attempt to seek past the start or end of the file.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual void LDK::VFile::flush (  )  [pure virtual]

Flush any buffers associated with this file.

Exceptions:
IOError if the file handle is invalid or an error occurred.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual int64 LDK::VFile::read ( void *  buffer,
uint32  objCount,
uint32  objSize = 1 
) [pure virtual]

Read a number of objects from this file.

Parameters:
buffer The buffer to store read data into.
objCount The number of objects to read.
objSize The size in bytes of each object.
Returns:
The number of objects read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
ArgumentError If objCount or objSize is 0.
EofError On an attempt to read past the end of the file.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual int32 LDK::VFile::getc (  )  [pure virtual]

Read a single character (byte) from this file. Mostly used in text mode.

Returns:
The character read.
Exceptions:
IOError if the file handle is invalid or the file is not readable.
EofError On an attempt to read past the end of the file.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual int32 LDK::VFile::ungetc ( char  c  )  [pure virtual]

Push one character back into the stream. Mostly used in text mode for programming language lexers and parsers. Character is lost by seeking or flushing, and only one character may be held in the pushed back buffer at a time.

Parameters:
c The character to push back.
Returns:
The character pushed back.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file position is at the beginning of the file.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual uint32 LDK::VFile::getString ( char *  buffer,
uint32  size 
) [virtual]

Read at most 1 less than size characters until whitespace into buffer.

Parameters:
buffer The buffer to store read data into.
size The maximum number of characters to read + 1.
Returns:
The number of characters read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before the string ends or size-1 characters have been read.

virtual const char* LDK::VFile::gets ( char *  buffer,
uint32  size 
) [pure virtual]

Read at most 1 less than size characters into buffer

Parameters:
buffer The buffer to store read data into.
size The size of the buffer in characters.
Returns:
The number of characters read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before whitespace or size-1 characters.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

int16 LDK::VFile::readSLE16 (  )  [inline]

Read a signed 16-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 2 bytes have been read.

Definition at line 186 of file VFile.h.

References LDK::swapSLE16().

Here is the call graph for this function:

uint16 LDK::VFile::readULE16 (  )  [inline]

Read an unsigned 16-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 2 bytes have been read.

Definition at line 199 of file VFile.h.

References LDK::swapULE16().

Here is the call graph for this function:

int16 LDK::VFile::readSBE16 (  )  [inline]

Read a signed 16-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 2 bytes have been read.

Definition at line 212 of file VFile.h.

References LDK::swapSBE16().

Here is the call graph for this function:

uint16 LDK::VFile::readUBE16 (  )  [inline]

Read an unsigned 16-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 2 bytes have been read.

Definition at line 225 of file VFile.h.

References LDK::swapUBE16().

Here is the call graph for this function:

int32 LDK::VFile::readSLE32 (  )  [inline]

Read a signed 32-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 4 bytes have been read.

Definition at line 238 of file VFile.h.

References LDK::swapSLE32().

Here is the call graph for this function:

uint32 LDK::VFile::readULE32 (  )  [inline]

Read an unsigned 32-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 4 bytes have been read.

Definition at line 251 of file VFile.h.

References LDK::swapULE32().

Here is the call graph for this function:

int32 LDK::VFile::readSBE32 (  )  [inline]

Read a signed 32-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 4 bytes have been read.

Definition at line 264 of file VFile.h.

References LDK::swapSBE32().

Here is the call graph for this function:

uint32 LDK::VFile::readUBE32 (  )  [inline]

Read an unsigned 32-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 4 bytes have been read.

Definition at line 277 of file VFile.h.

References LDK::swapUBE32().

Here is the call graph for this function:

int64 LDK::VFile::readSLE64 (  )  [inline]

Read a signed 64-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 8 bytes have been read.

Definition at line 290 of file VFile.h.

References LDK::swapSLE64().

Here is the call graph for this function:

uint64 LDK::VFile::readULE64 (  )  [inline]

Read an unsigned 64-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 8 bytes have been read.

Definition at line 303 of file VFile.h.

References LDK::swapULE64().

Here is the call graph for this function:

int64 LDK::VFile::readSBE64 (  )  [inline]

Read a signed 64-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 8 bytes have been read.

Definition at line 316 of file VFile.h.

References LDK::swapSBE64().

Here is the call graph for this function:

uint64 LDK::VFile::readUBE64 (  )  [inline]

Read an unsigned 64-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Returns:
The integer read.
Exceptions:
IOError If the file handle is invalid or the file is not readable.
EofError If the file ends before 8 bytes have been read.

Definition at line 329 of file VFile.h.

References LDK::swapUBE64().

Here is the call graph for this function:

virtual int64 LDK::VFile::write ( const void *  buffer,
uint32  objCount,
uint32  objSize = 1 
) [pure virtual]

Write a number of objects to this file.

Parameters:
buffer The buffer that holds the data to be written.
objCount The number of objects to be written.
objSize The size of each object to be written.
Returns:
The number of objects written.
Exceptions:
IOError If the file handle is invalid, the file is not writable, or the requested number of objects written does not match the actual number of objects written.
ArgumentError If ObjCount or ObjSize are 0.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual int32 LDK::VFile::putc ( char  c  )  [pure virtual]

Write a single character to this file.

Parameters:
c The character to write.
Returns:
The character written.
Exceptions:
IOError If the file handle is invalid or this file is not writable.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual int32 LDK::VFile::puts ( const char *  str  )  [pure virtual]

Write a string to this file. Behaves like "fputs" i.e. no newline is appended.

Parameters:
str The string to write.
Returns:
The number of characters written.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual int32 LDK::VFile::printf ( const char *  format,
  ... 
) [pure virtual]

Produce output according to format, as described in your compiler/OS documentation.

Parameters:
format the format string
... The data to format
Returns:
The number of characters written.
Exceptions:
IOError If the file handle is invalid or this file is not writable.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

virtual int32 LDK::VFile::vprintf ( const char *  format,
va_list  ap 
) [pure virtual]

Produce output according to format, as described in your compiler/OS documentation.

Parameters:
format the format string
ap A variable length argument list containing the data to format.
Returns:
The number of characters written.
Exceptions:
IOError If the file handle is invalid or this file is not writable.

Implemented in LDK::PhysFSFile, and LDK::StdFile.

void LDK::VFile::writeSLE16 ( int16  dat  )  [inline]

Write a signed 16-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 377 of file VFile.h.

References LDK::swapSLE16().

Here is the call graph for this function:

void LDK::VFile::writeULE16 ( uint16  dat  )  [inline]

Write an unsigned 16-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 389 of file VFile.h.

References LDK::swapULE16().

Here is the call graph for this function:

void LDK::VFile::writeSBE16 ( int16  dat  )  [inline]

Write a signed 16-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 401 of file VFile.h.

References LDK::swapSBE16().

Here is the call graph for this function:

void LDK::VFile::writeUBE16 ( uint16  dat  )  [inline]

Write an unsigned 16-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 413 of file VFile.h.

References LDK::swapUBE16().

Here is the call graph for this function:

void LDK::VFile::writeSLE32 ( int32  dat  )  [inline]

Write a signed 32-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 425 of file VFile.h.

References LDK::swapSLE32().

Here is the call graph for this function:

void LDK::VFile::writeULE32 ( uint32  dat  )  [inline]

Write an unsigned 32-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 437 of file VFile.h.

References LDK::swapULE32().

Here is the call graph for this function:

void LDK::VFile::writeSBE32 ( int32  dat  )  [inline]

Write a signed 32-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 449 of file VFile.h.

References LDK::swapSBE32().

Here is the call graph for this function:

void LDK::VFile::writeUBE32 ( uint32  dat  )  [inline]

Write an unsigned 32-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 461 of file VFile.h.

References LDK::swapUBE32().

Here is the call graph for this function:

void LDK::VFile::writeSLE64 ( int64  dat  )  [inline]

Write a signed 64-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 473 of file VFile.h.

References LDK::swapSLE64().

Here is the call graph for this function:

void LDK::VFile::writeULE64 ( uint64  dat  )  [inline]

Write an unsigned 64-bit little endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 485 of file VFile.h.

References LDK::swapULE64().

Here is the call graph for this function:

void LDK::VFile::writeSBE64 ( int64  dat  )  [inline]

Write a signed 64-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 497 of file VFile.h.

References LDK::swapSBE64().

Here is the call graph for this function:

void LDK::VFile::writeUBE64 ( uint64  dat  )  [inline]

Write an unsigned 64-bit big endian integer, performing byte swapping if nessecary. Can only be used in binary mode.

Parameters:
dat The integer to write.
Exceptions:
IOError If the file handle is invalid, this file is not writable, or the integer cannot be completely written.

Definition at line 509 of file VFile.h.

References LDK::swapUBE64().

Here is the call graph for this function:


The documentation for this class was generated from the following file:
Generated on Fri Aug 17 18:32:27 2007 for LDK by  doxygen 1.5.1