class MStream

Class which streams data into memory

Inheritance:


Public Methods

char* end(void)
Function which returns the current internal pointer value
MStream(char *start, int size)
Constructor which requires the maximum memory available
MStream(char *start, char *end)
Constructor which requires the start and end memory locations
MStream& operator<<(const char *s)
Operator to write a constant null terminated string into the stream
MStream& operator<<(double d)
Operator to write a double into the stream
MStream& operator<<(int i)
Operator to write an integer into the stream
MStream& operator<<(float f)
Operator to write a float into the stream
MStream& operator>>(float &f)
Operator to read a float from a memory stream
MStream& operator>>(char *s)
Operator to read an integer from a memory stream
MStream& operator>>(int &i)
Operator to read an integer from a memory stream
MStream& operator>>(double &d)
Operator to read a double from a memory stream
char* start(void)
Function which returns the first memory location of the stream

Private Fields

char* eom
Pointer to the end of the stream buffer
char* ptr
Pointer to the current position within the buffer
char* som
Pointer to the start of the stream buffer
bool swapflag
Flag which when true ensures all data is byte swapped

Private Methods

bool byteOrder(void)
Checks the byte order of the host machine
float swap(float f)
Swaps the byte order of a float
int swap(int i)
Swaps the byte order of an integer

Documentation

Class which streams data into memory.The class will only take int, float or string (char * only) variables and streams them into memory. Care is taken to ensure that all data is aligned on 4 byte boundaries since otherwise Alpha CPUs will produce unalign exception errors. Padding of strings is taken care of by the class so that the user need not worry about such things. At initialization time the class will also perform a simple check on the byte order of the host machine. If this differs from the Alpha architecture standard then all integers and floats will be byteswapped to the Alpha standard before being stored in the memory buffer. The class is written without inheritance from the STL because it must be capable of running online on the Alpha VME hardware. This also precludes use of dynamic memory allocation except.
MStream(char *start, int size)
Constructor which requires the maximum memory available. This constructs the stream in cases when the maximum available memory is known. The limits are checked everytime something is read from or written to the stream.
Parameters:
start - memory location where the stream will start
size - available memory size in bytes

MStream(char *start, char *end)
Constructor which requires the start and end memory locations. This constructs the stream such that all the data will lie between the two locations given. Each time data is written to or from the stream these limits are checked.
Parameters:
start - memory location where the stream will start
end - highest memory location the stream can use

char* start(void)
Function which returns the first memory location of the stream. The function is a simple inlined call returning the value of the `som' internal pointer.
Returns:
pointer to the start of the stream's memory block

char* end(void)
Function which returns the current internal pointer value. The function is a simple inlined call returning the value of the `ptr' internal pointer. When writing data to the stream this defines the end of the currently valid data and so can be used to find out which region of memory needs to be written to a file.
Returns:
pointer to one byte beyond the end of the valid data

MStream& operator<<(int i)
Operator to write an integer into the stream. If the host's byte order differs from that of an Alpha processor the bytes will be swapped before writing. If the stream size is exceeded then no data will be written.
Returns:
reference to the memory stream being used
Parameters:
i - integer value to write into the stream

MStream& operator<<(float f)
Operator to write a float into the stream. If the host's byte order differs from that of an Alpha processor the bytes will be swapped before writing. If the stream size is exceeded then no data will be written.
Returns:
reference to the memory stream being used
Parameters:
f - floating point value to write into the stream

MStream& operator<<(double d)
Operator to write a double into the stream. The routine casts the double as a float and then writes out the single precision value this will result in a loss of precision but does reduce the variable toa 4 byte quantity.
Returns:
reference to the memory stream being used
Parameters:
d - variable to write into the stream as a float

MStream& operator<<(const char *s)
Operator to write a constant null terminated string into the stream. This operator will also pad the string out to the next 4-byte boundary. This is to ensure correct alignment for Alpha processors.
Returns:
reference to the memory stream being used
Parameters:
s - pointer to the character string to write into the stream

MStream& operator>>(int &i)
Operator to read an integer from a memory stream. This routine reads the data at the current pointer to the memory stream and returns it in the integer given. The pointer is also advanced 4 bytes.
Returns:
reference to the memory stream being used
Parameters:
i - reference to integer variable to be read from the stream

MStream& operator>>(float &f)
Operator to read a float from a memory stream. The routine reads data pointed to by the internal stream pointer and returns this as the given floating point variable. The pointer is advanced by 4 bytes.
Returns:
reference to the memory stream being used
Parameters:
f - reference to float variable to be read from the stream

MStream& operator>>(double &d)
Operator to read a double from a memory stream. The routine reads data pointed to by the internal stream pointer as a 4 byte floating point value. this 4 byte value is then cast into the given double precision variable and returned. The internal pointer is advanced by 4 bytes by this function.
Returns:
reference to the memory stream being used
Parameters:
d - reference to double variable to be read from the stream

MStream& operator>>(char *s)
Operator to read an integer from a memory stream. The routine reads data pointed to by the internal stream pointer and puts it into the given string array. The pointer is then advanced by the length of the string rounded to the next largest multiple of four. (This is to ensure correct int and float byte alignment for alpha processors.)
Returns:
reference to the memory stream being used
Parameters:
s - pointer to character string to be read from the stream

bool byteOrder(void)
Checks the byte order of the host machine. This is achieved by defining an integer and then looking at the individual bytes stored in memory. If the byte order is different from the byte order of an Alpha CPU then true is returned. On an Alpha the integer value 0x01020304 is stored as 4,3,2,1 in adjacent memory locations. If this is not the case for the host machine then the bytes will be swapped.
Returns:
true if non-Alpha byte order, otherwise false

int swap(int i)
Swaps the byte order of an integer. This routine is called if the host machine does not use the Alpha processor byte order. It ensures that the data is written such that Alpha processors will read them correctly.
Returns:
byte swapped integer
Parameters:
i - the integer to be byte swapped

float swap(float f)
Swaps the byte order of a float. This routine is called if the host machine does not use the Alpha processor byte order. It ensures that the data is written such that Alpha processors will read them correctly.
Returns:
byte swapped float
Parameters:
f - the float to be byte swapped

char* som
Pointer to the start of the stream buffer

char* eom
Pointer to the end of the stream buffer

char* ptr
Pointer to the current position within the buffer

bool swapflag
Flag which when true ensures all data is byte swapped


Direct child classes:
TCCparser
Author:
Roger Moore (moore@pa.msu.edu)

alphabetic index hierarchy of classes


This page has been generated automatically by doc++.

Copyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de