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

PLMPackFile Class Reference

A class to handle archive-files (files nested in big archives). More...

#include <PLMPackFile.hpp>

Inheritance diagram for PLMPackFile:

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

 PLMPackFile (const char *filename, u32 start, u32 end, u32 mode=PLMResFile::PRF_READ, const char *name=NULL)
bool Open (const char *filename, u32 start, u32 end, u32 mode=PLMResFile::PRF_READ, const char *name=NULL)
virtual void Close ()
const char * GetRealName () const
const char * GetName () const
virtual bool Seek (int offset, int reference=PLMResFile::PRF_START)
virtual void SeekStart ()
virtual void SeekEnd ()
virtual u32 GetPos () const
virtual void Flush ()
virtual u32 Read (void *dest, u32 size)
virtual u32 Write (const void *src, u32 size)
virtual u32 GetLine (char *dest, u32 size, char sep= '\n')
virtual u32 GetLine (PLMString &dest, u32 maxsize=PLM::INDEX_ERROR, char sep= '\n')
virtual void PrintInfo () const
const char * Name () const
u32 Mode () const
bool Good () const
virtual bool Eof () const
u32 State () const
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)

Detailed Description

A class to handle archive-files (files nested in big archives).

This class allows to perform all standard operations on archive-files. It performs automatic byte-ordering conversion in all integer/float methods. The file is always assumed to be in little endian order. Note that the file size is limited in write mode, so Write*() functions will fail once the end if reached.


Member Enumeration Documentation

enum PLMResFile::PRFOpenMode [inherited]
 

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 [inherited]
 

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 [inherited]
 

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

PLMPackFile::PLMPackFile const char *    filename,
u32    start,
u32    end,
u32    mode = PLMResFile::PRF_READ,
const char *    name = NULL
 

Create a new object and try to open filename in mode mode.

The filename is the name of the big standard file (the archive), and you can restrict its usage to a specific part, from start to end. See Open() to get a description of parameters. Use Good() to check the object state before any use.


Member Function Documentation

bool PLMPackFile::Open const char *    filename,
u32    start,
u32    end,
u32    mode = PLMResFile::PRF_READ,
const char *    name = NULL
 

Try to open the file named filename and close the current file if any was open.

The filename is the name of the big standard file (the archive), and you can restrict its usage to a specific part, from start to end.

Parameters:
filename  the name of the real file to open (the archive), returned by GetRealName().
start  starting offset in the archive file (0 for normal start).
end  ending offset in the archive file (the first invalid offset after the data), 0 means the end of the real file.
mode  opening mode (see PLMResFile::PRFOpenMode for details), PRF_APPEND is not allowed.
name  the name of the file inside the archive (returned by GetName()), filename is used if NULL.
Returns:
true on success, false on error (invalid file).

virtual void PLMPackFile::Close   [virtual]
 

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

Reimplemented from PLMResFile.

const char * PLMPackFile::GetRealName   [inline]
 

Get the name of the real archive file (the container).

const char* PLMPackFile::GetName  
 

Get the name of the current nested file (stored inside the archive).

virtual bool PLMPackFile::Seek int    offset,
int    reference = PLMResFile::PRF_START
[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.

Implements PLMResFile.

virtual void PLMPackFile::SeekStart   [virtual]
 

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

Implements PLMResFile.

virtual void PLMPackFile::SeekEnd   [virtual]
 

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

Implements PLMResFile.

virtual u32 PLMPackFile::GetPos   [virtual]
 

Get current cursor position (offset from the start).

Implements PLMResFile.

virtual void PLMPackFile::Flush   [virtual]
 

Update version on disk with data in the buffer.

Implements PLMResFile.

virtual u32 PLMPackFile::Read void *    dest,
u32    size
[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.

Implements PLMResFile.

virtual u32 PLMPackFile::Write const void *    src,
u32    size
[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.

Implements PLMResFile.

virtual u32 PLMPackFile::GetLine char *    dest,
u32    size,
char    sep = '\n'
[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).

Implements PLMResFile.

virtual u32 PLMPackFile::GetLine PLMString   dest,
u32    maxsize = PLM::INDEX_ERROR,
char    sep = '\n'
[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()).

Implements PLMResFile.

virtual void PLMPackFile::PrintInfo   [virtual]
 

Print some debug info.

Implements PLMResFile.

const char * PLMResFile::Name   [inline, inherited]
 

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

u32 PLMResFile::Mode   [inline, inherited]
 

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

bool PLMResFile::Good   [inline, inherited]
 

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

bool PLMResFile::Eof   [inline, virtual, inherited]
 

Check if the file cursor is at the end.

Reimplemented in PLMFile.

u32 PLMResFile::State   [inline, inherited]
 

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

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

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   [inherited]
 

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

u16 PLMResFile::Read16   [inherited]
 

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

Data is read in little endian and converted if necessary.

u32 PLMResFile::Read32   [inherited]
 

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

Data is read in little endian and converted if necessary.

u16 PLMResFile::ReadBE16   [inherited]
 

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

Data is read in big endian and converted if necessary.

u32 PLMResFile::ReadBE32   [inherited]
 

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

Data is read in big endian and converted if necessary.

float PLMResFile::ReadFl   [inherited]
 

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

Data is read in little endian and converted if necessary.

double PLMResFile::ReadDbl   [inherited]
 

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

Data is read in little endian and converted if necessary.

bool PLMResFile::Write8 u8    c [inherited]
 

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

bool PLMResFile::Write16 u16    s [inherited]
 

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 [inherited]
 

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 [inherited]
 

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 [inherited]
 

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 [inherited]
 

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 [inherited]
 

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.


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

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