G4OutBitStream Class Reference

#include <G4RTOutBitStream.hh>


Public Member Functions

 G4OutBitStream (int size)
 ~G4OutBitStream ()
void SetBits (int v, int numBits)
void SetByte (u_char dat)
void SetWord (u_int dat)
void CopyByte (const char *src, int n)
u_charGetStreamAddress (void)
int GetStreamSize (void)

Protected Member Functions

void IncBuf (void)
void FullBit (void)
void Set8Bits (u_char v, int numBits)
void SetFewBits (u_char v, int numBits)
void SetBits2Byte (u_char v, int numBits)

Protected Attributes

u_charmHeadOfBuf
u_charmBuf
u_charmEndOfBuf
int mBitPos
int mWriteFlag


Detailed Description

Definition at line 44 of file G4RTOutBitStream.hh.


Constructor & Destructor Documentation

G4OutBitStream::G4OutBitStream ( int  size  ) 

Definition at line 38 of file G4RTOutBitStream.cc.

References mBitPos, mBuf, mEndOfBuf, mHeadOfBuf, and mWriteFlag.

00039 {
00040   if(size < 1)
00041         throw( G4MemoryError( size, "G4OutBitStream" ) );
00042 
00043   mHeadOfBuf = mBuf = new u_char[size];
00044   if( mHeadOfBuf == 0 )
00045         throw( G4MemoryError( size, "G4OutBitStream" ) );
00046 
00047   mEndOfBuf = mBuf + size;
00048 
00049   memset( mHeadOfBuf, 0, size );
00050 
00051   mBitPos = 7;
00052   mWriteFlag = 1;
00053 }

G4OutBitStream::~G4OutBitStream (  ) 

Definition at line 55 of file G4RTOutBitStream.cc.

References mBuf.

00056 {
00057   delete mBuf;
00058 }


Member Function Documentation

void G4OutBitStream::CopyByte ( const char *  src,
int  n 
)

Definition at line 158 of file G4RTOutBitStream.cc.

References FullBit(), mBuf, and mEndOfBuf.

Referenced by G4JpegCoder::WriteHeader().

00159 {
00160   if( mBuf+n < mEndOfBuf ){
00161         FullBit();
00162         memcpy( mBuf, src, n );
00163         mBuf += n;
00164         return;
00165   }
00166   throw( G4BufferError( "CopyByte" ) );
00167 }

void G4OutBitStream::FullBit ( void   )  [protected]

Definition at line 125 of file G4RTOutBitStream.cc.

References mBitPos, and SetFewBits().

Referenced by CopyByte(), SetByte(), and SetWord().

00126 {
00127   if( mBitPos != 7 )
00128         SetFewBits( BitFullMaskT[mBitPos], mBitPos+1 );
00129 }

u_char* G4OutBitStream::GetStreamAddress ( void   )  [inline]

Definition at line 54 of file G4RTOutBitStream.hh.

References mHeadOfBuf.

Referenced by G4JpegCoder::GetJpegData().

00054 {return mHeadOfBuf;};

int G4OutBitStream::GetStreamSize ( void   )  [inline]

Definition at line 55 of file G4RTOutBitStream.hh.

Referenced by G4JpegCoder::GetJpegData().

00055 {return mBuf - mHeadOfBuf;};

void G4OutBitStream::IncBuf ( void   )  [protected]

Definition at line 61 of file G4RTOutBitStream.cc.

References mBuf, mEndOfBuf, and mWriteFlag.

Referenced by SetBits2Byte(), SetByte(), SetFewBits(), and SetWord().

00062 {
00063   if( ++mBuf >= mEndOfBuf )
00064         mWriteFlag = 0;
00065 }

void G4OutBitStream::Set8Bits ( u_char  v,
int  numBits 
) [protected]

Definition at line 115 of file G4RTOutBitStream.cc.

References mBitPos, SetBits2Byte(), and SetFewBits().

Referenced by SetBits().

00116 {
00117   if( mBitPos + 1 >= numBits )
00118         SetFewBits( (u_char)v, numBits );
00119  else
00120         SetBits2Byte( (u_char)v, numBits );
00121 }

void G4OutBitStream::SetBits ( int  v,
int  numBits 
)

Definition at line 70 of file G4RTOutBitStream.cc.

