Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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 43 of file G4RTOutBitStream.hh.

Constructor & Destructor Documentation

◆ G4OutBitStream()

G4OutBitStream::G4OutBitStream ( int size)

Definition at line 37 of file G4RTOutBitStream.cc.

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

◆ ~G4OutBitStream()

G4OutBitStream::~G4OutBitStream ( )

Definition at line 54 of file G4RTOutBitStream.cc.

55{
56 delete mBuf;
57}

Member Function Documentation

◆ CopyByte()

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

Definition at line 157 of file G4RTOutBitStream.cc.

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

Referenced by G4JpegCoder::WriteHeader().

◆ FullBit()

void G4OutBitStream::FullBit ( void )
protected

Definition at line 124 of file G4RTOutBitStream.cc.

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

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

◆ GetStreamAddress()

u_char * G4OutBitStream::GetStreamAddress ( void )
inline

Definition at line 53 of file G4RTOutBitStream.hh.

53{return mHeadOfBuf;};

Referenced by G4JpegCoder::GetJpegData().

◆ GetStreamSize()

int G4OutBitStream::GetStreamSize ( void )
inline

Definition at line 54 of file G4RTOutBitStream.hh.

54{return int(mBuf - mHeadOfBuf);};

Referenced by G4JpegCoder::GetJpegData().

◆ IncBuf()

void G4OutBitStream::IncBuf ( void )
protected

Definition at line 60 of file G4RTOutBitStream.cc.

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

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

◆ Set8Bits()

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

Definition at line 114 of file G4RTOutBitStream.cc.

115{
116 if( mBitPos + 1 >= numBits )
117 SetFewBits( (u_char)v, numBits );
118 else
119 SetBits2Byte( (u_char)v, numBits );
120}
void SetBits2Byte(u_char v, int numBits)

Referenced by SetBits().

◆ SetBits()

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

Definition at line 69 of file G4RTOutBitStream.cc.

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

Referenced by G4JpegCoder::CodeHuffman().

◆ SetBits2Byte()

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

Definition at line 98 of file G4RTOutBitStream.cc.

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

Referenced by Set8Bits().

◆ SetByte()

void G4OutBitStream::SetByte ( u_char dat)

Definition at line 131 of file G4RTOutBitStream.cc.

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

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

◆ SetFewBits()

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

Definition at line 83 of file G4RTOutBitStream.cc.

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

Referenced by FullBit(), and Set8Bits().

◆ SetWord()

void G4OutBitStream::SetWord ( u_int dat)

Definition at line 143 of file G4RTOutBitStream.cc.

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

Referenced by G4JpegCoder::WriteHeader().

Member Data Documentation

◆ mBitPos

int G4OutBitStream::mBitPos
protected

Definition at line 61 of file G4RTOutBitStream.hh.

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

◆ mBuf

u_char* G4OutBitStream::mBuf
protected

◆ mEndOfBuf

u_char* G4OutBitStream::mEndOfBuf
protected

Definition at line 60 of file G4RTOutBitStream.hh.

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

◆ mHeadOfBuf

u_char* G4OutBitStream::mHeadOfBuf
protected

Definition at line 58 of file G4RTOutBitStream.hh.

Referenced by G4OutBitStream(), GetStreamAddress(), and GetStreamSize().

◆ mWriteFlag

int G4OutBitStream::mWriteFlag
protected

Definition at line 62 of file G4RTOutBitStream.hh.

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


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