OSG::BitUnpacker Class Reference

#include <OSGNFIOBitPacker.h>

List of all members.


Public Types

Types


typedef std::vector< UInt8 > BufferType

Public Member Functions

Constructor


 BitUnpacker (const BufferType &buffer, UInt32 max)
Unpack


UInt32 unpack (void)

Private Attributes

UInt32 _numBitsToUnpack
Int32 _numBitsRemaining
Int32 _nextBit
const BufferType_buffer

Detailed Description

Definition at line 94 of file OSGNFIOBitPacker.h.


Member Typedef Documentation

typedef std::vector<UInt8> OSG::BitUnpacker::BufferType

Definition at line 102 of file OSGNFIOBitPacker.h.


Constructor & Destructor Documentation

BitUnpacker::BitUnpacker ( const BufferType buffer,
UInt32  max 
)

Definition at line 161 of file OSGNFIOBitPacker.cpp.

References _numBitsToUnpack.

00161                                                                    :
00162     _numBitsToUnpack (1                ),
00163     _numBitsRemaining(buffer.size() * 8),
00164     _nextBit         (0                ),
00165     _buffer          (buffer           )
00166 {
00167     while(true)
00168     {
00169         UInt32 maxValue = (UInt32) (1 << _numBitsToUnpack) - 1;
00170         if (maxValue >= max)
00171             break;
00172 
00173         ++_numBitsToUnpack;
00174     }
00175 }


Member Function Documentation

UInt32 BitUnpacker::unpack ( void   ) 

Definition at line 177 of file OSGNFIOBitPacker.cpp.

References _buffer, _nextBit, _numBitsRemaining, and _numBitsToUnpack.

Referenced by OSG::NFIOGeometry::readPackedIndices(), and OSG::OSBGeometryHelper::readPackedIntegralProperty().

00178 {
00179     UInt32 result          = 0;
00180     UInt32 numBitsToUnpack = _numBitsToUnpack;
00181 
00182     while(numBitsToUnpack)
00183     {
00184         UInt32 byteIndex = (_nextBit / 8);
00185         UInt32 bitIndex  = (_nextBit % 8);
00186         UInt32 srcMask   = (1 << (7 - bitIndex));
00187         UInt32 destMask  = (1 << (numBitsToUnpack - 1));
00188 
00189         if(_buffer[byteIndex] & srcMask)
00190             result |= destMask;
00191         numBitsToUnpack--;
00192         _nextBit++;
00193     }
00194 
00195     _numBitsRemaining -= numBitsToUnpack;
00196 
00197     return result;
00198 }


Member Data Documentation

Definition at line 122 of file OSGNFIOBitPacker.h.

Referenced by BitUnpacker(), and unpack().

Definition at line 123 of file OSGNFIOBitPacker.h.

Referenced by unpack().

Int32 OSG::BitUnpacker::_nextBit [private]

Definition at line 124 of file OSGNFIOBitPacker.h.

Referenced by unpack().

Definition at line 126 of file OSGNFIOBitPacker.h.

Referenced by unpack().


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