References Set8Bits().

Referenced by G4JpegCoder::CodeHuffman().

00071 {
00072   if( numBits == 0 )
00073         return;
00074   if( numBits > 16 )
00075         throw( G4BufferError( "SetBits:Max Bit Over" ) );
00076   if( numBits > 8 ){
00077         Set8Bits( u_char(v>>8), numBits-8 );
00078         numBits = 8;
00079   }
00080   Set8Bits( u_char(v), numBits );
00081 }

void G4OutBitStream::SetBits2Byte ( u_char  v,
int  numBits 
) [protected]

Definition at line 99 of file G4RTOutBitStream.cc.

References IncBuf(), mBitPos, and mBuf.

Referenced by Set8Bits().

00100 {
00101   v &= BitFullMaskT[numBits-1];
00102   int nextBits = numBits - (mBitPos + 1);
00103   *mBuf |= ( v >> nextBits ) & BitFullMaskT[mBitPos];
00104   if( *mBuf == 0xff ){
00105         IncBuf();
00106         *mBuf = 0;
00107   }
00108   IncBuf();
00109 
00110   *mBuf = v << (8 - nextBits);
00111   mBitPos = 7 - nextBits;
00112 }

void G4OutBitStream::SetByte ( u_char  dat  ) 

Definition at line 132 of file G4RTOutBitStream.cc.

References FullBit(), IncBuf(), mBuf, and mWriteFlag.

Referenced by G4JpegCoder::WriteEOI(), and G4JpegCoder::WriteHeader().

00133 {
00134   if( mWriteFlag ){
00135         FullBit();
00136         *mBuf = dat;
00137         IncBuf();
00138         return;
00139   }
00140   throw( G4BufferError( "SetByte" ) );
00141 }

void G4OutBitStream::SetFewBits ( u_char  v,
int  numBits 
) [protected]

Definition at line 84 of file G4RTOutBitStream.cc.

References IncBuf(), mBitPos, and mBuf.

Referenced by FullBit(), and Set8Bits().

00085 {
00086   v &= BitFullMaskT[numBits-1];
00087   *mBuf |= v << (mBitPos + 1 - numBits);
00088   if( (mBitPos -= numBits) < 0 ){
00089         if( *mBuf == 0xff ){
00090           IncBuf();
00091           *mBuf = 0;
00092         }
00093         IncBuf();
00094         mBitPos = 7;
00095     }
00096 }

void G4OutBitStream::SetWord ( u_int  dat  ) 

Definition at line 144 of file G4RTOutBitStream.cc.

References FullBit(), IncBuf(), mBuf, and mWriteFlag.

Referenced by G4JpegCoder::WriteHeader().

00145 {
00146   if( mWriteFlag ){
00147         FullBit();
00148         *mBuf = (dat >> 8) & 0xff;
00149         IncBuf();
00150         *mBuf = dat & 0xff;
00151         IncBuf();
00152         return;
00153   }
00154   throw( G4BufferError( "SetWord" ) );
00155 }


Field Documentation

int G4OutBitStream::mBitPos [protected]

Definition at line 62 of file G4RTOutBitStream.hh.

Referenced by FullBit(), G4OutBitStream(), Set8Bits(), SetBits2Byte(), and SetFewBits().

u_char* G4OutBitStream::mBuf [protected]

Definition at line 60 of file G4RTOutBitStream.hh.

Referenced by CopyByte(), G4OutBitStream(), IncBuf(), SetBits2Byte(), SetByte(), SetFewBits(), SetWord(), and ~G4OutBitStream().

u_char* G4OutBitStream::mEndOfBuf [protected]

Definition at line 61 of file G4RTOutBitStream.hh.

Referenced by CopyByte(), G4OutBitStream(), and IncBuf().

u_char* G4OutBitStream::mHeadOfBuf [protected]

Definition at line 55 of file G4RTOutBitStream.hh.

Referenced by G4OutBitStream(), and GetStreamAddress().

int G4OutBitStream::mWriteFlag [protected]

Definition at line 63 of file G4RTOutBitStream.hh.

Referenced by G4OutBitStream(), IncBuf(), SetByte(), and SetWord().


The documentation for this class was generated from the following files:
Generated on Mon May 27 17:52:48 2013 for Geant4 by  doxygen 1.4.7