SLBM  3.0
Regional Seismic Travel Time
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
util::DataBuffer Class Reference

A byte array container used to hold binary data in the same manner as disk based file system. More...

#include <DataBuffer.h>

Public Member Functions

 DataBuffer ()
 
 DataBuffer (bool doPad)
 
 DataBuffer (string *str)
 
 DataBuffer (const DataBuffer &db)
 
virtual ~DataBuffer ()
 
DataBufferoperator= (const DataBuffer &db)
 
void dumpBuffer ()
 
void writeToFile (ofstream &ofs)
 
void writeToFile (fstream &ofs)
 
void readFromFile (fstream &ifs, int num_bytes)
 
void readFromFile (ifstream &ifs, int num_bytes)
 
void readFromFile (fstream &ifs, int64 filePos, int num_bytes)
 
void readFromFile (ifstream &ifs, int64 filePos, int num_bytes)
 
const string & readMD5HashKey ()
 
string generateMD5HashKey ()
 
string generateDataBufMD5HashKey ()
 
void align4Byte ()
 Aligns the DataBuffer position pointer on a 4 byte boundary if it is not currently aligned as such. More...
 
void align8Byte ()
 Aligns the DataBuffer position pointer on an 8 byte boundary if it is not currently aligned as such. More...
 
void checkBufferSize (int sincr)
 Checks the current buffer storage size and increments to see if it can contain sincr more bytes. If not it increments the size so that sincr bytes can be added safely. More...
 
void clear ()
 Clear the DataBuffer. More...
 
const string & readString ()
 Read a string and return a reference to be assigned to another string in the client. This function assumes the length of the string occurs imediately before the actual string data. More...
 
void readString (string &str, int num_chars)
 Read num_chars from 'this' databuffer into the input string, str. More...
 
void readCharArray (char *array, int num_chars)
 Read num_chars characters from 'this' DataBuffer into /em array. More...
 
uByte readByte ()
 Read a byte from the buffer and update the iterator. More...
 
uByte readByte (int pos)
 Read a byte from the positions specified by pos ... doesn't update dbDataPos. More...
 
void readByteArray (uByte *array, int num_bytes)
 Read num_bytes characters from 'this' DataBuffer into array. More...
 
bool readBool ()
 Read a bool from the buffer and update the iterator. More...
 
bool readBool (int pos)
 Read a bool from the positions specified by pos ... doesn't update dbDataPos. More...
 
void readBoolArray (bool *array, int num_bools)
 Read num_bools booleans from 'this' DataBuffer into array. More...
 
int readInt32 ()
 Read an int from the buffer. Make sure the buffer is 4byte alligned before reading. More...
 
int readInt32 (int pos)
 Read the int from the positions specified by pos ... doesn't update dbDataPos. More...
 
int readRawInt32 ()
 Read an Int32 ... don't check for alignment ... fast but client is responsible for alignment. More...
 
void readIntArray (int *array, int num_ints)
 Read num_ints integers from 'this' DataBuffer into array. More...
 
int64 readInt64 ()
 Read a long from the buffer. Make sure the buffer is 8byte alligned before reading. More...
 
int64 readInt64 (int pos)
 Read the long from the positions specified by pos ... doesn't update dbDataPos. More...
 
int64 readRawInt64 ()
 Read a long ... don't check for alignment ... fast but client is responsible for alignment. More...
 
void readLongArray (int64 *array, int num_longs)
 Read num_longs int64s from 'this' DataBuffer into array. More...
 
float readFloat ()
 Read a float from the buffer. Make sure the buffer is 4byte alligned before reading. More...
 
float readFloat (int pos)
 Read the float from the positions specified by pos ... doesn't update dbDataPos. More...
 
float readRawFloat ()
 Read a float ... don't check for alignment ... fast but client is responsible for alignment. More...
 
void readFloatArray (float *array, int num_floats)
 Read num_floats floats from 'this' DataBuffer into array. More...
 
double readDouble ()
 Read a double from the buffer. Make sure the buffer is 8byte alligned before reading. More...
 
double readDouble (int pos)
 Just read the double from the positions specified by pos ... doesn't update dbDataPos. More...
 
double readRawDouble ()
 Read a double ... don't check for alignment ... fast but client is responsible for alignment. More...
 
void readDoubleArray (double *array, int num_doubles)
 Read num_doubles doubles from 'this' DataBuffer into array. More...
 
void writeString (const string &in_string)
 Write the string in_string into 'this' DataBuffer. More...
 
void writeString (char *char_string)
 Write the string char_string into 'this' DataBuffer. More...
 
void writeCharArray (const char *array, int num_chars)
 Write num_chars of the character array into 'this' DataBuffer. More...
 
void writeByte (uByte b)
 Write a byte (b) to the DataBuffer. Make sure the buffer is sized appropriately before writing. More...
 
void writeByte (uByte b, int pos)
 Write a uByte (b) at databuffer position pos. Does not update the iterator. More...
 
void writeRawByte (uByte b)
 Write a uByte (b) ... don't check for alignment or size ... fast but the client is responsible for handling alignment and sizing correctly. More...
 
void writeByteArray (const uByte *array, int num_bytes)
 Write num_bytes uBytes from the input array into 'this' DataBuffer. More...
 
void writeBool (bool b)
 Write a bool (b) to the DataBuffer. Make sure the buffer is sized appropriately before writing. More...
 
void writeBool (bool b, int pos)
 Write a bool (b) at databuffer position pos. Does not update the iterator. More...
 
void writeRawBool (bool b)
 Write a bool (b) ... do not check for alignment or size ... fast but the client is responsible for handling alignment and sizing correctly. More...
 
void writeBoolArray (const bool *array, int num_bools)
 Write num_bools bools from the input array into 'this' DataBuffer. More...
 
void writeInt32 (int i)
 Write an Int32 (i) to the DataBuffer. Make sure the buffer is 4byte alligned and sized appropriatly before reading. More...
 
void writeInt32 (int i, int pos)
 Write an int (i) at databuffer position pos. Do not update the iterator. More...
 
void writeRawInt32 (int i)
 Write an Int32 (i) ... do not check for alignment or size ... fast but the client is responsible for handling alignment and sizing correctly. More...
 
void writeIntArray (const int *array, int num_ints)
 Write num_ints ints from the input array into 'this' DataBuffer. More...
 
void writeInt64 (int64 i)
 Write an Int64 (i) to the DataBuffer. Make sure the buffer is 8byte alligned and sized appropriatly before reading. More...
 
void writeInt64 (int64 i, int pos)
 Write a long (i) at databuffer position pos. Does not update the iterator. More...
 
void writeRawInt64 (int64 i)
 Write an Int64 (i) ... don't check for alignment or size ... fast but the client is responsible for handling alignment and sizing correctly. More...
 
void writeLongArray (const int64 *array, int num_longs)
 Write num_longs longs from the input array into 'this' DataBuffer. More...
 
void writeFloat (float f)
 Write a float (f) to the DataBuffer. Make sure the buffer is 4byte alligned and sized appropriatly before reading. More...
 
void writeFloat (float f, int pos)
 Write a float (f) at databuffer position pos. Does not update the iterator. More...
 
void writeRawFloat (float f)
 Write a float (f) ... do not check for alignment or size ... fast but the client is responsible for handling alignment and sizing correctly. More...
 
void writeFloatArray (const float *array, int num_floats)
 Write num_floats floats from the input array into 'this' DataBuffer. More...
 
void writeDouble (double d)
 Write a double (d) to the DataBuffer. Make sure the buffer is 8byte alligned and sized appropriatly before reading. More...
 
void writeDouble (double d, int pos)
 Write a double (d) at databuffer position pos. Does not update the iterator. More...
 
void writeRawDouble (double d)
 Write a double (d) ... do not check for alignment or size ... fast but the client is responsible for handling alignment and sizing correctly. More...
 
void writeDoubleArray (const double *array, int num_doubles)
 Write num_doubles doubles from the input array into 'this' DataBuffer. More...
 
virtual string get_class_name () const
 Returns the class name. More...
 
virtual int class_size () const
 Returns the class size (in bytes). More...
 
void setSize (int num_bytes)
 Set the size of the data buffer to num_bytes. More...
 
int size ()
 Return the current DataBuffer size. More...
 
void resetPos ()
 Reset the buffers iterator location to zero. More...
 
void setPosToEnd ()
 Set the buffers iterator position to dbSize. If current iterator exceeds dbsize then dbsize is set and dbDataPos is unchanged. More...
 
int getPos () const
 Return the buffers iterator location. More...
 
void incrementPos (int increment)
 Increment the buffers iterator by increment bytes. This is an unsafe operation. If dbDataPos + increment > dbSize. dbSize is NOT checked. More...
 
void decrementPos (int decrement)
 Decrement the buffers iterator by decrement bytes. This is an unsafe operation. If dbDataPos - decrement < 0. More...
 
string getData () const
 Return a reference to the DataBuffer. More...
 
int getCapacity () const
 Return allocated capacity of 'this' DataBuffer. More...
 
char * getPosPointer ()
 Return a pointer to the current iterator location in the buffer. More...
 
char * getPosPointer (int pos)
 Return a Pointer to position pos in the buffer. More...
 
void setByteOrderReverse (bool bor)
 Sets the byte order reverse flag to bor. More...
 
void byteOrderReverseOn ()
 Sets the byte order reverse flag to true. More...
 
void byteOrderReverseOff ()
 Sets the byte order reverse flag to false. More...
 
bool isByteOrderReversed () const
 Returns true if the byte order in reads and writes is reversed for all 2, 4, or 8 byte intrinsincs (short, int, long, float, double, etc.). More...
 
void reserve (int sze)
 brief Reserves space in the DataBuffer More...
 

Static Public Member Functions

static void reverseBOArray (int n, char *a, int s)
 
static void reverseBO2Array (int n, char *a)
 
static void reverseBO4Array (int n, char *a)
 
static void reverseBO8Array (int n, char *a)
 
static void reverseBO2 (char *d)
 Reverses byte order of d. d is assumed to point to an 2 byte element. More...
 
static void reverseBO4 (char *d)
 Reverses byte order of d. d is assumed to point to an 4 byte element. More...
 
static void reverseBO8 (char *d)
 Reverses byte order of d. d is assumed to point to an 8 byte element. More...
 
static string class_name ()
 Static function that returns the class name. More...
 
static int getAllocationReqSize ()
 

Static Public Attributes

static const int ALLOCATION_REQ_SIZE
 Default allocation requirement size for a data buffer. More...
 

Protected Attributes

string * dbData
 A string object is used to contain the actual data. More...
 
int dbDataPos
 The current iterator position in the data container (dbData). More...
 
int dbSize
 The current size of the data container. More...
 
bool dbPad
 A boolean, that if true, maintains 4 and 8 byte alignment in support of double alignment compilation. More...
 
bool dbReverse
 A boolean, that if true, reverses the byte order of all 2, 4, and 8 byte intrinsics (shorts, ints, long, floats, doubles, etc.). This flag is set by the FileDatabase object only and otherwise defaults to false. The flag is used to convert byte order between big- and little- endian formats. More...
 
bool dbOwnStr
 A boolean, that if true, indicates the storage string for this DataBuffer is owned and therefore deleted when the DataBuffer is deleted. More...
 

Detailed Description

The object contains a padding facility to maintain 1, 4, and 8 byte aligned objects so that the objects that utilize this class can be compiled as doubly aligned. This object is used extensively in support of database object serialization. The class contains a long list of methods and properties supporting read/write capability for string, char, byte, bool, int, long, float, and double types. Most types also contain an array read/write capability. Finally, the ability to read and write compressed data is provided using the zlib library facility.

