|
|
|||
File indexing completed on 2026-09-29 09:12:54
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 // G4SurfBits 0027 // 0028 // Class description: 0029 // 0030 // This class provides a simple container of bits, to be used for 0031 // optimization of tessellated surfaces (G4TessellatedSolid). 0032 // Each bit can be set and tested via the functions SetBitNumber and 0033 // TestBitNumber. 0034 // The default value of all bits is false. 0035 // The size of the container is automatically extended when a bit 0036 // number is either set or tested. To reduce the memory size of the 0037 // container use the Compact function, this will discard the memory 0038 // occupied by the upper bits that are 0. 0039 0040 // Author: Marek Gayer (CERN), 19.10.2012 - Created and adapted from original 0041 // implementation of Root/TBits class. 0042 // -------------------------------------------------------------------- 0043 #ifndef G4SURFBITS_HH 0044 #define G4SURFBITS_HH 0045 0046 #include <cstring> 0047 0048 #include "G4Types.hh" 0049 0050 /** 0051 * @brief G4SurfBits provides a simple container of bits, to be used for 0052 * optimization of tessellated surfaces. The size of the container is 0053 * automatically extended when a bit number is either set or tested. 0054 */ 0055 0056 class G4SurfBits 0057 { 0058 public: 0059 0060 /** 0061 * Constructor given the number of bits. 0062 * @param[in] nbits The number of bits. 0063 */ 0064 G4SurfBits(unsigned int nbits = 0); 0065 0066 /** 0067 * Destructor. Clears all allocated bits. 0068 */ 0069 ~G4SurfBits(); 0070 0071 /** 0072 * Copy constructor and assignment operator. 0073 */ 0074 G4SurfBits(const G4SurfBits&); 0075 G4SurfBits& operator=(const G4SurfBits&); 0076 0077 /** 0078 * Methods for bit manipulation. 0079 */ 0080 void ResetAllBits(G4bool value = false); // if value=1 set all bits to 1 0081 inline void ResetBitNumber(unsigned int bitnumber); 0082 inline void SetBitNumber(unsigned int bitnumber, G4bool value = true); 0083 inline G4bool TestBitNumber(unsigned int bitnumber) const; 0084 0085 /** 0086 * Accessor operator. 0087 */ 0088 inline G4bool operator[](unsigned int bitnumber) const; 0089 0090 /** 0091 * Optimized setters. Each of these will replace the contents of the 0092 * receiver with the bitvector in the parameter array. The number of bits 0093 * is changed to 'nbits'. If nbits is smaller than fNBits, the receiver 0094 * will NOT be compacted. 0095 */ 0096 void set(unsigned int nbits, const char* array); 0097 void set(unsigned int nbits, const G4int* array); 0098 0099 /** 0100 * Optimized getters. Each of these will replace the contents of the 0101 * parameter array with the bits in the receiver. The parameter array must 0102 * be large enough to hold all of the bits in the receiver. 0103 * Note on semantics: any bits in the parameter array that go beyond the 0104 * number of the bits in the receiver will have an unspecified value. For 0105 * example, if calling Get(Int*) with an array of one integer and the 0106 * G4SurfBits object has less than 32 bits, then the remaining bits in the 0107 * integer will have an unspecified value. 0108 */ 0109 void Get(char* array) const; 0110 void Get(G4int* array) const; 0111 0112 /** 0113 * Utilities to clear or reduce the space used. 0114 */ 0115 void Clear(); 0116 void Compact(); // Reduce the space used. 0117 0118 /** 0119 * Accessors. 0120 */ 0121 inline unsigned int GetNbits() const { return fNBits; } 0122 inline unsigned int GetNbytes() const { return fNBytes; } 0123 0124 /** 0125 * Logging functions. 0126 */ 0127 void Print() const; // to show the list of active bits 0128 void Output(std::ostream &) const; 0129 0130 public: 0131 0132 unsigned char* fAllBits = nullptr; // [fNBytes] array of UChars 0133 0134 private: 0135 0136 void ReserveBytes(unsigned int nbytes); 0137 0138 private: 0139 0140 unsigned int fNBits; // Highest bit set + 1 0141 unsigned int fNBytes; // Number of UChars in fAllBits 0142 }; 0143 0144 // inline functions... 0145 0146 #include "G4SurfBits.icc" 0147 0148 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|