Main Page | Compound List | Compound Members | Examples

TPT::Buffer Class Reference

List of all members.

Public Member Functions

 Buffer (const char *filename)
 Instantiate on filename.

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

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

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

 ~Buffer ()
 Cleanup.

char getnextchar ()
 Get next character from buffer.

bool unget ()
 Back up in the buffer.

void reset ()
 Reset pointers to beginning of buffer.

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

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

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

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

unsigned long size () const
 Current size.

void setname (const char *name)
 Set buffer name.

const char * getname ()
 Get buffer name.


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

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:
is input fstream
Returns:
nothing

TPT::Buffer::Buffer const char *  buf,
unsigned long  bufsize
[explicit]
 

Instantiate on existing buffer.

Construct a read Buffer for an existing buffer.

Returns:
nothing

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

TPT::Buffer::~Buffer  ) 
 

Cleanup.

Free buffer and fstream if necessary


Member Function Documentation

const char * TPT::Buffer::getname  ) 
 

Get buffer name.

Get the current buffer name.

Returns:
current buffer name.

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.

Returns:
next available character;

undefined if no more characters available

Examples:
bufferbuffer.cxx, bufferfile.cxx, and bufferfstream.cxx.

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.

Returns:
current offset into buffer of next character to be read.

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) {
.
.
.
}

Returns:
false if no data is available;

true if data is available

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

void TPT::Buffer::reset  ) 
 

Reset pointers to beginning of buffer.

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

Returns:
nothing

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

void TPT::Buffer::setname const char *  name  ) 
 

Set buffer name.

Set the buffer name. By default, file buffers will have a name of the filename if the buffer is a file buffer, or 'stream', 'memory', or 'buffer' depending on the constructor.

Parameters:
name new buffer name
Returns:
nothing

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.

Returns:
current size of buffer

bool TPT::Buffer::unget  ) 
 

Back up in the buffer.

Unget a single character back into the buffer.

Returns:
false on success;

true if unget buffer full


The documentation for this class was generated from the following files:
Generated on Sat Feb 7 16:06:07 2004 for LibTPT by doxygen 1.3.3