BufReader

The class BufReader provides an interface for buffered reading from a file.

Typedefs

typedef unsigned int uint;
Code:

Public Methods

createInstance

static BufReader *createInstance(const char *pFile, uint iBufSize);

Create an instance of BufReader to read from the specified file.

pFile

Name of file to read from.

iBufSize

Size of buffer to use

createInstance

static BufReader *createInstance(FILE *fIn, uint iBufSize);

Create an instance of BufReader to read from the specified file.

fIn

File handle for input file.

iBufSize

Size of buffer to use

destructor

~BufReader();

The destructor.

getNextChar

char *getNextChar();

Gets the next character and moves the internal cursor by 1. If the end of the buffer has been reached, the next block is read from the file.

Returns the next character.

getBlock

int getBlock(char *p, uint iSize);

Reads a block of the specified size to the proveded buffer.

p

Pointer to a char array.

iSize

Number of characters to read into p

Returns 0 on success, -1 on failure.

getBlock

int getBlock(char *p, uint *piSize, const char *pLim);

Reads a block until the string pLim has been read, but at most the specified number of characters.

p

Pointer to a char array.

iSize

Maximum number of characters to read into p.

pLim

Limiting string.

Returns 0 on success, -1 on failure.

skip

char *skip(uint iSkip);

Skip ove the next iSkip characters

Returns 0 on success, -1 on error

getPos

long getPos();

Get current position in file.

Returns current position in file.

getCurPos

long getCurPos();

Get current position in buffer.

Returns current position in buffer.

loadFromCurrentPos

int loadFromCurrentPos();

Load the buffer from current file position.

Returns 0 on success, -1 on failure.

Protected Methods

constructor

BufReader();

Initializes members.

initialize

int initialize(const char *pFile, uint iBufSize);
pFile

Name of the file to be read.

iBufSize

Buffer size.

Opens the file, allocates the buffer and resets members.

initialize

int initialize(FILE *fIn, uint iBufSize, bool bCloseFile);
fIn

File handle to opened input file.

iBufSize

Buffer size.

bCloseFile

If true BufReader will close the file at the end of its life.

Allocates the buffer and resets members.