Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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.

39 {
40  if(size < 1)
41  throw( G4MemoryError( size, "G4OutBitStream" ) );
42 
43  mHeadOfBuf = mBuf = new u_char[size];
44  if( mHeadOfBuf == 0 )
45  throw( G4MemoryError( size, "G4OutBitStream" ) );
46 
47  mEndOfBuf = mBuf + size;
48 
49  memset( mHeadOfBuf, 0, size );
50 
51  mBitPos = 7;
52  mWriteFlag = 1;
53 }
unsigned char u_char
Definition: G4RTJpeg.hh:40
G4OutBitStream::~G4OutBitStream ( )

Definition at line 55 of file G4RTOutBitStream.cc.

56 {
57  delete mBuf;
58 }

Member Function Documentation

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

Definition at line 158 of file G4RTOutBitStream.cc.

159 {
160  if( mBuf+n < mEndOfBuf ){
161  FullBit();
162  memcpy( mBuf, src, n );
163  mBuf += n;
164  return;
165  }
166  throw( G4BufferError( "CopyByte" ) );
167 }

Here is the call graph for this function:

Here is the caller graph for this function:

void G4OutBitStream::FullBit ( void  )
protected

Definition at line 125 of file G4RTOutBitStream.cc.

126 {
127  if( mBitPos != 7 )
128  SetFewBits( BitFullMaskT[mBitPos], mBitPos+1 );
129 }
void SetFewBits(u_char v, int numBits)
static const u_char BitFullMaskT[8]

Here is the call graph for this function:

Here is the caller graph for this function:

u_char* G4OutBitStream::GetStreamAddress ( void  )
inline

Definition at line 54 of file G4RTOutBitStream.hh.

54 {return mHeadOfBuf;};

Here is the caller graph for this function:

int G4OutBitStream::GetStreamSize ( void  )
inline

Definition at line 55 of file G4RTOutBitStream.hh.

55 {return mBuf - mHeadOfBuf;};

Here is the caller graph for this function:

void G4OutBitStream::IncBuf ( void  )
protected

Definition at line 61 of file G4RTOutBitStream.cc.

62 {
63  if( ++mBuf >= mEndOfBuf )
64  mWriteFlag = 0;
65 }

Here is the caller graph for this function:

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

Definition at line 115 of file G4RTOutBitStream.cc.

116 {
117  if( mBitPos + 1 >= numBits )
118  SetFewBits( (u_char)v, numBits );
119  else
120  SetBits2Byte( (u_char)v, numBits );
121 }
void SetFewBits(u_char v, int numBits)
unsigned char u_char
Definition: G4RTJpeg.hh:40
void SetBits2Byte(u_char v, int numBits)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 70 of file G4RTOutBitStream.cc.

71 {
72  if( numBits == 0 )
73  return;
74  if( numBits > 16 )
75  throw( G4BufferError( "SetBits:Max Bit Over" ) );
76  if( numBits > 8 ){
77  Set8Bits( u_char(v>>8), numBits-8 );
78  numBits = 8;
79  }
80  Set8Bits( u_char(v), numBits );
81 }
unsigned char u_char
Definition: G4RTJpeg.hh:40
void Set8Bits(u_char v, int numBits)

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 99 of file G4RTOutBitStream.cc.

100 {
101  v &= BitFullMaskT[numBits-1];
102  int nextBits = numBits - (mBitPos + 1);
103  *mBuf |= ( v >> nextBits ) & BitFullMaskT[mBitPos];
104  if( *mBuf == 0xff ){
105  IncBuf();
106  *mBuf = 0;
107  }
108  IncBuf();
109 
110  *mBuf = v << (8 - nextBits);
111  mBitPos = 7 - nextBits;
112 }
static const u_char BitFullMaskT[8]

Here is the call graph for this function:

Here is the caller graph for this function:

void G4OutBitStream::SetByte ( u_char  dat)

Definition at line 132 of file G4RTOutBitStream.cc.

133 {
134  if( mWriteFlag ){
135  FullBit();
136  *mBuf = dat;
137  IncBuf();
138  return;
139  }
140  throw( G4BufferError( "SetByte" ) );
141 }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 84 of file G4RTOutBitStream.cc.

85 {
86  v &= BitFullMaskT[numBits-1];
87  *mBuf |= v << (mBitPos + 1 - numBits);
88  if( (mBitPos -= numBits) < 0 ){
89  if( *mBuf == 0xff ){
90  IncBuf();
91  *mBuf = 0;
92  }
93  IncBuf();
94  mBitPos = 7;
95  }
96 }
static const u_char BitFullMaskT[8]

Here is the call graph for this function:

Here is the caller graph for this function:

void G4OutBitStream::SetWord ( u_int  dat)

Definition at line 144 of file G4RTOutBitStream.cc.

145 {
146  if( mWriteFlag ){
147  FullBit();
148  *mBuf = (dat >> 8) & 0xff;
149  IncBuf();
150  *mBuf = dat & 0xff;
151  IncBuf();
152  return;
153  }
154  throw( G4BufferError( "SetWord" ) );
155 }

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

int G4OutBitStream::mBitPos
protected

Definition at line 62 of file G4RTOutBitStream.hh.

u_char* G4OutBitStream::mBuf
protected

Definition at line 60 of file G4RTOutBitStream.hh.

u_char* G4OutBitStream::mEndOfBuf
protected

Definition at line 61 of file G4RTOutBitStream.hh.

u_char* G4OutBitStream::mHeadOfBuf
protected

Definition at line 55 of file G4RTOutBitStream.hh.

int G4OutBitStream::mWriteFlag
protected

Definition at line 63 of file G4RTOutBitStream.hh.


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