Main Page   Modules   Class Hierarchy   Compound List   Compound Members  

GAUGE3D::GIStream Class Reference

Provides many functions for reading data from a stream. More...

#include <gauge3d/files/istream.h>

Inherits GAUGE3D::GObject.

List of all members.

Public Types

enum  tSeekType { BEGINNING, CURRENT, END }
 Position to seek relative to. Used by Seek(). More...

enum  tReadMode { BINARY, ASCII }
 Read mode specifiers for ReadMode(). More...

enum  tEndianness { BIG, LITTLE }
 Endianness specifiers for Endianness(). More...

enum  tNumberBase { OCT = 8, DEC = 10, HEX = 16 }
 Number base specifiers for NumberBase(). More...


Public Methods

 GIStream (pGRawIStream streamSource)
 Create a buffered input stream. More...

 GIStream (pGRawIStream streamSource,int bufferSize)
 Create a possibly buffered input stream with a given buffer size. More...

 ~GIStream ()
 Destructor.

void Seek (int pos,tSeekType seekType)
 Seek the stream position. More...

int TellPos ()
 Get the distance in bytes between the beginning of the stream and the current position.

int Read (uint64 *target,int num=1)
 Read one or more uint64's into the target buffer. Returns the number successfully read.

int Read (uint32 *target,int num=1)
 Read one or more uint32's into the target buffer. Returns the number successfully read.

int Read (uint16 *target,int num=1)
 Read one or more uint16's into the target buffer. Returns the number successfully read.

int Read (int64 *target,int num=1)
 Read one or more int64's into the target buffer. Returns the number successfully read.

int Read (int32 *target,int num=1)
 Read one or more int32's into the target buffer. Returns the number successfully read.

int Read (int16 *target,int num=1)
 Read one or more int16's into the target buffer. Returns the number successfully read.

int Read (float64 *target,int num=1)
 Read one or more float64's into the target buffer. Returns the number successfully read.

int Read (float32 *target,int num=1)
 Read one or more float32's into the target buffer. Returns the number successfully read.

int Read (char *target,int num=1)
 Read one or more char's into the target buffer. Returns the number successfully read.

int Read (char *target[],int num=1,char *scanCode=NULL,int stringSize=-1)
 Read one or more strings into the target buffer. Returns the number successfully read. More...

int Read (GString *target,int num=1,char *scanCode=NULL)
 Read one or more strings into the target buffer. Returns the number successfully read. More...

int Read (void *target,int num)
 Read num bytes of raw data.

char Peek ()
 Check what the next byte in the stream is without extracting it. More...

char Get ()
 Get the next byte in the stream. More...

bool WaitForInput (tTime timeout=0.0)
 Wait for input to become available. More...

void ReadMode (tReadMode mode)
tReadMode ReadMode ()
 Get the current read mode.

void Endianness (tEndianness endianness)
 Set the endianness of the input data. Only applies to binary streams.

tEndianness Endianness ()
 Get the endianness of the input data.

void NumberBase (tNumberBase base)
 Set the number base of the input data. Only applies to text streams.

tNumberBase NumberBase ()
 Get the number base of the input data.

bool InputAvailable ()
 Returns true if input is currently available. More...

 operator void * ()
 Use to check if the last read operation succeeded. More...


Related Functions

(Note that these are not member functions.)

GIStream & operator>> (GIStream &is,tType &target)
 The >> operator works the same as it does for C++ istreams.


Detailed Description

Provides many functions for reading data from a stream.

GIStream does not provide the stream data itself. It wraps around a GRawIStream. GIStream provides many different ways to read the data, however, whereas GRawIStream only lets you read the data raw.

You can use a GIStream in either binary or text mode. Text mode works like regular C++ istreams, where numbers are read as ASCII, human-readable numbers, etc. In binary mode, on the other hand, the numbers are read in actual binary code, where a 32-bit number should be exactly four bytes in size in the file. Also, when in binary mode you can set whether to expect the data in big-endian or little-endian format. The data will automatically be converted to the host's endianness when read.


Member Enumeration Documentation

enum GAUGE3D::GIStream::tSeekType
 

Position to seek relative to. Used by Seek().

Enumeration values:
BEGINNING   Seek relative to the start of the stream.
CURRENT   Seek relative to the current position.
END   Seek relative to the end of the stream.

