Introduction Manual Class Reference Header Reference

ZCom_BitStream Class Reference

Collaboration diagram for ZCom_BitStream:

Collaboration graph
[legend]
List of all members.

Detailed Description

Bitstreams are Zoidcom's native data exchange objects.


Public Member Functions

void Clear ()
 Remove all data and reset position counters.
ZCom_BitStreamDuplicate () const
 Make exact copy of this object, including position counters.
bool isEqual (const ZCom_BitStream &_other) const
 Check if two bitstreams contain the same data.
void operator delete (void *_p)
 Overloaded memory operator ensuring that always Zoidcom's delete gets called.
void * operator new (size_t _size)
 Overloaded memory operator ensuring that always Zoidcom's new gets called.
ZCom_BitStreamoperator= (const ZCom_BitStream &_str)
 Assignment operator.
 ZCom_BitStream (const ZCom_BitStream &_str)
 Copy constructor.
 ZCom_BitStream (zU16 _maxfill=64)
 Constructor.
 ~ZCom_BitStream ()
 Destructor.
Data operations
bool addBitStream (ZCom_BitStream *_stream, bool _allow_align=false)
 Add an existing bitstream to the stream.
bool addBool (bool _b)
 Add a bool to the stream.
bool addBuffer (char *_buf, zU16 _size)
 Add a buffer to the stream.
bool addFloat (zFloat _f, zU8 _mant_bits)
 Add a float to the stream.
bool addInt (zU32 _data, zU8 _bits)
 Add an int to the stream.
bool addSignedInt (zS32 _data, zU8 _bits)
 Add a signed int to the stream.
bool addString (const char *_string)
 Add a string to the stream.
bool addStringW (const wchar_t *_string)
 Add a string to the stream.
ZCom_BitStreamgetBitStream (zU32 _bits, bool _allow_align=false)
 Retrieve a whole bitstream.
bool getBool ()
 Retrieve a bool.
zU16 getBuffer (char *_buf, zU16 _bytes)
 Retrieve a buffer.
zU16 getBufferMax (void)
 Get amount of bytes available for buffer get.
zFloat getFloat (zU8 _mant_bits)
 Retrieve a float.
zU32 getInt (zU8 _bits)
 Retrieve an int.
zS32 getSignedInt (zU8 _bits)
 Retrieve signed int.
void getString (char *_buf, zU16 _maxsize)
 Retrieve a string.
zU16 getStringLength ()
 Get length of upcoming string.
zU16 getStringSize ()
 Get size of upcoming string.
const char * getStringStatic ()
 Retrieve a string via static buffer.
void getStringW (wchar_t *_buf, zU16 _maxsize)
 Get size of upcoming string. Retrieve a string.
zU16 getStringWLength ()
 Get length of upcoming string.
const wchar_t * getStringWStatic ()
 Retrieve a string via static buffer.
void skipBits (zU32 _amount)
 Skip some bits in the stream. This only affects the get* methods.
void skipBool ()
 Skip a bool.
void skipBuffer (zU16 _bytes)
 Skip a stored buffer in the stream.
void skipFloat (zU8 _mant_bits)
 Skip a float.
void skipInt (zU8 _bits)
 Skip an int.
void skipSignedInt (zU8 _bits)
 Skip a signed int.
void skipString ()
 Skip a string or wstring.
Data size checks.
bool checkFull () const
 Check if stream limit has been exceeded.
bool checkMax (zU32 _bits)
 Check if stream has enough space for _bits more bits.
bool endOfStream () const
 Check if stream read pos is at end of stream.
zU32 getBitCount () const
 Get amount of bits stored in the stream.
(De-)Serialization.
bool Deserialize (char *_ptr, zU16 _size)
 Deserialize array to stream.
zU16 getSizeHint (void)
 Get needed size for serialize buffer.
bool Serialize (char *_ptr, zU16 *_size, zU16 _max_size)
 Serialize stream to array.
Stream position operations.
void logReadState ()
 Log current read position to the log output.
void logWriteState ()
 Log current write position to the log output.
void resetReadState ()
 Reset read state to beginning of stream.
void restoreReadState (const BitPos &_pos)
 Restore read state (Undos all get*** calls since 'saveReadState').
void restoreWriteState (const BitPos &_pos)
 Restore write state. (Undos all add*** calls since 'saveWriteState').
void saveReadState (BitPos &_pos) const
 Store read state.
void saveWriteState (BitPos &_pos) const
 Store write state.

Classes

struct  BitPos
 Position in bitstream. More...


Constructor & Destructor Documentation

ZCom_BitStream::ZCom_BitStream zU16  _maxfill = 64  ) 
 

Constructor.

Parameters:
_maxfill Expected amount of bytes the stream will hold.

ZCom_BitStream::ZCom_BitStream const ZCom_BitStream _str  ) 
 

