Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4SurfBits.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4SurfBits
27//
28// Class description:
29//
30// This class provides a simple container of bits, to be used for
31// optimization of tessellated surfaces (G4TessellatedSolid).
32// Each bit can be set and tested via the functions SetBitNumber and
33// TestBitNumber.
34// The default value of all bits is false.
35// The size of the container is automatically extended when a bit
36// number is either set or tested. To reduce the memory size of the
37// container use the Compact function, this will discard the memory
38// occupied by the upper bits that are 0.
39
40// Author: Marek Gayer (CERN), 19.10.2012 - Created and adapted from original
41// implementation of Root/TBits class.
42// --------------------------------------------------------------------
43#ifndef G4SURFBITS_HH
44#define G4SURFBITS_HH
45
46#include <cstring>
47
48#include "G4Types.hh"
49
50/**
51 * @brief G4SurfBits provides a simple container of bits, to be used for
52 * optimization of tessellated surfaces. The size of the container is
53 * automatically extended when a bit number is either set or tested.
54 */
55
57{
58 public:
59
60 /**
61 * Constructor given the number of bits.
62 * @param[in] nbits The number of bits.
63 */
64 G4SurfBits(unsigned int nbits = 0);
65
66 /**
67 * Destructor. Clears all allocated bits.
68 */
70
71 /**
72 * Copy constructor and assignment operator.
73 */
74 G4SurfBits(const G4SurfBits&);
76
77 /**
78 * Methods for bit manipulation.
79 */
80 void ResetAllBits(G4bool value = false); // if value=1 set all bits to 1
81 inline void ResetBitNumber(unsigned int bitnumber);
82 inline void SetBitNumber(unsigned int bitnumber, G4bool value = true);
83 inline G4bool TestBitNumber(unsigned int bitnumber) const;
84
85 /**
86 * Accessor operator.
87 */
88 inline G4bool operator[](unsigned int bitnumber) const;
89
90 /**
91 * Optimized setters. Each of these will replace the contents of the
92 * receiver with the bitvector in the parameter array. The number of bits
93 * is changed to 'nbits'. If nbits is smaller than fNBits, the receiver
94 * will NOT be compacted.
95 */
96 void set(unsigned int nbits, const char* array);
97 void set(unsigned int nbits, const G4int* array);
98
99 /**
100 * Optimized getters. Each of these will replace the contents of the
101 * parameter array with the bits in the receiver. The parameter array must
102 * be large enough to hold all of the bits in the receiver.
103 * Note on semantics: any bits in the parameter array that go beyond the
104 * number of the bits in the receiver will have an unspecified value. For
105 * example, if calling Get(Int*) with an array of one integer and the
106 * G4SurfBits object has less than 32 bits, then the remaining bits in the
107 * integer will have an unspecified value.
108 */
109 void Get(char* array) const;
110 void Get(G4int* array) const;
111
112 /**
113 * Utilities to clear or reduce the space used.
114 */
115 void Clear();
116 void Compact(); // Reduce the space used.
117
118 /**
119 * Accessors.
120 */
121 inline unsigned int GetNbits() const { return fNBits; }
122 inline unsigned int GetNbytes() const { return fNBytes; }
123
124 /**
125 * Logging functions.
126 */
127 void Print() const; // to show the list of active bits
128 void Output(std::ostream &) const;
129
130 public:
131
132 unsigned char* fAllBits = nullptr; // [fNBytes] array of UChars
133
134 private:
135
136 void ReserveBytes(unsigned int nbytes);
137
138 private:
139
140 unsigned int fNBits; // Highest bit set + 1
141 unsigned int fNBytes; // Number of UChars in fAllBits
142};
143
144// inline functions...
145
146#include "G4SurfBits.icc"
147
148#endif
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
unsigned int GetNbits() const
void Output(std::ostream &) const
G4SurfBits & operator=(const G4SurfBits &)
Definition G4SurfBits.cc:57
unsigned int GetNbytes() const
unsigned char * fAllBits
void ResetAllBits(G4bool value=false)
void Get(char *array) const
void Clear()
Definition G4SurfBits.cc:88
void ResetBitNumber(unsigned int bitnumber)
void Compact()
Definition G4SurfBits.cc:99
void SetBitNumber(unsigned int bitnumber, G4bool value=true)
void set(unsigned int nbits, const char *array)
G4bool operator[](unsigned int bitnumber) const
G4SurfBits(unsigned int nbits=0)
Definition G4SurfBits.cc:35
void Print() const
G4bool TestBitNumber(unsigned int bitnumber) const