gwnavruntime/kernel/SF_BitSet.h Source File
Go to the documentation of this file.
17 #ifndef INC_KY_Kernel_BitSet_H
18 #define INC_KY_Kernel_BitSet_H
27 template <
class Allocator>
31 FixedBitSetBase(
const void* pheapAddr,
unsigned bitsCount)
32 : BitsCount(bitsCount)
34 unsigned dataLen = (BitsCount + 7)/8;
35 pData = (UByte*)Allocator::Alloc(pheapAddr, dataLen, __FILE__, __LINE__);
36 memset(pData, 0, dataLen);
38 FixedBitSetBase(
const FixedBitSetBase& other)
39 : BitsCount(other.BitsCount)
41 unsigned dataLen = (BitsCount + 7)/8;
42 pData = (UByte*)Allocator::Alloc(Memory::GetHeapByAddress(other.pData), dataLen, __FILE__, __LINE__);
43 memcpy(pData, other.pData, dataLen);
47 Allocator::Free(pData);
50 FixedBitSetBase& operator =(
const FixedBitSetBase& other)
54 Allocator::Free(pData);
56 BitsCount = other.BitsCount;
57 unsigned dataLen = (BitsCount + 7)/8;
58 pData = (UByte*)Allocator::Alloc(Memory::GetHeapByAddress(other.pData), dataLen, __FILE__, __LINE__);
59 memcpy(pData, other.pData, dataLen);
65 void Set(
unsigned bitIndex)
67 KY_ASSERT(bitIndex < BitsCount);
68 pData[bitIndex >> 3] |= (1 << (bitIndex & 7));
71 void Set(
unsigned bitIndex,
bool s)
73 (s) ? Set(bitIndex) : Clear(bitIndex);
76 void Clear(
unsigned bitIndex)
78 KY_ASSERT(bitIndex < BitsCount);
79 pData[bitIndex >> 3] &= ~(1 << (bitIndex & 7));
82 bool IsSet(
unsigned bitIndex)
const
84 KY_ASSERT(bitIndex < BitsCount);
85 return (pData[bitIndex >> 3] & (1 << (bitIndex & 7))) != 0;
87 bool operator[](
unsigned bitIndex)
const {
return IsSet(bitIndex); }
94 template<
int SID=Stat_Default_Mem>
95 class FixedBitSetLH :
public FixedBitSetBase<AllocatorLH<UByte, SID> >
98 typedef FixedBitSetBase<AllocatorLH<UByte, SID> > BaseType;
101 void* getThis() {
return this; }
103 FixedBitSetLH(
unsigned bitsCount) : BaseType(getThis(), bitsCount) {}
106 template<
int SID=Stat_Default_Mem>
107 class FixedBitSetDH :
public FixedBitSetBase<AllocatorDH<UByte, SID> >
110 typedef FixedBitSetBase<AllocatorDH<UByte, SID> > BaseType;
112 FixedBitSetDH(MemoryHeap* pheap,
unsigned bitsCount) : BaseType(pheap, bitsCount) {}
115 template<
int SID=Stat_Default_Mem>
116 class FixedBitSetGH :
public FixedBitSetBase<AllocatorGH<UByte, SID> >
119 typedef FixedBitSetBase<AllocatorGH<UByte, SID> > BaseType;
121 FixedBitSetGH(
unsigned bitsCount) : BaseType(Memory::GetGlobalHeap(), bitsCount) {}
126 #endif // INC_KY_Kernel_BitSet_H
Definition: gamekitcrowddispersion.h:20