Constructor & Destructor Documentation

util::DataBuffer::DataBuffer ( )
util::DataBuffer::DataBuffer ( bool  doPad)
util::DataBuffer::DataBuffer ( string *  str)
util::DataBuffer::DataBuffer ( const DataBuffer db)
virtual util::DataBuffer::~DataBuffer ( )
virtual

Member Function Documentation

void util::DataBuffer::align4Byte ( )
inline
void util::DataBuffer::align8Byte ( )
inline
void util::DataBuffer::byteOrderReverseOff ( )
inline
void util::DataBuffer::byteOrderReverseOn ( )
inline
void util::DataBuffer::checkBufferSize ( int  sincr)
inline
string util::DataBuffer::class_name ( )
inlinestatic
int util::DataBuffer::class_size ( ) const
inlinevirtual
void util::DataBuffer::clear ( )
inline
void util::DataBuffer::decrementPos ( int  decrement)
inline
void util::DataBuffer::dumpBuffer ( )
string util::DataBuffer::generateDataBufMD5HashKey ( )
string util::DataBuffer::generateMD5HashKey ( )
string util::DataBuffer::get_class_name ( ) const
inlinevirtual
static int util::DataBuffer::getAllocationReqSize ( )
static
int util::DataBuffer::getCapacity ( ) const
inline
string util::DataBuffer::getData ( ) const
inline
int util::DataBuffer::getPos ( ) const
inline
char * util::DataBuffer::getPosPointer ( )
inline
char * util::DataBuffer::getPosPointer ( int  pos)
inline
void util::DataBuffer::incrementPos ( int  increment)
inline
bool util::DataBuffer::isByteOrderReversed ( ) const
inline
DataBuffer& util::DataBuffer::operator= ( const DataBuffer db)
bool util::DataBuffer::readBool ( )
inline
bool util::DataBuffer::readBool ( int  pos)
inline
void util::DataBuffer::readBoolArray ( bool *  array,
int  num_bools 
)
inline
uByte util::DataBuffer::readByte ( )
inline
uByte util::DataBuffer::readByte ( int  pos)
inline
void util::DataBuffer::readByteArray ( uByte *  array,
int  num_bytes 
)
inline
void util::DataBuffer::readCharArray ( char *  array,
int  num_chars 
)
inline
double util::DataBuffer::readDouble ( )
inline
double util::DataBuffer::readDouble ( int  pos)
inline
void util::DataBuffer::readDoubleArray ( double *  array,
int  num_doubles 
)
inline
float util::DataBuffer::readFloat ( )
inline
float util::DataBuffer::readFloat ( int  pos)
inline
void util::DataBuffer::readFloatArray ( float *  array,
int  num_floats 
)
inline
void util::DataBuffer::readFromFile ( fstream &  ifs,
int  num_bytes 
)
void util::DataBuffer::readFromFile ( ifstream &  ifs,
int  num_bytes 
)
void util::DataBuffer::readFromFile ( fstream &  ifs,
int64  filePos,
int  num_bytes 
)
void util::DataBuffer::readFromFile ( ifstream &  ifs,
int64  filePos,
int  num_bytes 
)
int util::DataBuffer::readInt32 ( )
inline
int util::DataBuffer::readInt32 ( int  pos)
inline
int64 util::DataBuffer::readInt64 ( )
inline
int64 util::DataBuffer::readInt64 ( int  pos)
inline
void util::DataBuffer::readIntArray ( int *  array,
int  num_ints 
)
inline
void util::DataBuffer::readLongArray ( int64 *  array,
int  num_longs 
)
inline
const string& util::DataBuffer::readMD5HashKey ( )
double util::DataBuffer::readRawDouble ( )
inline
float util::DataBuffer::readRawFloat ( )
inline
int util::DataBuffer::readRawInt32 ( )
inline
int64 util::DataBuffer::readRawInt64 ( )
inline
const string & util::DataBuffer::readString ( )
inline
void util::DataBuffer::readString ( string &  str,
int  num_chars 
)
inline
void util::DataBuffer::reserve ( int  sze)
inline