enum GAUGE3D::GIStream::tReadMode
 

Read mode specifiers for ReadMode().

Enumeration values:
BINARY   Binary mode reading.
ASCII   ASCII text mode reading.

enum GAUGE3D::GIStream::tEndianness
 

Endianness specifiers for Endianness().

Enumeration values:
BIG   Big endian. Most significant byte comes first. PPC processors are big endian.
LITTLE   Little endian. Least significant byte comes first. Intel processors are little endian.

enum GAUGE3D::GIStream::tNumberBase
 

Number base specifiers for NumberBase().

Enumeration values:
OCT   Octal (base 8).
DEC   Decimal (base 10).
HEX   Hexidecimal (base 16).


Constructor & Destructor Documentation

GAUGE3D::GIStream::GIStream ( pGRawIStream streamSource )
 

Create a buffered input stream.

Parameters:
streamSource   A pointer to a GRawIStream from which to read data.

GAUGE3D::GIStream::GIStream ( pGRawIStream streamSource,
int bufferSize )
 

Create a possibly buffered input stream with a given buffer size.

Parameters:
streamSource   A pointer to a GRawIStream from which to read data.
bufferSize   The size of the internal buffer in bytes. You can set this to zero to create an unbuffered stream, but this will usually be slower unless you are reading data in large blocks. Also, only buffered streams can be used in text (non-binary) mode.


Member Function Documentation

void GAUGE3D::GIStream::Seek ( int pos,
tSeekType seekType )
 

Seek the stream position.

Parameters:
pos   Position to seek to, in bytes.
seekType   Point in the stream that pos is relative to.

int GAUGE3D::GIStream::Read ( char * target[],
int num = 1,
char * scanCode = NULL,
int stringSize = -1 )
 

Read one or more strings into the target buffer. Returns the number successfully read.

Parameters:
target   A pointer to an array of pointers to arrays of char's to which to write the strings.
num   The number of strings to read.
scanCode   Specifies what characters to include in the string. It has the same syntax as the scanf %[] conversion specifier, without the brackets. So, "^
" would say to stop when a newline is encountered. By default, the set of all non-whitespace characters is used.
stringSize   The number of characters in each character array. If the string being read into one particular character array is longer than this, the remainder will be ignored. Each array will always be zero-terminated. A value of -1 indicates that no limit should be placed on the size of the strings read (not recommended!).

int GAUGE3D::GIStream::Read ( GString * target,
int num = 1,
char * scanCode = NULL )
 

Read one or more strings into the target buffer. Returns the number successfully read.

Parameters:
target   A pointer to an array of strings to which to write the data read.
num   The number of strings to read.
scanCode   Specifies what characters to include in the string. It has the same syntax as the scanf %[] conversion specifier, without the brackets. So, "^
" would say to stop when a newline is encountered. By default, the set of all non-whitespace characters is used.

char GAUGE3D::GIStream::Peek ( )
 

Check what the next byte in the stream is without extracting it.

Note:
This can only be done with buffered streams.

char GAUGE3D::GIStream::Get ( )
 

Get the next byte in the stream.

Note:
This can only be done with buffered streams.

bool GAUGE3D::GIStream::WaitForInput ( tTime timeout = 0.0 )
 

Wait for input to become available.

Parameters:
timout   Maximum amount of time to wait for input, or 0 to wait indefinately.
Returns:
True if input became available, false otherwise.
Note:
This function may return false immediately if it knows that input will not be available in the future. For example, if the stream is a file and it is at the end of the file.

void GAUGE3D::GIStream::ReadMode ( tReadMode mode )
 

\breif Set how to interpret the data in the stream (binary or text).

Parameters:
mode   One of tReadMode.

bool GAUGE3D::GIStream::InputAvailable ( )
 

Returns true if input is currently available.

Remarks:
You can use this to test if you are at the end of a file.

GAUGE3D::GIStream::operator void * ( )
 

Use to check if the last read operation succeeded.

Remarks:
Using the stream as a truth value returns true if the last read operation succeeded. This way, you can say something like:
  • while(myStream >> data) {...}
to keep reading in and processing data until there is no longer data available.


The documentation for this class was generated from the following file:
Generated at Tue Jan 30 17:07:34 2001 for gauge3d by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000