Copy constructor.

ZCom_BitStream::~ZCom_BitStream  ) 
 

Destructor.


Member Function Documentation

void ZCom_BitStream::Clear  ) 
 

Remove all data and reset position counters.

ZCom_BitStream* ZCom_BitStream::Duplicate  )  const
 

Make exact copy of this object, including position counters.

void ZCom_BitStream::saveWriteState BitPos _pos  )  const [inline]
 

Store write state.

Parameters:
_pos Store target.

void ZCom_BitStream::restoreWriteState const BitPos _pos  )  [inline]
 

Restore write state. (Undos all add*** calls since 'saveWriteState').

Parameters:
_pos Previously stored BitPos object.

void ZCom_BitStream::saveReadState BitPos _pos  )  const [inline]
 

Store read state.

Parameters:
_pos Store target.

void ZCom_BitStream::restoreReadState const BitPos _pos  )  [inline]
 

Restore read state (Undos all get*** calls since 'saveReadState').

Parameters:
_pos Previously stored BitPos object.

void ZCom_BitStream::resetReadState  )  [inline]
 

Reset read state to beginning of stream.

void ZCom_BitStream::logReadState  ) 
 

Log current read position to the log output.

void ZCom_BitStream::logWriteState  ) 
 

Log current write position to the log output.

bool ZCom_BitStream::checkMax zU32  _bits  ) 
 

Check if stream has enough space for _bits more bits.

Parameters:
_bits The amount of bits to check against.
Returns:
'true' if enough space is left.

bool ZCom_BitStream::checkFull  )  const [inline]
 

Check if stream limit has been exceeded.

Returns:
'true' if self imposed max fill has been exceeded.

bool ZCom_BitStream::endOfStream  )  const [inline]
 

Check if stream read pos is at end of stream.

Returns:
'true' if end of stream has been reached

zU32 ZCom_BitStream::getBitCount  )  const [inline]
 

Get amount of bits stored in the stream.

Returns:
# of bits in the stream.

bool ZCom_BitStream::Serialize char *  _ptr,
zU16 _size,
zU16  _max_size
 

Serialize stream to array.

Parameters:
_ptr Store target.
_size Pointer to an int where the stored amount of bytes will be written.
_max_size Size of the storage array.
Returns:
'true' on success.

bool ZCom_BitStream::Deserialize char *  _ptr,
zU16  _size
 

Deserialize array to stream.

Parameters:
_ptr Pointer to the serialized array.
_size Size of that array.
Returns:
'true' if no errors occured.

zU16 ZCom_BitStream::getSizeHint void   ) 
 

Get needed size for serialize buffer.

Returns:
Amount of bytes needed to serialize the current stream.

bool ZCom_BitStream::addInt zU32  _data,
zU8  _bits
 

Add an int to the stream.

Note:
The sign bit is only added if enough bits, in most cases 32, are used. For adding signed data use addSignedInt() instead.
Parameters:
_data Input data.
_bits Amount of bits to store.
Returns:
'true' on success.

zU32 ZCom_BitStream::getInt zU8  _bits  ) 
 

Retrieve an int.

Parameters:
_bits Amount of bits to retrieve.
Returns:
The int.

void ZCom_BitStream::skipInt zU8  _bits  ) 
 

Skip an int.

Parameters:
_bits Amount of bits used to store the int.

bool ZCom_BitStream::addSignedInt zS32  _data,
zU8  _bits
 

Add a signed int to the stream.

Parameters:
_data Input data.
_bits Amount of bits to store.
Note:
One extra bit is stored for sign.
Returns:
'true' on success.

zS32 ZCom_BitStream::getSignedInt zU8  _bits  ) 
 

Retrieve signed int.

Parameters:
_bits Amount of bits to retrieve.
Returns:
The int.

void ZCom_BitStream::skipSignedInt zU8  _bits  ) 
 

Skip a signed int.

Parameters:
_bits Amount of bits used to store the signed int.

bool ZCom_BitStream::addBool bool  _b  ) 
 

Add a bool to the stream.

Parameters:
_b Input data.
Returns:
'true' on success.

bool ZCom_BitStream::getBool  ) 
 

Retrieve a bool.

Returns:
The bool.

void ZCom_BitStream::skipBool  ) 
 

Skip a bool.

bool ZCom_BitStream::addFloat zFloat  _f,
zU8  _mant_bits
 

Add a float to the stream.

Parameters:
_f Input data.
_mant_bits Amount of mantissa bits to store. For more details look ZCom_Node::addReplicationFloat().
Returns:
'true' on success.

zFloat ZCom_BitStream::getFloat zU8  _mant_bits  ) 
 

Retrieve a float.

Parameters:
_mant_bits Amount of mantissa bits that have been stored with addFloat().
Returns:
The float.

void ZCom_BitStream::skipFloat zU8  _mant_bits  ) 
 

