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

VFile class that encapsulates a FILE*. More...

#include <LDK/StdFile.h>

Inheritance diagram for LDK::StdFile:

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

Collaboration graph
[legend]

Public Member Functions

 StdFile (FILE *f=NULL)
virtual void openRead (const char *fileName, bool text=false)
virtual void openWrite (const char *fileName, bool text=false)
virtual void openAppend (const char *fileName, bool text=false)
virtual int64 length ()
virtual void close ()
virtual bool eof ()
virtual int64 tell ()
virtual int64 seek (int64 offset, int whence)
virtual void flush ()
FILE * handle ()
virtual int64 read (void *buffer, uint32 objCount, uint32 objSize=1)
virtual int32 getc ()
virtual int32 ungetc (char c)
virtual const char * gets (char *buffer, uint32 size)
virtual int64 write (const void *buffer, uint32 objCount, uint32 objSize=1)
virtual int32 putc (char c)
virtual int32 puts (const char *str)
virtual int32 printf (const char *format,...)
virtual int32 vprintf (const char *format, va_list ap)

Protected Member Functions

 StdFile (const StdFile &)
void operator= (const StdFile &)

Protected Attributes

FILE * mFile

Detailed Description

This class is only to allow an application to output to a native command prompt. It is also the only VFile derivative that can be used by multiple threads (I'm using locked stdio). VFileSystem defaults to using StdFiles for stdIn(), stdOut() and stdErr(). In general a user of this library should never create one. Use PhysFSFiles, as returned by VFileSystem instead.

See also:
VFile

PhysFSFile

VFileSystem

Definition at line 67 of file StdFile.h.


Member Function Documentation

virtual void LDK::StdFile::openRead ( const char *  fileName,
bool  text = false 
) [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.

Implements LDK::VFile.

virtual void LDK::StdFile::openWrite ( const char *  fileName,
bool  text = false 
) [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.

Implements LDK::VFile.

virtual void LDK::StdFile::openAppend ( const char *  fileName,
bool  text = false 
) [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.

Implements LDK::VFile.

virtual int64 LDK::StdFile::length (  )  [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.

Implements LDK::VFile.

virtual void LDK::StdFile::close (  )  [virtual]

Close this file.

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

Implements LDK::VFile.

virtual bool LDK::StdFile::eof (  )  [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.

Implements LDK::VFile.

virtual int64 LDK::StdFile::tell (  )  [virtual]

Determine the current file position.

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

Implements LDK::VFile.

virtual int64 LDK::StdFile::seek ( int64  offset,
int  whence 
) [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.

Implements LDK::VFile.

virtual void LDK::StdFile::flush (  )  [virtual]

Flush any buffers associated with this file.

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

Implements LDK::VFile.

virtual int64 LDK::StdFile::read ( void *  buffer,
uint32  objCount,
uint32  objSize = 1 
) [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.

Implements LDK::VFile.

virtual int32 LDK::StdFile::getc (  )  [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.

Implements LDK::VFile.

virtual int32 LDK::StdFile::ungetc ( char  c  )  [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.

Implements LDK::VFile.

virtual const char* LDK::StdFile::gets ( char *  buffer,
uint32  size 
) [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.

Implements LDK::VFile.

virtual int64 LDK::StdFile::write ( const void *  buffer,
uint32  objCount,
uint32  objSize = 1 
) [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.

Implements LDK::VFile.

virtual int32 LDK::StdFile::putc ( char  c  )  [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.

Implements LDK::VFile.

virtual int32 LDK::StdFile::puts ( const char *  str  )  [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.

Implements LDK::VFile.

virtual int32 LDK::StdFile::printf ( const char *  format,
  ... 
) [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.

Implements LDK::VFile.

virtual int32 LDK::StdFile::vprintf ( const char *  format,
va_list  ap 
) [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.

Implements LDK::VFile.


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