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

PLMFile Class Reference

File object. More...

#include <PLMFile.hpp>

Inheritance diagram for PLMFile:

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

 PLMFile (const char *filename=0, u32 mode=PLMResFile::PRF_READ)
bool Open (const char *filename, u32 mode=PLMResFile::PRF_READ)
virtual void Close ()
virtual bool Eof () 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
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

File object.

This class allows to perform all standard operations on a file. It performs automatic byte-ordering conversion in all integer/float methods. The file is always assumed to be in little endian order.


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

PLMFile::PLMFile const char *    filename = 0,
u32    mode = PLMResFile::PRF_READ
 

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

See PLMResFile::PRFOpenMode for details on opening modes. Use Good() to check the state before any use.


Member Function Documentation

bool PLMFile::Open const char *    filename,
u32    mode = PLMResFile::PRF_READ
 

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

See PLMResFile::PRFOpenMode for details on opening modes.

Returns:
true on success, false on error.

virtual void PLMFile::Close   [virtual]
 

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

Reimplemented from PLMResFile.

virtual bool PLMFile::Eof   [virtual]
 

Check if the file cursor is at the end.

Reimplemented from PLMResFile.

virtual bool PLMFile::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 PLMFile::SeekStart   [virtual]
 

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

Implements PLMResFile.

virtual void PLMFile::SeekEnd   [virtual]
 

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

Implements PLMResFile.

virtual u32 PLMFile::GetPos   [virtual]
 

Get current cursor position (offset from the start).

Implements PLMResFile.

virtual void PLMFile::Flush   [virtual]
 

Update version on disk with data in the buffer.

Implements PLMResFile.

virtual u32 PLMFile::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 PLMFile::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 PLMFile::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 PLMFile::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 PLMFile::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.

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:
  • PLMFile.hpp

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