File indexing completed on 2026-09-28 09:19:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef _BRepGraphInc_BitFlags_HeaderFile
0015 #define _BRepGraphInc_BitFlags_HeaderFile
0016
0017 #include <NCollection_LinearVector.hxx>
0018
0019 #include <cstdint>
0020 #include <cstddef>
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 class BRepGraphInc_BitFlags
0044 {
0045 static constexpr uint32_t THE_BITS_PER_BLOCK = 64;
0046 using BlockType = uint64_t;
0047
0048 public:
0049
0050 BRepGraphInc_BitFlags() = default;
0051
0052
0053
0054 void Resize(const size_t theCount)
0055 {
0056 const size_t aBlockCount = (theCount + THE_BITS_PER_BLOCK - 1) / THE_BITS_PER_BLOCK;
0057 myBlocks.Resize(aBlockCount, 0);
0058 myBitCount = theCount;
0059 maskTailBits();
0060 }
0061
0062
0063 void Set(const uint32_t theIndex)
0064 {
0065 const size_t aBlock = theIndex / THE_BITS_PER_BLOCK;
0066 const uint32_t aBit = theIndex % THE_BITS_PER_BLOCK;
0067 myBlocks[aBlock] |= (BlockType(1) << aBit);
0068 }
0069
0070
0071 void Clear(const uint32_t theIndex)
0072 {
0073 const size_t aBlock = theIndex / THE_BITS_PER_BLOCK;
0074 const uint32_t aBit = theIndex % THE_BITS_PER_BLOCK;
0075 myBlocks[aBlock] &= ~(BlockType(1) << aBit);
0076 }
0077
0078
0079 [[nodiscard]] bool Test(const uint32_t theIndex) const
0080 {
0081 const size_t aBlock = theIndex / THE_BITS_PER_BLOCK;
0082 const uint32_t aBit = theIndex % THE_BITS_PER_BLOCK;
0083 return (myBlocks[aBlock] & (BlockType(1) << aBit)) != 0;
0084 }
0085
0086
0087 void SetAll()
0088 {
0089 for (size_t i = 0; i < myBlocks.Size(); ++i)
0090 {
0091 myBlocks[i] = ~BlockType(0);
0092 }
0093 maskTailBits();
0094 }
0095
0096
0097 void ClearAll()
0098 {
0099 for (size_t i = 0; i < myBlocks.Size(); ++i)
0100 {
0101 myBlocks[i] = 0;
0102 }
0103 }
0104
0105
0106 [[nodiscard]] bool HasAnyBitSet() const
0107 {
0108 for (size_t i = 0; i < myBlocks.Size(); ++i)
0109 {
0110 if (myBlocks[i] != 0)
0111 {
0112 return true;
0113 }
0114 }
0115 return false;
0116 }
0117
0118
0119 [[nodiscard]] size_t NbBlocks() const { return myBlocks.Size(); }
0120
0121
0122 [[nodiscard]] size_t BitCount() const { return myBitCount; }
0123
0124
0125 [[nodiscard]] bool IsValidIndex(const uint32_t theIndex) const { return theIndex < myBitCount; }
0126
0127
0128 [[nodiscard]] const BlockType* Blocks() const { return myBlocks.Data(); }
0129
0130 private:
0131 void maskTailBits()
0132 {
0133 const uint32_t aTailBits = static_cast<uint32_t>(myBitCount % THE_BITS_PER_BLOCK);
0134 if (aTailBits == 0u || myBlocks.Size() == 0)
0135 {
0136 return;
0137 }
0138
0139 const BlockType aTailMask = (BlockType(1) << aTailBits) - BlockType(1);
0140 myBlocks[myBlocks.Size() - 1] &= aTailMask;
0141 }
0142
0143 NCollection_LinearVector<BlockType> myBlocks;
0144 size_t myBitCount = 0;
0145 };
0146
0147 #endif