OpenBarnyard
 
Loading...
Searching...
No Matches
TBitField.h
Go to the documentation of this file.
1#pragma once
2#include "Toshi/Defines.h"
3#include "Toshi/T2Iterator.h"
4
6
7template <TUINT NUM_BITS>
9{
10public:
12 static constexpr TUINT MIN_NUM_BITS = 8 * sizeof( ValueType );
13 static constexpr TUINT BIT_SUBNUM_MASK = MIN_NUM_BITS - 1;
14
15public:
17 {
18 T2_FOREACH_ARRAY( m_Values, i )
19 {
20 m_Values[ i ] = 0;
21 }
22 }
23
24 void Set( TINT a_iBitNum, TBOOL a_bSet )
25 {
26 TASSERT( a_iBitNum >= 0 );
27 TASSERT( a_iBitNum < NUM_BITS );
28
29 TUINT uiBit = 1 << ( a_iBitNum % NUM_BITS );
30
31 if ( a_bSet ) m_Values[ a_iBitNum / MIN_NUM_BITS ] |= uiBit;
32 else
33 m_Values[ a_iBitNum / MIN_NUM_BITS ] &= ~uiBit;
34 }
35
36 TBOOL IsSet( TINT a_iBitNum ) const
37 {
38 TASSERT( a_iBitNum >= 0 );
39 TASSERT( a_iBitNum < NUM_BITS );
40
41 return ( m_Values[ a_iBitNum / MIN_NUM_BITS ] & ( 1 << ( a_iBitNum % NUM_BITS ) ) ) != 0;
42 }
43
44private:
45 ValueType m_Values[ ( NUM_BITS + BIT_SUBNUM_MASK ) / MIN_NUM_BITS ];
46};
47
#define TASSERT(X,...)
Definition Defines.h:138
#define TOSHI_NAMESPACE_START
Definition Defines.h:47
#define TOSHI_NAMESPACE_END
Definition Defines.h:50
#define T2_FOREACH_ARRAY(arrName, iteratorName)
Definition T2Iterator.h:10
#define BIT_SUBNUM_MASK
Definition TBitArray.cpp:13
#define MIN_NUM_BITS
Definition TBitArray.cpp:12
unsigned int TUINT
Definition Typedefs.h:8
uint32_t TUINT32
Definition Typedefs.h:13
int TINT
Definition Typedefs.h:7
bool TBOOL
Definition Typedefs.h:6
void Set(TINT a_iBitNum, TBOOL a_bSet)
Definition TBitField.h:24
static constexpr TUINT BIT_SUBNUM_MASK
Definition TBitField.h:13
TUINT32 ValueType
Definition TBitField.h:11
static constexpr TUINT MIN_NUM_BITS
Definition TBitField.h:12
TBOOL IsSet(TINT a_iBitNum) const
Definition TBitField.h:36