#include <G4SurfBits.hh>
Public Member Functions | |
G4SurfBits (unsigned int nbits=0) | |
G4SurfBits (const G4SurfBits &) | |
G4SurfBits & | operator= (const G4SurfBits &) |
~G4SurfBits () | |
void | ResetAllBits (G4bool value=false) |
void | ResetBitNumber (unsigned int bitnumber) |
void | SetBitNumber (unsigned int bitnumber, G4bool value=true) |
G4bool | TestBitNumber (unsigned int bitnumber) const |
G4bool | operator[] (unsigned int bitnumber) const |
void | set (unsigned int nbits, const char *array) |
void | set (unsigned int nbits, const G4int *array) |
void | Get (char *array) const |
void | Get (G4int *array) const |
void | Clear () |
void | Compact () |
unsigned int | GetNbits () const |
unsigned int | GetNbytes () const |
void | Print () const |
void | Output (std::ostream &) const |
Data Fields | |
unsigned char * | fAllBits |
Protected Member Functions | |
void | ReserveBytes (unsigned int nbytes) |
Protected Attributes | |
unsigned int | fNBits |
unsigned int | fNBytes |
Definition at line 59 of file G4SurfBits.hh.
G4SurfBits::G4SurfBits | ( | unsigned int | nbits = 0 |
) |
Definition at line 43 of file G4SurfBits.cc.
References fAllBits, fNBits, and fNBytes.
00043 : fNBits(nBits) 00044 { 00045 // G4SurfBits constructor. All bits set to 0 00046 00047 if (fNBits <= 0) fNBits = 0; 00048 fNBytes = fNBits ? ((fNBits-1)/8) + 1 : 1; 00049 fAllBits = new unsigned char[fNBytes]; 00050 // this is redundant only with libNew 00051 std::memset(fAllBits,0,fNBytes); 00052 }
G4SurfBits::G4SurfBits | ( | const G4SurfBits & | ) |
Definition at line 55 of file G4SurfBits.cc.
References fAllBits, and fNBytes.
00055 : fNBits(original.fNBits), 00056 fNBytes(original.fNBytes) 00057 { 00058 // G4SurfBits copy constructor 00059 00060 fAllBits = new unsigned char[fNBytes]; 00061 std::memcpy(fAllBits,original.fAllBits,fNBytes); 00062 }
G4SurfBits::~G4SurfBits | ( | ) |
Definition at line 84 of file G4SurfBits.cc.
References fAllBits.
00085 { 00086 // G4SurfBits destructor 00087 00088 delete [] fAllBits; 00089 }
void G4SurfBits::Clear | ( | ) |
Definition at line 92 of file G4SurfBits.cc.
References fAllBits, fNBits, and fNBytes.
Referenced by G4SurfaceVoxelizer::Voxelize().
00093 { 00094 // Clear the value. 00095 00096 delete [] fAllBits; 00097 fAllBits = 0; 00098 fNBits = 0; 00099 fNBytes = 0; 00100 }
void G4SurfBits::Compact | ( | ) |
Definition at line 103 of file G4SurfBits.cc.
References fAllBits, fNBits, and fNBytes.
00104 { 00105 // Reduce the storage used by the object to a minimun 00106 00107 if (!fNBits || !fAllBits) return; 00108 unsigned int needed; 00109 for(needed=fNBytes-1; 00110 needed > 0 && fAllBits[needed]==0; ) { needed--; }; 00111 needed++; 00112 00113 if (needed!=fNBytes) { 00114 unsigned char *old_location = fAllBits; 00115 fAllBits = new unsigned char[needed]; 00116 00117 std::memcpy(fAllBits,old_location,needed); 00118 delete [] old_location; 00119 00120 fNBytes = needed; 00121 fNBits = 8*fNBytes; 00122 } 00123 }
void G4SurfBits::Get | ( | G4int * | array | ) | const |
Definition at line 204 of file G4SurfBits.cc.
References Get().
00205 { 00206 // Get all the bytes. 00207 00208 Get((char*)array); 00209 }
void G4SurfBits::Get | ( | char * | array | ) | const |
unsigned int G4SurfBits::GetNbits | ( | ) | const [inline] |
Definition at line 101 of file G4SurfBits.hh.
References fNBits.
Referenced by G4TessellatedSolid::SafetyFromOutside().
00101 { return fNBits; }
unsigned int G4SurfBits::GetNbytes | ( | ) | const [inline] |
Definition at line 102 of file G4SurfBits.hh.
References fNBytes.
Referenced by G4TessellatedSolid::AllocatedMemory(), and G4SurfaceVoxelizer::AllocatedMemory().
00102 { return fNBytes; }
G4SurfBits & G4SurfBits::operator= | ( | const G4SurfBits & | ) |
Definition at line 65 of file G4SurfBits.cc.
References fAllBits, fNBits, and fNBytes.
00066 { 00067 // G4SurfBits assignment operator 00068 if (this != &rhs) { 00069 // TObject::operator=(rhs); 00070 fNBits = rhs.fNBits; 00071 fNBytes = rhs.fNBytes; 00072 delete [] fAllBits; 00073 if (fNBytes != 0) { 00074 fAllBits = new unsigned char[fNBytes]; 00075 std::memcpy(fAllBits,rhs.fAllBits,fNBytes); 00076 } else { 00077 fAllBits = 0; 00078 } 00079 } 00080 return *this; 00081 }
G4bool G4SurfBits::operator[] | ( | unsigned int | bitnumber | ) | const [inline] |
Definition at line 166 of file G4SurfBits.hh.
References TestBitNumber().
00167 { 00168 return TestBitNumber(bitnumber); 00169 }
void G4SurfBits::Output | ( | std::ostream & | ) | const |
Definition at line 126 of file G4SurfBits.cc.
References fAllBits, and fNBytes.
00127 { 00128 // Print the value to the std::ostream 00129 for(unsigned int i=0; i<fNBytes; ++i) { 00130 unsigned char val = fAllBits[fNBytes - 1 - i]; 00131 for (unsigned int j=0; j<8; ++j) { 00132 os << (G4bool)(val&0x80); 00133 val <<= 1; 00134 } 00135 } 00136 }
void G4SurfBits::Print | ( | ) | const |
Definition at line 139 of file G4SurfBits.cc.
References fAllBits, fNBytes, G4cout, and G4endl.
00140 { 00141 // Print the list of active bits 00142 G4int count = 0; 00143 for(unsigned int i=0; i<fNBytes; ++i) { 00144 unsigned char val = fAllBits[i]; 00145 for (unsigned int j=0; j<8; ++j) { 00146 if (val & 1) G4cout << " bit:" << count << " = 1" << G4endl; 00147 count++; 00148 val = val >> 1; 00149 } 00150 } 00151 }
void G4SurfBits::ReserveBytes | ( | unsigned int | nbytes | ) | [protected] |
Definition at line 160 of file G4SurfBits.cc.
References fAllBits, and fNBytes.
Referenced by set().
00161 { 00162 // Reverse each bytes. 00163 00164 if (nbytes > fNBytes) { 00165 // do it in this order to remain exception-safe. 00166 unsigned char *newBits=new unsigned char[nbytes]; 00167 delete[] fAllBits; 00168 fNBytes=nbytes; 00169 fAllBits=newBits; 00170 } 00171 }
void G4SurfBits::ResetAllBits | ( | G4bool | value = false |
) |
void G4SurfBits::ResetBitNumber | ( | unsigned int | bitnumber | ) | [inline] |
Definition at line 161 of file G4SurfBits.hh.
References SetBitNumber().
00162 { 00163 SetBitNumber(bitnumber,false); 00164 }
void G4SurfBits::set | ( | unsigned int | nbits, | |
const G4int * | array | |||
) |
Definition at line 196 of file G4SurfBits.cc.
References set().
00197 { 00198 // set all the bytes. 00199 00200 set(nBits, (const char*)array); 00201 }
void G4SurfBits::set | ( | unsigned int | nbits, | |
const char * | array | |||
) |
Definition at line 174 of file G4SurfBits.cc.
References fAllBits, fNBits, and ReserveBytes().
Referenced by G4SurfaceVoxelizer::DisplayListNodes(), and set().
00175 { 00176 // set all the bytes 00177 unsigned int nbytes=(nBits+7)>>3; 00178 00179 ReserveBytes(nbytes); 00180 00181 fNBits=nBits; 00182 std::memcpy(fAllBits, array, nbytes); 00183 }
void G4SurfBits::SetBitNumber | ( | unsigned int | bitnumber, | |
G4bool | value = true | |||
) | [inline] |
Definition at line 123 of file G4SurfBits.hh.
References fAllBits, fNBits, and fNBytes.
Referenced by ResetBitNumber().
00124 { 00125 // set bit number 'bitnumber' to be value 00126 if (bitnumber >= fNBits) { 00127 unsigned int new_size = (bitnumber/8) + 1; 00128 if (new_size > fNBytes) { 00129 if (new_size < 100 * 1024 * 1024) 00130 new_size *= 2; 00131 unsigned char *old_location = fAllBits; 00132 fAllBits = new unsigned char[new_size]; 00133 std::memcpy(fAllBits,old_location,fNBytes); 00134 std::memset(fAllBits+fNBytes ,0, new_size-fNBytes); 00135 fNBytes = new_size; 00136 delete [] old_location; 00137 } 00138 fNBits = bitnumber+1; 00139 } 00140 unsigned int loc = bitnumber/8; 00141 unsigned char bit = bitnumber%8; 00142 if (value) 00143 fAllBits[loc] |= (1<<bit); 00144 else 00145 fAllBits[loc] &= (0xFF ^ (1<<bit)); 00146 }
G4bool G4SurfBits::TestBitNumber | ( | unsigned int | bitnumber | ) | const [inline] |
Definition at line 148 of file G4SurfBits.hh.
References fAllBits, and fNBits.
Referenced by operator[]().
00149 { 00150 // Return the current value of the bit 00151 00152 if (bitnumber >= fNBits) return false; 00153 unsigned int loc = bitnumber/8; 00154 unsigned char value = fAllBits[loc]; 00155 unsigned char bit = bitnumber%8; 00156 G4bool result = (value & (1<<bit)) != 0; 00157 return result; 00158 // short: return 0 != (fAllBits[bitnumber/8] & (1<< (bitnumber%8))); 00159 }
unsigned char* G4SurfBits::fAllBits |
Definition at line 113 of file G4SurfBits.hh.
Referenced by Clear(), Compact(), G4SurfBits(), Get(), G4SurfaceVoxelizer::GetCandidatesVoxelArray(), operator=(), Output(), Print(), ReserveBytes(), ResetAllBits(), set(), SetBitNumber(), TestBitNumber(), and ~G4SurfBits().
unsigned int G4SurfBits::fNBits [protected] |
Definition at line 117 of file G4SurfBits.hh.
Referenced by Clear(), Compact(), G4SurfBits(), Get(), GetNbits(), operator=(), set(), SetBitNumber(), and TestBitNumber().
unsigned int G4SurfBits::fNBytes [protected] |
Definition at line 118 of file G4SurfBits.hh.
Referenced by Clear(), Compact(), G4SurfBits(), GetNbytes(), operator=(), Output(), Print(), ReserveBytes(), ResetAllBits(), and SetBitNumber().