Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   Namespace Members   Compound Members  

PLMResFile Class Reference

Abstract file class. More...

#include <PLMResFile.hpp>

Inheritance diagram for PLMResFile:

Inheritance graph
[legend]
List of all members.

Public Types

enum  PRFOpenMode {
  PRF_ERROR = 0, PRF_READ = 1, PRF_WRITE = 2, PRF_RW = 3,
  PRF_TRUNC = 4, PRF_CREATE = 8, PRF_APPEND = 16
}
enum  PRFState {
  ERR_CLOSED = 0x10, ERR_MODE = 0x20, ERR_OPEN = 0x30, ERR_READ = 0x07,
  ERR_WRITE = 0x05, ERR_SEEK = 0x03, ERR_OK = 0x01
}
enum  PRFRef { PRF_START = SEEK_SET, PRF_CUR = SEEK_CUR, PRF_END = SEEK_END }

Public Methods

virtual void Close ()
const char * Name () const
u32 Mode () const
bool Good () const
virtual bool Eof () const
u32 State () const
virtual bool Seek (int offset, int reference=PRF_START)=0
virtual void SeekStart ()=0
virtual void SeekEnd ()=0
virtual u32 GetPos () const=0
virtual void Flush ()=0
virtual u32 GetLine (char *dest, u32 size, char sep= '\n')=0
virtual u32 GetLine (PLMString &dest, u32 maxsize=PLM::INDEX_ERROR, char sep= '\n')=0
virtual u32 Read (void *dest, u32 size)=0
virtual u32 Write (const void *src, u32 size)=0
virtual u32 WriteStr (const PLMString &src, u32 size=PLM::INDEX_ERROR)
u8 Read8 ()
u16 Read16 ()
u32 Read32 ()
u16 ReadBE16 ()
u32 ReadBE32 ()
float ReadFl ()
double ReadDbl ()
bool Write8 (u8 c)
bool Write16 (u16 s)
bool Write32 (u32 i)
bool WriteBE16 (u16 s)
bool WriteBE32 (u32 i)
bool WriteFl (float f)
bool WriteDbl (double d)
virtual void PrintInfo () const=0

Protected Methods

 PLMResFile ()

Detailed Description

Abstract file class.

This class allows to perform all standard operations on files. It can work on standard files, on files placed in archives, and on memory files as well. Automatic byte-ordering conversions are made by functions that read and write integers and floats. The file is always supposed to store data in little endian order.


Member Enumeration Documentation

enum PLMResFile::PRFOpenMode
 

File opening modes, you can add TRUNC and others with '|' (bitwise-or).

Enumeration values:
PRF_ERROR  error (can be set to this one after a bad operation)
PRF_READ  read only mode (Write*() not allowed)
PRF_WRITE  write only mode (Read*() not allowed), file is truncated if it already exists
PRF_RW  read + write mode
PRF_TRUNC  (write modes only), remove content if the file already exists
PRF_CREATE  (write modes only), force creation = return false if the file already exists
PRF_APPEND  (write modes only), file is not truncated and cursor is moved at the end of the file

enum PLMResFile::PRFState
 

Object internal state.

Enumeration values:
ERR_CLOSED  (closed) the file is closed or not yet opened
ERR_MODE  (closed) wrong opening mode given to the constructor
ERR_OPEN  (closed) error while opening a file
ERR_READ  (open) a read error has occured
ERR_WRITE  (open) a write error has occured
ERR_SEEK  (open) error in seeking methods
ERR_OK  (open) all is ok, the file is open

enum PLMResFile::PRFRef
 

References for Seek().

Enumeration values:
PRF_START  offset is counted from the beginning of the file
PRF_CUR  offset is added to current position
PRF_END  offset is counted from the end of the file (should be negative or NULL)


Constructor & Destructor Documentation

PLMResFile::PLMResFile   [inline, protected]
 

Create a new resource file.


Member Function Documentation

void PLMResFile::Close   [inline, virtual]
 

Close the file, set state to ERR_CLOSED. No method will work until Open() is called.

Reimplemented in PLMFile, PLMMemFile, and PLMPackFile.

const char * PLMResFile::Name   [inline]
 

Get the current file name (the name used to open it).

u32 PLMResFile::Mode   [inline]
 

Returns current opening mode (see PLMResFile::PRFOpenMode enum).

bool PLMResFile::Good   [inline]
 

Returns current state of the file. False means you can not perform any operation.

bool PLMResFile::Eof   [inline, virtual]
 

Check if the file cursor is at the end.

Reimplemented in PLMFile.

u32 PLMResFile::State   [inline]
 

Get the current state of the object. See PLMResFile::PRFState enum.

virtual bool PLMResFile::Seek int    offset,
int    reference = PRF_START
[pure virtual]
 

Move the cursor to a specific position inside the file.

Parameters:
offset  number of bytes to move (can be < 0 to go back)
reference  reference to compute the final position, use PLMResFile::PRFRef enum.
Returns:
true on success, false on error and the position is not modified.

Implemented in PLMFile, PLMMemFile, and PLMPackFile.

virtual void PLMResFile::SeekStart   [pure virtual]
 

Move the cursor to the beginning of the file (starting offset).

Implemented in PLMFile, PLMMemFile, and PLMPackFile.

virtual void PLMResFile::SeekEnd   [pure virtual]
 

Move the cursor to the end of the file (ending offset).

Implemented in PLMFile, PLMMemFile, and PLMPackFile.

virtual u32 PLMResFile::GetPos   [pure virtual]
 

Get current cursor position (offset from the start).

Implemented in PLMFile, PLMMemFile, and PLMPackFile.

virtual void PLMResFile::Flush   [pure virtual]
 

Update version on disk with data in the buffer.

Implemented in PLMFile, PLMMemFile, and PLMPackFile.

virtual u32 PLMResFile::GetLine char *    dest,
u32    size,
char    sep = '\n'
[pure virtual]
 

Read characters from a text file until sep is found or size-1 characters are read, and write them to dest.

Note that sep is replaced by a final '\0' in dest.

Returns:
  • 0 = error, can not read source,
  • 1 = empty line (sep is the first character encountered),
  • n = number of characters written (including \0).

Implemented in PLMFile, PLMMemFile, and PLMPackFile.

virtual u32 PLMResFile::GetLine PLMString   dest,
u32    maxsize = PLM::INDEX_ERROR,
char    sep = '\n'
[pure virtual]
 

Read characters from a text file until sep is found or maxsize characters are read, and write them to dest (which is cleared).

The file cursor then points just after 'sep'. If maxsize = PLM::INDEX_ERROR, read until sep is found (or memory is full).

Returns:
  • 0 = error, can not read source,
  • 1 = empty line (sep is the first character encountered),
  • n = number of characters read (may be different from written = dest.Length()).

Implemented in PLMFile, PLMMemFile, and PLMPackFile.

virtual u32 PLMResFile::Read void *    dest,
u32    size
[pure virtual]
 

Read data from the file.

Try to read size bytes and write them to dest.

Returns:
the number of bytes read, 0 means error or end of file.

Implemented in PLMFile, PLMMemFile, and PLMPackFile.

virtual u32 PLMResFile::Write const void *    src,
u32    size
[pure virtual]
 

Write data to the file.

Try to write size bytes read from src.

Returns:
the number of bytes written, 0 means error or end of file.

Implemented in PLMFile, PLMMemFile, and PLMPackFile.

virtual u32 PLMResFile::WriteStr const PLMString   src,
u32    size = PLM::INDEX_ERROR
[virtual]
 

Write a string to the file.

Try to write size characters read from src. Use size = PLM::INDEX_ERROR to write the whole string.

Returns:
the number of bytes written, 0 means error or end of file.

u8 PLMResFile::Read8  
 

Read one byte and move the cursor (+1 byte).

u16 PLMResFile::Read16  
 

Read one small integer and move the cursor (+2 bytes).

Data is read in little endian and converted if necessary.

u32 PLMResFile::Read32  
 

Read one integer and move the cursor (+4 bytes).

Data is read in little endian and converted if necessary.

u16 PLMResFile::ReadBE16  
 

Read one small integer and move the cursor (+2 bytes).

Data is read in big endian and converted if necessary.

u32 PLMResFile::ReadBE32  
 

Read one integer and move the cursor (+4 bytes).

Data is read in big endian and converted if necessary.

float PLMResFile::ReadFl  
 

Read one float and move the cursor (+4 bytes).

Data is read in little endian and converted if necessary.

double PLMResFile::ReadDbl  
 

Read one double and move the cursor (+8 bytes).

Data is read in little endian and converted if necessary.

bool PLMResFile::Write8 u8    c
 

Write one byte and move the cursor (+1 byte), returns false on error (bad state).

bool PLMResFile::Write16 u16    s
 

Write one small integer and move the cursor (+2 bytes), returns false on error (bad state).

Data is written in little endian and converted if necessary.

bool PLMResFile::Write32 u32    i
 

Write one integer and move the cursor (+4 bytes), returns false on error (bad state).

Data is written in little endian and converted if necessary.

bool PLMResFile::WriteBE16 u16    s
 

Write one small integer and move the cursor (+2 bytes), returns false on error (bad state).

Data is written in big endian and converted if necessary.

bool PLMResFile::WriteBE32 u32    i
 

Write one integer and move the cursor (+4 bytes), returns false on error (bad state).

Data is written in big endian and converted if necessary.

bool PLMResFile::WriteFl float    f
 

Write one float and move the cursor (+4 bytes), returns false on error (bad state).

Data is written in little endian and converted if necessary.

bool PLMResFile::WriteDbl double    d
 

Write one double and move the cursor (+8 bytes), returns false on error (bad state).

Data is written in little endian and converted if necessary.

virtual void PLMResFile::PrintInfo   [pure virtual]
 

Print some debug info.

Implemented in PLMFile, PLMMemFile, and PLMPackFile.


The documentation for this class was generated from the following file:
  • PLMResFile.hpp

Generated by Doxygen 1.2.18 on Tue Oct 26 12:07:44 2004.