Skip a float.

Parameters:
_mant_bits Mantissa bits used to store the float.

bool ZCom_BitStream::addString const char *  _string  ) 
 

Add a string to the stream.

Parameters:
_string NULL-terminated c-string.
Returns:
'true' on success.

zU16 ZCom_BitStream::getStringSize  ) 
 

Get size of upcoming string.

Returns:
If a string or widestring is the next data in the stream call this to get its size (in bytes), without trailing 0.

zU16 ZCom_BitStream::getStringLength  ) 
 

Get length of upcoming string.

Returns:
If a string is the next data in the stream call this to get its length (number of characters), without trailing 0.

void ZCom_BitStream::getString char *  _buf,
zU16  _maxsize
 

Retrieve a string.

Parameters:
_buf Should point to an allocated buffer.
_maxsize Size of that buffer. Find size of incoming string with getStringSize().

const char* ZCom_BitStream::getStringStatic  ) 
 

Retrieve a string via static buffer.

Returns:
Pointer to a static buffer containing the next string in the stream.
The buffer is of size 2048, longer strings are cut. The next call to this method will overwrite the content of this buffer.
Note:
This method is thread-safe.

void ZCom_BitStream::skipString  ) 
 

Skip a string or wstring.

bool ZCom_BitStream::addStringW const wchar_t *  _string  ) 
 

Add a string to the stream.

Parameters:
_string NULL-terminated c-string.
Returns:
'true' on success.

void ZCom_BitStream::getStringW wchar_t *  _buf,
zU16  _maxsize
 

Get size of upcoming string. Retrieve a string.

Parameters:
_buf Should point to an allocated buffer.
_maxsize Size of that buffer (elementcount, not bytes). Find size of incoming string with getStringWLength().

zU16 ZCom_BitStream::getStringWLength  ) 
 

Get length of upcoming string.

Returns:
If a string is the next data in the stream call this to get its length (number of characters), without trailing 0.

const wchar_t* ZCom_BitStream::getStringWStatic  ) 
 

Retrieve a string via static buffer.

Returns:
Pointer to a static buffer containing the next string in the stream.
The buffer can hold wide strings of upto 1024 wchars, longer strings are cut. The next call to this method will overwrite the content of this buffer.
Note:
This method is thread-safe.

bool ZCom_BitStream::addBuffer char *  _buf,
zU16  _size
 

Add a buffer to the stream.

Parameters:
_buf Pointer to the buffer.
_size of the buffer.
Returns:
'true' on success.

zU16 ZCom_BitStream::getBuffer char *  _buf,
zU16  _bytes
 

Retrieve a buffer.

Parameters:
_buf Pointer to allocated array.
_bytes Size of that array.
Returns:
The amount of bytes really read (is smaller for end of stream conditions).

void ZCom_BitStream::skipBuffer zU16  _bytes  ) 
 

Skip a stored buffer in the stream.

Parameters:
_bytes The size of the buffer to skip.

zU16 ZCom_BitStream::getBufferMax void   ) 
 

Get amount of bytes available for buffer get.

Returns:
Maximum size a getBuffer() would be able to retrieve.

bool ZCom_BitStream::addBitStream ZCom_BitStream _stream,
bool  _allow_align = false
 

Add an existing bitstream to the stream.

Parameters:
_stream The bitstream to attach.
_allow_align Use allow_align=true only if you intent to get the stream back as a whole with getBitStream(.., true) Otherwise you cannot know how many padding bits have been added.
Returns:
'true' on success.
For extracting the stream again with getBitStream() the same value for _allow_align must be used.

ZCom_BitStream* ZCom_BitStream::getBitStream zU32  _bits,
bool  _allow_align = false
 

Retrieve a whole bitstream.

Parameters:
_bits Amount of bits to retrieve.
_allow_align See addBitStream().
The application is responsible for deleting the resulting object.

void ZCom_BitStream::skipBits zU32  _amount  ) 
 

Skip some bits in the stream. This only affects the get* methods.

Parameters:
_amount Number of bits to skip.

bool ZCom_BitStream::isEqual const ZCom_BitStream _other  )  const
 

Check if two bitstreams contain the same data.

Returns:
true If two bitstreams have the same contents.

void* ZCom_BitStream::operator new size_t  _size  ) 
 

Overloaded memory operator ensuring that always Zoidcom's new gets called.

void ZCom_BitStream::operator delete void *  _p  ) 
 

Overloaded memory operator ensuring that always Zoidcom's delete gets called.

ZCom_BitStream& ZCom_BitStream::operator= const ZCom_BitStream _str  ) 
 

Assignment operator.


This file is part of the documentation for Zoidcom. Documentation copyright © 2004-2008 by Jörg Rüppel. Generated on Sat Aug 16 15:26:50 2008 for Zoidcom by doxygen 1.4.6-NO