Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

File Class Reference

Binary file. More...

#include <File.h>

Inherited by WDFFile.

Inheritance diagram for File:

Inheritance graph
[legend]
List of all members.

Public Methods

 File ()
 Default constuctor.

 File (const string &name)
 Constuct and open a file.

 ~File ()
 Destructor, closes the file.

FILE * handle ()
 Returns the FILE pointer.

unsigned int tell ()
 Return the file position. More...

int seek (long offset, int whence=SEEK_SET)
 Set the file position. More...

void open (const string &name)
 Opens a file for reading. More...

void create (const string &name)
 Creates a file for writing. More...

void close ()
 Closes the file. More...

int readAsciiInteger ()
 Reads an ascii interger. More...

void readString (string &name)
 Reads a null terminated string.

uint16 readChar ()
 Reads a single character.

uint16 readShort ()
 Reads a 2-byte integer value.

uint32 readInt ()
 Reads a 4-byte integer value.

float readFloat ()
 Reads a floating point value.

void writeString (const string &name)
 Writes a null terminated string.

void writeChar (uint16 ch)
 Writes a single character.

void writeShort (uint16 i)
 Writes a 2-byte integer value.

void writeInt (uint32 i)
 Writes a 4-byte integer value.

void writeFloat (float fl)
 Writes a floating point value.


Protected Attributes

FILE * f
 File pointer.

EndianShip endianShip
 The endianship of the file.


Detailed Description

Binary file.

Todo:
Use endianship to write both Little and Big endian files.

Wrapper for randon acces FILE.


Member Function Documentation

void File::close  
 

Closes the file.

Precondition:
none.
Postcondition:
The file has been closed.

void File::create const string &    name
 

Creates a file for writing.

Parameters:
name  Name of the file to create.
Precondition:
none.
Postcondition:
The file is created and open for writing.
Exceptions:
runtime_error  When the file could not be created.

Reimplemented in WDFFile.

void File::open const string &    name
 

Opens a file for reading.

Parameters:
name  Name of the file to open.
Precondition:
none.
Postcondition:
The file is open for reading.
Exceptions:
runtime_error  When the file could not be opened.

Reimplemented in WDFFile.

int File::readAsciiInteger  
 

Reads an ascii interger.

This method first skips all whitespace and then reads an interger value.

int File::seek long    offset,
int    whence = SEEK_SET
[inline]
 

Set the file position.

Use fseek to set the position for the file. The value of offset determines the new position, in one of three ways selected by the value of whence (defined as macros in ` stdio.h'):

  • SEEK_SET---<[offset]> is the absolute file position. offset must be positive.
  • SEEK_CUR---<[offset]> is relative to the current file position. offset can be positive or negative.
  • SEEK_END---<[offset]> is relative to the current end of file. offset can meaningfully be either positive (to increase the size of the file) or negative.
Returns:
seek returns 0 when successful. If fseek fails, the result is EOF.
See also:
fseek().

unsigned int File::tell   [inline]
 

Return the file position.

The result of tell is the current position for the file. If you record this result, you can later use it with fseek to return the file to this position.

Returns:
tell returns the file position, if possible. If it cannot do this, it returns -1L.


The documentation for this class was generated from the following files:
This documentation was generated using doxygen. If you have any comments or additions please mail me.