Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Examples  

TPT::Buffer Class Reference

#include <buffer.h>

List of all members.

Public Methods

 Buffer (const char *filename)
 Instantiate on filename. More...

 Buffer (std::istream *is)
 Instantiate on open input fstream. More...

 Buffer (const char *buffer, unsigned long size)
 Instantiate on existing buffer. More...

 Buffer (const Buffer &buf, unsigned long start, unsigned long end)
 Instantiate on subsection of existing buffer. More...

 ~Buffer ()
 Cleanup. More...

char getnextchar ()
 Get next character from buffer. More...

bool unget ()
 Back up in the buffer. More...

void reset ()
 Reset pointers to beginning of buffer. More...

bool seek (unsigned long index)
 Seek to index in buffer. More...

unsigned long offset () const
 Get current offset into buffer. More...

 operator bool () const
 True when not at end of buffer. More...

const char operator[] (unsigned long index)
 Index access. More...

unsigned long size () const
 Current size. More...


Detailed Description

The TPT::Buffer class provides a generic way to buffer input from a file, file stream, or existing buffer one character at a time.
Examples:

bufferbuffer.cxx, bufferfile.cxx, and bufferfstream.cxx.


Constructor & Destructor Documentation

TPT::Buffer::Buffer const char *    filename [explicit]
 

Instantiate on filename.

Construct a read Buffer for the specified file.

Parameters:
filename  name of file to buffer
Returns:
nothing
Author:
Isaac W. Foraker

TPT::Buffer::Buffer std::istream *    is [explicit]
 

Instantiate on open input fstream.

Construct a read Buffer for an open fstream. The input stream will not be closed when Buffer is destructed.

Parameters:
filein  input fstream
Returns:
nothing
Author:
Isaac W. Foraker

TPT::Buffer::Buffer const char *    buffer,
unsigned long    size
[explicit]
 

Instantiate on existing buffer.

Construct a read Buffer for an existing buffer.

Returns:
nothing
Author:
Isaac W. Foraker

TPT::Buffer::Buffer const Buffer &    buf,
unsigned long    start,
unsigned long    end
[explicit]
 

Instantiate on subsection of existing buffer.

Construct a read Buffer on a subspace of an existing Buffer.

Returns:
nothing
Author:
Isaac W. Foraker

TPT::Buffer::~Buffer  
 

Cleanup.

Free buffer and fstream if necessary


Member Function Documentation

char TPT::Buffer::getnextchar  
 

Get next character from buffer.

Get the next available character from the buffer. Use operator bool() to determine if more data is available. Reading past the end of the buffer results in undefined behavior.

Parameters:
none 
Returns:
next available character; undefined if no more characters available
Author:
Isaac W. Foraker

unsigned long TPT::Buffer::offset   const
 

Get current offset into buffer.

Get the offset of the next character in the buffer to be read. Use operator bool() to determine if there is data in the buffer.

Parameters:
none 
Returns:
current offset into buffer of next character to be read.
Author:
Isaac W. Foraker

TPT::Buffer::operator bool   const
 

True when not at end of buffer.

Perform a boolean check for availability of data in the buffer. Usage can look like:

TPT::Buffer readbuf("input.txt");
if (readbuf) {
.
.
.
}

Parameters:
none 
Returns:
false if no data is available; true if data is available
Author:
Isaac W. Foraker

const char TPT::Buffer::operator[] unsigned long    index
 

Index access.

Read from a specific index in the buffer, without losing the current position information, reading the input file or stream if necessary.

Parameters:
index  Offset into buffer from beginning.
Returns:
character at index; undefined if invalid index
Author:
Isaac W. Foraker

void TPT::Buffer::reset  
 

Reset pointers to beginning of buffer.

Reset the buffer index to the beginning of the input buffer.

Parameters:
none 
Returns:
nothing
Author:
Isaac W. Foraker

bool TPT::Buffer::seek unsigned long    index
 

Seek to index in buffer.

Seek to a index point in the buffer. The seek will force reading of the file or stream if the index has not yet been buffered. If the index is past the end of the buffer, the attempt will fail and the internal index will not be reset.

Parameters:
index  Offset into buffer from beginning.
Returns:
false on success; true if past end of buffer
Author:
Isaac W. Foraker

unsigned long TPT::Buffer::size   const
 

Current size.

Get the size of the current buffer. If this is a file or stream buffer, the size may be smaller than the current file or stream if the buffer has not been fully filled.

Parameters:
none 
Returns:
current size of buffer
Author:
Isaac W. Foraker

bool TPT::Buffer::unget  
 

Back up in the buffer.

Unget a single character back into the buffer.

Parameters:
c  character to put back.
Returns:
false on success; true if unget buffer full
Author:
Isaac W. Foraker


The documentation for this class was generated from the following files:
Generated on Wed Sep 4 22:06:43 2002 for LibTPT by doxygen1.2.13 written by Dimitri van Heesch, © 1997-2001