Reserves space in the DataBuffer.

void util::DataBuffer::resetPos ( )
inline
void util::DataBuffer::reverseBO2 ( char *  d)
inlinestatic
static void util::DataBuffer::reverseBO2Array ( int  n,
char *  a 
)
static
void util::DataBuffer::reverseBO4 ( char *  d)
inlinestatic
static void util::DataBuffer::reverseBO4Array ( int  n,
char *  a 
)
static
void util::DataBuffer::reverseBO8 ( char *  d)
inlinestatic
static void util::DataBuffer::reverseBO8Array ( int  n,
char *  a 
)
static
static void util::DataBuffer::reverseBOArray ( int  n,
char *  a,
int  s 
)
static
void util::DataBuffer::setByteOrderReverse ( bool  bor)
inline
void util::DataBuffer::setPosToEnd ( )
inline
void util::DataBuffer::setSize ( int  num_bytes)
inline
int util::DataBuffer::size ( )
inline
void util::DataBuffer::writeBool ( bool  b)
inline
void util::DataBuffer::writeBool ( bool  b,
int  pos 
)
inline
void util::DataBuffer::writeBoolArray ( const bool *  array,
int  num_bools 
)
inline
void util::DataBuffer::writeByte ( uByte  b)
inline
void util::DataBuffer::writeByte ( uByte  b,
int  pos 
)
inline
void util::DataBuffer::writeByteArray ( const uByte *  array,
int  num_bytes 
)
inline
void util::DataBuffer::writeCharArray ( const char *  array,
int  num_chars 
)
inline
void util::DataBuffer::writeDouble ( double  d)
inline
void util::DataBuffer::writeDouble ( double  d,
int  pos 
)
inline
void util::DataBuffer::writeDoubleArray ( const double *  array,
int  num_doubles 
)
inline
void util::DataBuffer::writeFloat ( float  f)
inline
void util::DataBuffer::writeFloat ( float  f,
int  pos 
)
inline
void util::DataBuffer::writeFloatArray ( const float *  array,
int  num_floats 
)
inline
void util::DataBuffer::writeInt32 ( int  i)
inline
void util::DataBuffer::writeInt32 ( int  i,
int  pos 
)
inline
void util::DataBuffer::writeInt64 ( int64  i)
inline
void util::DataBuffer::writeInt64 ( int64  i,
int  pos 
)
inline
void util::DataBuffer::writeIntArray ( const int *  array,
int  num_ints 
)
inline
void util::DataBuffer::writeLongArray ( const int64 *  array,
int  num_longs 
)
inline
void util::DataBuffer::writeRawBool ( bool  b)
inline
void util::DataBuffer::writeRawByte ( uByte  b)
inline
void util::DataBuffer::writeRawDouble ( double  d)
inline
void util::DataBuffer::writeRawFloat ( float  f)
inline
void util::DataBuffer::writeRawInt32 ( int  i)
inline
void util::DataBuffer::writeRawInt64 ( int64  i)
inline
void util::DataBuffer::writeString ( const string &  in_string)
inline
void util::DataBuffer::writeString ( char *  char_string)
inline
void util::DataBuffer::writeToFile ( ofstream &  ofs)
void util::DataBuffer::writeToFile ( fstream &  ofs)

Member Data Documentation

const int util::DataBuffer::ALLOCATION_REQ_SIZE
static
string* util::DataBuffer::dbData
protected
int util::DataBuffer::dbDataPos
protected
bool util::DataBuffer::dbOwnStr
protected
bool util::DataBuffer::dbPad
protected
bool util::DataBuffer::dbReverse
protected
int util::DataBuffer::dbSize
protected

The documentation for this class was generated from the following file: