Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4SurfBits Class Reference

#include <G4SurfBits.hh>

Public Member Functions

 G4SurfBits (unsigned int nbits=0)
 
 G4SurfBits (const G4SurfBits &)
 
G4SurfBitsoperator= (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
 

Public Attributes

unsigned char * fAllBits
 

Protected Member Functions

void ReserveBytes (unsigned int nbytes)
 

Protected Attributes

unsigned int fNBits
 
unsigned int fNBytes
 

Detailed Description

Definition at line 59 of file G4SurfBits.hh.

Constructor & Destructor Documentation

G4SurfBits::G4SurfBits ( unsigned int  nbits = 0)

Definition at line 43 of file G4SurfBits.cc.

43  : fNBits(nBits)
44 {
45  // G4SurfBits constructor. All bits set to 0
46 
47  if (fNBits <= 0) fNBits = 0;
48  fNBytes = fNBits ? ((fNBits-1)/8) + 1 : 1;
49  fAllBits = new unsigned char[fNBytes];
50  // this is redundant only with libNew
51  std::memset(fAllBits,0,fNBytes);
52 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
unsigned int fNBytes
Definition: G4SurfBits.hh:118
unsigned int fNBits
Definition: G4SurfBits.hh:117
G4SurfBits::G4SurfBits ( const G4SurfBits original)

Definition at line 55 of file G4SurfBits.cc.

55  : fNBits(original.fNBits),
56  fNBytes(original.fNBytes)
57 {
58  // G4SurfBits copy constructor
59 
60  fAllBits = new unsigned char[fNBytes];
61  std::memcpy(fAllBits,original.fAllBits,fNBytes);
62 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
unsigned int fNBytes
Definition: G4SurfBits.hh:118
unsigned int fNBits
Definition: G4SurfBits.hh:117
G4SurfBits::~G4SurfBits ( )

Definition at line 84 of file G4SurfBits.cc.

85 {
86  // G4SurfBits destructor
87 
88  delete [] fAllBits;
89 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113

Member Function Documentation

void G4SurfBits::Clear ( )

Definition at line 92 of file G4SurfBits.cc.

93 {
94  // Clear the value.
95 
96  delete [] fAllBits;
97  fAllBits = 0;
98  fNBits = 0;
99  fNBytes = 0;
100 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
unsigned int fNBytes
Definition: G4SurfBits.hh:118
unsigned int fNBits
Definition: G4SurfBits.hh:117

Here is the caller graph for this function:

void G4SurfBits::Compact ( )

Definition at line 103 of file G4SurfBits.cc.

104 {
105  // Reduce the storage used by the object to a minimun
106 
107  if (!fNBits || !fAllBits) return;
108  unsigned int needed;
109  for(needed=fNBytes-1;
110  needed > 0 && fAllBits[needed]==0; ) { needed--; };
111  needed++;
112 
113  if (needed!=fNBytes) {
114  unsigned char *old_location = fAllBits;
115  fAllBits = new unsigned char[needed];
116 
117  std::memcpy(fAllBits,old_location,needed);
118  delete [] old_location;
119 
120  fNBytes = needed;
121  fNBits = 8*fNBytes;
122  }
123 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
unsigned int fNBytes
Definition: G4SurfBits.hh:118
unsigned int fNBits
Definition: G4SurfBits.hh:117
void G4SurfBits::Get ( char *  array) const

Definition at line 186 of file G4SurfBits.cc.

187 {
188  // Copy all the byes.
189  std::memcpy(array, fAllBits, (fNBits+7)>>3);
190 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
unsigned int fNBits
Definition: G4SurfBits.hh:117

Here is the caller graph for this function:

void G4SurfBits::Get ( G4int array) const

Definition at line 204 of file G4SurfBits.cc.

205 {
206  // Get all the bytes.
207 
208  Get((char*)array);
209 }
void Get(char *array) const
Definition: G4SurfBits.cc:186

Here is the call graph for this function:

unsigned int G4SurfBits::GetNbits ( ) const
inline

Definition at line 101 of file G4SurfBits.hh.

101 { return fNBits; }
unsigned int fNBits
Definition: G4SurfBits.hh:117

Here is the caller graph for this function:

unsigned int G4SurfBits::GetNbytes ( ) const
inline

Definition at line 102 of file G4SurfBits.hh.

102 { return fNBytes; }
unsigned int fNBytes
Definition: G4SurfBits.hh:118

Here is the caller graph for this function:

G4SurfBits & G4SurfBits::operator= ( const G4SurfBits rhs)

Definition at line 65 of file G4SurfBits.cc.

66 {
67  // G4SurfBits assignment operator
68  if (this != &rhs) {
69  // TObject::operator=(rhs);
70  fNBits = rhs.fNBits;
71  fNBytes = rhs.fNBytes;
72  delete [] fAllBits;
73  if (fNBytes != 0) {
74  fAllBits = new unsigned char[fNBytes];
75  std::memcpy(fAllBits,rhs.fAllBits,fNBytes);
76  } else {
77  fAllBits = 0;
78  }
79  }
80  return *this;
81 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
unsigned int fNBytes
Definition: G4SurfBits.hh:118
unsigned int fNBits
Definition: G4SurfBits.hh:117
G4bool G4SurfBits::operator[] ( unsigned int  bitnumber) const
inline

Definition at line 166 of file G4SurfBits.hh.

167 {
168  return TestBitNumber(bitnumber);
169 }
G4bool TestBitNumber(unsigned int bitnumber) const
Definition: G4SurfBits.hh:148

Here is the call graph for this function:

void G4SurfBits::Output ( std::ostream &  os) const

Definition at line 126 of file G4SurfBits.cc.

127 {
128  // Print the value to the std::ostream
129  for(unsigned int i=0; i<fNBytes; ++i) {
130  unsigned char val = fAllBits[fNBytes - 1 - i];
131  for (unsigned int j=0; j<8; ++j) {
132  os << (G4bool)(val&0x80);
133  val <<= 1;
134  }
135  }
136 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
bool G4bool
Definition: G4Types.hh:79
unsigned int fNBytes
Definition: G4SurfBits.hh:118
void G4SurfBits::Print ( void  ) const

Definition at line 139 of file G4SurfBits.cc.

140 {
141  // Print the list of active bits
142  G4int count = 0;
143  for(unsigned int i=0; i<fNBytes; ++i) {
144  unsigned char val = fAllBits[i];
145  for (unsigned int j=0; j<8; ++j) {
146  if (val & 1) G4cout << " bit:" << count << " = 1" << G4endl;
147  count++;
148  val = val >> 1;
149  }
150  }
151 }
int G4int
Definition: G4Types.hh:78
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
G4GLOB_DLL std::ostream G4cout
unsigned int fNBytes
Definition: G4SurfBits.hh:118
#define G4endl
Definition: G4ios.hh:61
void G4SurfBits::ReserveBytes ( unsigned int  nbytes)
protected

Definition at line 160 of file G4SurfBits.cc.

161 {
162  // Reverse each bytes.
163 
164  if (nbytes > fNBytes) {
165  // do it in this order to remain exception-safe.
166  unsigned char *newBits=new unsigned char[nbytes];
167  delete[] fAllBits;
168  fNBytes=nbytes;
169  fAllBits=newBits;
170  }
171 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
unsigned int fNBytes
Definition: G4SurfBits.hh:118

Here is the caller graph for this function:

void G4SurfBits::ResetAllBits ( G4bool  value = false)

Definition at line 154 of file G4SurfBits.cc.

155 {
156  if (fAllBits) std::memset(fAllBits, value ? 0xFF : 0,fNBytes);
157 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
const XML_Char int const XML_Char * value
Definition: expat.h:331
unsigned int fNBytes
Definition: G4SurfBits.hh:118
void G4SurfBits::ResetBitNumber ( unsigned int  bitnumber)
inline

Definition at line 161 of file G4SurfBits.hh.

162 {
163  SetBitNumber(bitnumber,false);
164 }
void SetBitNumber(unsigned int bitnumber, G4bool value=true)
Definition: G4SurfBits.hh:123

Here is the call graph for this function:

void G4SurfBits::set ( unsigned int  nbits,
const char *  array 
)

Definition at line 174 of file G4SurfBits.cc.

175 {
176  // set all the bytes
177  unsigned int nbytes=(nBits+7)>>3;
178 
179  ReserveBytes(nbytes);
180 
181  fNBits=nBits;
182  std::memcpy(fAllBits, array, nbytes);
183 }
void ReserveBytes(unsigned int nbytes)
Definition: G4SurfBits.cc:160
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
unsigned int fNBits
Definition: G4SurfBits.hh:117

Here is the call graph for this function:

Here is the caller graph for this function:

void G4SurfBits::set ( unsigned int  nbits,
const G4int array 
)

Definition at line 196 of file G4SurfBits.cc.

197 {
198  // set all the bytes.
199 
200  set(nBits, (const char*)array);
201 }
void set(unsigned int nbits, const char *array)
Definition: G4SurfBits.cc:174

Here is the call graph for this function:

void G4SurfBits::SetBitNumber ( unsigned int  bitnumber,
G4bool  value = true 
)
inline

Definition at line 123 of file G4SurfBits.hh.

124 {
125  // set bit number 'bitnumber' to be value
126  if (bitnumber >= fNBits) {
127  unsigned int new_size = (bitnumber/8) + 1;
128  if (new_size > fNBytes) {
129  if (new_size < 100 * 1024 * 1024)
130  new_size *= 2;
131  unsigned char *old_location = fAllBits;
132  fAllBits = new unsigned char[new_size];
133  std::memcpy(fAllBits,old_location,fNBytes);
134  std::memset(fAllBits+fNBytes ,0, new_size-fNBytes);
135  fNBytes = new_size;
136  delete [] old_location;
137  }
138  fNBits = bitnumber+1;
139  }
140  unsigned int loc = bitnumber/8;
141  unsigned char bit = bitnumber%8;
142  if (value)
143  fAllBits[loc] |= (1<<bit);
144  else
145  fAllBits[loc] &= (0xFF ^ (1<<bit));
146 }
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
const XML_Char int const XML_Char * value
Definition: expat.h:331
unsigned int fNBytes
Definition: G4SurfBits.hh:118
unsigned int fNBits
Definition: G4SurfBits.hh:117

Here is the caller graph for this function:

G4bool G4SurfBits::TestBitNumber ( unsigned int  bitnumber) const
inline

Definition at line 148 of file G4SurfBits.hh.

149 {
150  // Return the current value of the bit
151 
152  if (bitnumber >= fNBits) return false;
153  unsigned int loc = bitnumber/8;
154  unsigned char value = fAllBits[loc];
155  unsigned char bit = bitnumber%8;
156  G4bool result = (value & (1<<bit)) != 0;
157  return result;
158  // short: return 0 != (fAllBits[bitnumber/8] & (1<< (bitnumber%8)));
159 }
G4double G4ParticleHPJENDLHEData::G4double result
unsigned char * fAllBits
Definition: G4SurfBits.hh:113
const XML_Char int const XML_Char * value
Definition: expat.h:331
bool G4bool
Definition: G4Types.hh:79
unsigned int fNBits
Definition: G4SurfBits.hh:117

Here is the caller graph for this function:

Member Data Documentation

unsigned char* G4SurfBits::fAllBits

Definition at line 113 of file G4SurfBits.hh.

unsigned int G4SurfBits::fNBits
protected

Definition at line 117 of file G4SurfBits.hh.

unsigned int G4SurfBits::fNBytes
protected

Definition at line 118 of file G4SurfBits.hh.


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