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

VFile class that makes use of Ryan C. Gordon's fantastic physfs library. More...

#include <LDK/PhysFSFile.h>

Inheritance diagram for LDK::PhysFSFile:

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

Collaboration graph
[legend]

Public Member Functions

 PhysFSFile (PHYSFS_file *file=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 ()
PHYSFS_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

void resetPos ()

Protected Attributes

PHYSFS_file * mFile
int mUnget
int64 mPos

Detailed Description

PhysFSFiles can read from all sorts of archives and game files transparently. They are the only filetype created by VFileSystem. They are also sandboxed, so it is impossible to stomp all over a filesystem. Physfs itself cannot handle text mode, so this class adds text functionality, as well as being able to transparently read windows text files on unix systems and vice/versa.

Supports large files (> 4 gigabytes) on 32-bit architectures, but some archive formats (like ZIP) have their own limits.

Cannot write archive files, only reads them. Writing is always to a native file.

The physfs library is available from http://www.icculus.org/physfs

Read it's documentation for more info.

See also:
VFile

StdFile

VFileSystem

Definition at line 65 of file PhysFSFile.h.


Member Function Documentation

virtual void LDK::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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::PhysFSFile::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