Introduction Manual Class Reference Header Reference

zoidcom_bitstream.h

Go to the documentation of this file.
00001 /****************************************
00002 * zoidcom_bitstream.h
00003 * bitstream class
00004 *
00005 * This file is part of the "Zoidcom Automated Networking System" application library.
00006 * Copyright (C)2002-2007 by Joerg Rueppel. See documentation for copyright and licensing details.
00007 *****************************************/
00008 
00012 #ifndef _ZCOM_BITSTREAM_H_
00013 #define _ZCOM_BITSTREAM_H_
00014 
00015 #include "zoidcom.h"
00016 
00019 class ZCOM_API ZCom_BitStream
00020 {
00021 public:
00023   struct BitPos
00024   {
00026     zU16 bit;
00028     zU16 pos;
00029   };
00030 protected:
00031   // array holding the data
00032   char*   m_ar;
00033   // fill counter in bits
00034   zU32    m_fill;
00035   BitPos  m_fillpos, m_readpos;
00036   // size of array in bytes
00037   zU16    m_size;
00038   // max fill in bytes
00039   zU16    m_maxfill;
00040 
00041   zU8     m_flags;
00042 public:
00045   ZCom_BitStream( zU16 _maxfill = 64 );
00047   ZCom_BitStream( const ZCom_BitStream &_str );
00049   ~ZCom_BitStream();
00050 
00052   void Clear();
00053 
00055   ZCom_BitStream *Duplicate() const;
00056 
00062 
00063 
00064   void saveWriteState( BitPos &_pos ) const {_pos = m_fillpos;}
00065 
00068   void restoreWriteState( const BitPos &_pos ) {m_fillpos = _pos; m_fill = m_fillpos.pos * 8 + m_fillpos.bit; }
00069 
00072   void saveReadState( BitPos &_pos ) const {_pos = m_readpos;}
00073 
00076   void restoreReadState( const BitPos &_pos ) {m_readpos = _pos;}
00077 
00079   void resetReadState() {m_readpos.bit = 0;m_readpos.pos = 0;}
00080 
00082   void logReadState();
00083 
00085   void logWriteState();
00086 
00088 
00094 
00095 
00096 
00097   bool checkMax( zU32 _bits );
00098 
00101   inline bool checkFull() const {return ( m_fill / 8 > m_maxfill );}
00102 
00105   inline bool endOfStream() const {return m_readpos.pos * 8 + m_readpos.bit > m_fillpos.pos * 8 + m_fillpos.bit;}
00106 
00109   inline zU32 getBitCount() const {return m_fillpos.pos * 8 + m_fillpos.bit;}
00110   // @}
00111 
00117 
00118 
00119 
00120 
00121 
00122   bool Serialize( char *_ptr, zU16 *_size, zU16 _max_size );
00123 
00128   bool Deserialize( char *_ptr, zU16 _size );
00129 
00132   zU16 getSizeHint( void );
00133 
00135 
00141 
00142 
00143 
00144 
00145 
00146 
00147   bool addInt( zU32 _data, zU8 _bits );
00148 
00152   zU32 getInt( zU8 _bits );
00153 
00156   void skipInt( zU8 _bits );
00157 
00163   bool addSignedInt( zS32 _data, zU8 _bits );
00164 
00168   zS32 getSignedInt( zU8 _bits );
00169 
00172   void skipSignedInt( zU8 _bits );
00173 
00177   bool addBool( bool _b );
00178 
00181   bool getBool();
00182 
00184   void skipBool();
00185 
00190   bool addFloat( zFloat _f, zU8 _mant_bits );
00191 
00195   zFloat getFloat( zU8 _mant_bits );
00196 
00199   void skipFloat( zU8 _mant_bits );
00200 
00204   bool addString( const char *_string );
00205 
00208   zU16 getStringSize();
00209 
00212   zU16 getStringLength();
00213 
00217   void getString( char *_buf, zU16 _maxsize );
00218 
00224   const char* getStringStatic();
00225 
00227   void skipString();
00228 
00232   bool addStringW( const wchar_t *_string );
00233 
00236 
00240   void getStringW( wchar_t *_buf, zU16 _maxsize );
00241 
00244   zU16 getStringWLength();
00245 
00252   const wchar_t* getStringWStatic();
00253 
00258   bool addBuffer( char *_buf, zU16 _size );
00259 
00264   zU16 getBuffer( char *_buf, zU16 _bytes );
00265 
00268   void skipBuffer(zU16 _bytes);
00269 
00272   zU16  getBufferMax( void );
00273 
00281   bool addBitStream( ZCom_BitStream *_stream, bool _allow_align = false );
00282 
00288   ZCom_BitStream *getBitStream( zU32 _bits, bool _allow_align = false );
00289 
00292   void skipBits(zU32 _amount);
00293   // @}
00294 
00297   bool isEqual(const ZCom_BitStream& _other) const;
00298 
00300   void* operator new(size_t _size);
00302   void  operator delete(void *_p);
00303 
00305   ZCom_BitStream& operator=(const ZCom_BitStream &_str);
00306 
00307   // only for zoidcom internal use
00308   char *getString();
00309 protected:
00310   bool checkSize( zU32 _bits );
00311   inline void incPos( struct BitPos *_pos );
00312 };
00313 
00314 #endif
00315 
00316 

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:49 2008 for Zoidcom by doxygen 1.4.6-NO