"L. Spiro Engine"

F:/My Projects/LSEngine/Modules/LSStandardLib/Src/Streams/LSSTDBitStream.h

00001 
00016 #ifndef __LSSTD_BITSTREAM_H__
00017 #define __LSSTD_BITSTREAM_H__
00018 
00019 #include "../LSSTDStandardLib.h"
00020 #include "LSSTDStream.h"
00021 
00022 namespace lsstd {
00023 
00030         class CBitStream : public IStream {
00031         public :
00032                 // == Various constructors.
00033                 LSE_CALL                                                                CBitStream();
00034                 LSE_CALL                                                                ~CBitStream();
00035 
00036                 
00037                 // == Functions.
00041                 LSVOID LSE_CALL                                                 Reset();
00042 
00050                 LSBOOL LSE_CALL                                                 ReadBits( LSUINT8 * _pui8Buffer, LSUINT32 _ui32BitsToRead ) const;
00051 
00059                 virtual LSUINT32 LSE_CALL                               ReadBytes( LSUINT8 * _pui8Buffer, LSUINT32 _ui32BytesToRead ) const;
00060 
00066                 virtual LSUINT64 LSE_CALL                               ReadUInt64() const;
00067                 
00073                 virtual LSUINT32 LSE_CALL                               ReadUInt32() const;
00074 
00080                 virtual LSUINT16 LSE_CALL                               ReadUInt16() const;
00081 
00087                 virtual LSUINT8 LSE_CALL                                ReadUInt8() const;
00088 
00094                 virtual LSFLOAT LSE_CALL                                ReadFloat() const;
00095 
00101                 virtual LSDOUBLE LSE_CALL                               ReadDouble() const;
00102 
00110                 LSBOOL LSE_CALL                                                 WriteBits( const LSUINT8 * _pui8Buffer, LSUINT32 _ui32BitsToWrite );
00111 
00119                 virtual LSUINT32 LSE_CALL                               WriteBytes( const LSUINT8 * _pui8Buffer, LSUINT32 _ui32BytesToWrite );
00120 
00126                 virtual LSBOOL LSE_CALL                                 WriteUInt64( const LSUINT64 &_ui64Value );
00127                 
00133                 virtual LSBOOL LSE_CALL                                 WriteUInt32( LSUINT32 _ui32Value );
00134 
00140                 virtual LSBOOL LSE_CALL                                 WriteUInt16( LSUINT16 _ui16Value );
00141 
00147                 virtual LSBOOL LSE_CALL                                 WriteUInt8( LSUINT8 _ui8Value );
00148 
00154                 virtual LSBOOL LSE_CALL                                 WriteFloat( LSFLOAT _fValue );
00155 
00161                 virtual LSBOOL LSE_CALL                                 WriteDouble( const LSDOUBLE &_dValue );
00162 
00169                 LSUINT32 LSE_CALL                                               GetLengthInBytes() const;
00170 
00176                 const LSUINT8 * LSE_CALL                                GetRawBytes() const;
00177 
00185                 LSUINT64 LSE_CALL                                               SetPos( LSUINT64 _ui64Pos ) const;
00186 
00192                 LSUINT64 LSE_CALL                                               GetPos() const;
00193 
00202                 LSBOOL LSE_CALL                                                 PreAlloc( LSUINT64 _ui64NewSize );
00203 
00212                 LSVOID LSE_CALL                                                 Borrow( const LSUINT8 * _pui8Buffer, LSUINTPTR _uiptrSize );
00213 
00214         protected :
00215                 // == Members.
00219                 LSUINT64                                                                m_ui64TotalBits;
00220 
00224                 LSUINT32 *                                                              m_pui32Buffer;
00225 
00229                 LSUINT32                                                                m_ui32Total;
00230 
00234                 LSUINT32                                                                m_ui32Alloc;
00235 
00239                 LSBOOL                                                                  m_bBorrowed;
00240 
00241 
00248                 mutable LSUINT64                                                m_ui64Pos;
00249 
00250 
00251                 // == Functions.
00259                 LSBOOL LSE_CALL                                                 Alloc( LSUINT32 _ui32Total );
00260 
00268                 virtual LSVOID * LSE_CALL                               ReAlloc( LSVOID * _pvOriginal, LSUINT32 _ui32Total ) const;
00269 
00275                 virtual LSVOID LSE_CALL                                 Free( LSVOID * _pvOriginal ) const;
00276 
00284                 static LSVOID LSE_CALL                                  GetByteAndBit( const LSUINT64 &_ui64BitPos,
00285                         LSUINT32 &_ui32ByteIndex, LSUINT32 &_ui32BitIndex );
00286         };
00287 
00288 
00289         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00290         // DEFINITIONS
00291         // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00292         // == Functions.
00300         LSE_INLINE LSVOID LSE_CALL CBitStream::GetByteAndBit( const LSUINT64 &_ui64BitPos,
00301                 LSUINT32 &_ui32ByteIndex, LSUINT32 &_ui32BitIndex ) {
00302                 _ui32ByteIndex = static_cast<LSUINT32>(_ui64BitPos >> 3ULL);
00303                 _ui32BitIndex = static_cast<LSUINT32>(_ui64BitPos & 7ULL);
00304         }
00305 
00306 }       // namespace lsstd
00307 
00308 #endif  // __LSSTD_BITSTREAM_H__
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator