Nazara Engine
0.4
A fast, complete, cross-platform API designed for game development
|
Core class that represents a set of bits. More...
Public Types | |
using | PointerSequence = std::pair< const void *, std::size_t > |
Public Member Functions | |
Bitset () | |
Constructs a Bitset object by default. | |
Bitset (std::size_t bitCount, bool val) | |
Constructs a Bitset object of bitCount bits to value val. More... | |
Bitset (const char *bits) | |
Constructs a Bitset object from the contents initialized with a copy of the null-terminated character string pointed to by bits. More... | |
Bitset (const char *bits, std::size_t bitCount) | |
Constructs a Bitset object from the contents initialized with a copy of the character string pointed to by bits takings the bitCount first characters. More... | |
Bitset (const Bitset &bitset)=default | |
Bitset (const String &bits) | |
Constructs a Bitset object from a Nz::String. More... | |
template<typename T > | |
Bitset (T value) | |
Constructs a Bitset copying an unsigned integral number. More... | |
Bitset (Bitset &&bitset) noexcept=default | |
template<typename T > | |
void | AppendBits (T bits, std::size_t bitCount) |
Appends bits to the bitset. More... | |
void | Clear () noexcept |
Clears the content of the bitset. More... | |
std::size_t | Count () const |
Counts the number of bits set to 1. More... | |
void | Flip () |
Flips each bit of the bitset. More... | |
std::size_t | FindFirst () const |
Finds the first bit set to one in the bitset. More... | |
std::size_t | FindNext (std::size_t bit) const |
Finds the next enabled in the bitset. More... | |
Block | GetBlock (std::size_t i) const |
Gets the ith block. More... | |
std::size_t | GetBlockCount () const |
Gets the number of blocks. More... | |
std::size_t | GetCapacity () const |
Gets the capacity of the bitset. More... | |
std::size_t | GetSize () const |
Gets the number of bits. More... | |
PointerSequence | Read (const void *ptr, std::size_t bitCount) |
Read a byte sequence into a bitset. More... | |
PointerSequence | Read (const PointerSequence &sequence, std::size_t bitCount) |
Read a byte sequence into a bitset. More... | |
void | PerformsAND (const Bitset &a, const Bitset &b) |
Performs the "AND" operator between two bitsets. More... | |
void | PerformsNOT (const Bitset &a) |
Performs the "NOT" operator of the bitset. More... | |
void | PerformsOR (const Bitset &a, const Bitset &b) |
Performs the "OR" operator between two bitsets. More... | |
void | PerformsXOR (const Bitset &a, const Bitset &b) |
Performs the "XOR" operator between two bitsets. More... | |
bool | Intersects (const Bitset &bitset) const |
Checks if bitsets have one block in common. More... | |
void | Reserve (std::size_t bitCount) |
Reserves enough blocks to contain bitCount bits. More... | |
void | Resize (std::size_t bitCount, bool defaultVal=false) |
Resizes the bitset to the size of bitCount. More... | |
void | Reset () |
Resets the bitset to zero bits. | |
void | Reset (std::size_t bit) |
Resets the bit at the index. More... | |
void | Reverse () |
Reverse the order of bits in a bitset. More... | |
void | Set (bool val=true) |
Sets the bitset to val. More... | |
void | Set (std::size_t bit, bool val=true) |
Sets the bit at the index. More... | |
void | SetBlock (std::size_t i, Block block) |
Set the ith block. More... | |
void | ShiftLeft (std::size_t pos) |
Shift all the bits toward the left. More... | |
void | ShiftRight (std::size_t pos) |
Shift all the bits toward the right. More... | |
void | Swap (Bitset &bitset) |
Swaps the two bitsets. More... | |
bool | Test (std::size_t bit) const |
Tests the ith bit. More... | |
bool | TestAll () const |
Tests each block. More... | |
bool | TestAny () const |
Tests if one bit is set. More... | |
bool | TestNone () const |
Tests if one bit is not set. More... | |
template<typename T > | |
T | To () const |
Converts the bitset to template type. More... | |
String | ToString () const |
Gives a string representation. More... | |
void | UnboundedReset (std::size_t bit) |
Resets the bit at the index. More... | |
void | UnboundedSet (std::size_t bit, bool val=true) |
Sets the bit at the index. More... | |
bool | UnboundedTest (std::size_t bit) const |
Tests the ith bit. More... | |
Bit | operator[] (std::size_t index) |
Gets the ith bit. More... | |
bool | operator[] (std::size_t index) const |
Gets the ith bit. More... | |
Bitset | operator~ () const |
Negates the bitset. More... | |
Bitset & | operator= (const Bitset &bitset)=default |
Bitset & | operator= (const String &bits) |
Sets this bitset from a Nz::String. More... | |
template<typename T > | |
Bitset & | operator= (T value) |
Bitset & | operator= (Bitset &&bitset) noexcept=default |
Bitset | operator<< (std::size_t pos) const |
Shift all the bits toward the left. More... | |
Bitset & | operator<<= (std::size_t pos) |
Shift all the bits toward the left. More... | |
Bitset | operator>> (std::size_t pos) const |
Shift all the bits toward the right. More... | |
Bitset & | operator>>= (std::size_t pos) |
Shift all the bits toward the right. More... | |
Bitset & | operator &= (const Bitset &bitset) |
Bitset & | operator|= (const Bitset &bitset) |
Performs an "OR" with another bitset. More... | |
Bitset & | operator^= (const Bitset &bitset) |
Performs an "XOR" with another bitset. More... | |
template<typename T > | |
Bitset< Block, Allocator > & | operator= (T value) |
Copies the internal representation of an unsigned integer. More... | |
Static Public Member Functions | |
static Bitset | FromPointer (const void *ptr, std::size_t bitCount, PointerSequence *sequence=nullptr) |
Builds a bitset from a byte sequence. More... | |
Static Public Attributes | |
static constexpr Block | fullBitMask = std::numeric_limits<Block>::max() |
static constexpr std::size_t | bitsPerBlock = BitCount<Block>() |
static constexpr std::size_t | npos = std::numeric_limits<std::size_t>::max() |
Core class that represents a set of bits.
This class meets the requirements of Container, AllocatorAwareContainer, SequenceContainer
|
explicit |
Constructs a Bitset object of bitCount bits to value val.
bitCount | Number of bits |
val | Value of those bits, by default false |
|
explicit |
Constructs a Bitset object from the contents initialized with a copy of the null-terminated character string pointed to by bits.
bits | Null-terminated character string containing only '0' and '1' |
Nz::Bitset< Block, Allocator >::Bitset | ( | const char * | bits, |
std::size_t | bitCount | ||
) |
Constructs a Bitset object from the contents initialized with a copy of the character string pointed to by bits takings the bitCount first characters.
bits | Character string containing only '0' and '1' |
bitCount | Number of characters to take into consideration |
|
explicit |
Constructs a Bitset object from a Nz::String.
bits | String containing only '0' and '1' |
Nz::Bitset< Block, Allocator >::Bitset | ( | T | value | ) |
Constructs a Bitset copying an unsigned integral number.
value | Number to be used as a base |
void Nz::Bitset< Block, Allocator >::AppendBits | ( | T | bits, |
std::size_t | bitCount | ||
) |
Appends bits to the bitset.
This function extends the bitset with bits extracted from an integer value
bits | An integer value from where bits will be extracted |
bitCount | Number of bits to extract from the value |
|
noexcept |
Clears the content of the bitset.
This function clears the bitset content, resetting its bit and block count at zero.
std::size_t Nz::Bitset< Block, Allocator >::Count | ( | ) | const |
Counts the number of bits set to 1.
std::size_t Nz::Bitset< Block, Allocator >::FindFirst | ( | ) | const |
Finds the first bit set to one in the bitset.
std::size_t Nz::Bitset< Block, Allocator >::FindNext | ( | std::size_t | bit | ) | const |
Finds the next enabled in the bitset.
bit | Index of the last bit found, which will not be treated by this function |
void Nz::Bitset< Block, Allocator >::Flip | ( | ) |
Flips each bit of the bitset.
This function flips every bit of the bitset, which means every '1' turns into a '0' and conversely.
|
static |
Builds a bitset from a byte sequence.
This function builds a bitset using a byte sequence by reading bitCount bits from it
ptr | A pointer to the start of the byte sequence |
bitCount | Number of bits to read from the byte sequence |
sequence | Optional data to pass to a next call to Read |
Block Nz::Bitset< Block, Allocator >::GetBlock | ( | std::size_t | i | ) | const |
Gets the ith block.
i | Index of the block |
std::size_t Nz::Bitset< Block, Allocator >::GetBlockCount | ( | ) | const |
Gets the number of blocks.
std::size_t Nz::Bitset< Block, Allocator >::GetCapacity | ( | ) | const |
Gets the capacity of the bitset.
std::size_t Nz::Bitset< Block, Allocator >::GetSize | ( | ) | const |
Gets the number of bits.
bool Nz::Bitset< Block, Allocator >::Intersects | ( | const Bitset< Block, Allocator > & | bitset | ) | const |
Checks if bitsets have one block in common.
bitset | Bitset to test |
Bitset< Block, Allocator > Nz::Bitset< Block, Allocator >::operator<< | ( | std::size_t | pos | ) | const |
Shift all the bits toward the left.
pos | Bit shifting to be applied |
Bitset< Block, Allocator > & Nz::Bitset< Block, Allocator >::operator<<= | ( | std::size_t | pos | ) |
Shift all the bits toward the left.
pos | Bit shifting to be applied |
Bitset< Block, Allocator > & Nz::Bitset< Block, Allocator >::operator= | ( | const String & | bits | ) |
Sets this bitset from a Nz::String.
bits | String containing only '0' and '1' |
Bitset<Block, Allocator>& Nz::Bitset< Block, Allocator >::operator= | ( | T | value | ) |
Copies the internal representation of an unsigned integer.
value | Unsigned number which will be used as a source |
Bitset< Block, Allocator > Nz::Bitset< Block, Allocator >::operator>> | ( | std::size_t | pos | ) | const |
Shift all the bits toward the right.
pos | Bit shifting to be applied |
Bitset< Block, Allocator > & Nz::Bitset< Block, Allocator >::operator>>= | ( | std::size_t | pos | ) |
Shift all the bits toward the right.
pos | Bit shifting to be applied |
Bitset< Block, Allocator >::Bit Nz::Bitset< Block, Allocator >::operator[] | ( | std::size_t | index | ) |
Gets the ith bit.
bool Nz::Bitset< Block, Allocator >::operator[] | ( | std::size_t | index | ) | const |
Gets the ith bit.
Bitset< Block, Allocator > & Nz::Bitset< Block, Allocator >::operator^= | ( | const Bitset< Block, Allocator > & | bitset | ) |
Performs an "XOR" with another bitset.
bitset | Other bitset |
Bitset< Block, Allocator > & Nz::Bitset< Block, Allocator >::operator|= | ( | const Bitset< Block, Allocator > & | bitset | ) |
Performs an "OR" with another bitset.
bitset | Other bitset |
Bitset< Block, Allocator > Nz::Bitset< Block, Allocator >::operator~ | ( | ) | const |
Negates the bitset.
void Nz::Bitset< Block, Allocator >::PerformsAND | ( | const Bitset< Block, Allocator > & | a, |
const Bitset< Block, Allocator > & | b | ||
) |
Performs the "AND" operator between two bitsets.
a | First bitset |
b | Second bitset |
void Nz::Bitset< Block, Allocator >::PerformsNOT | ( | const Bitset< Block, Allocator > & | a | ) |
Performs the "NOT" operator of the bitset.
a | Bitset to negate |
void Nz::Bitset< Block, Allocator >::PerformsOR | ( | const Bitset< Block, Allocator > & | a, |
const Bitset< Block, Allocator > & | b | ||
) |
Performs the "OR" operator between two bitsets.
a | First bitset |
b | Second bitset |
void Nz::Bitset< Block, Allocator >::PerformsXOR | ( | const Bitset< Block, Allocator > & | a, |
const Bitset< Block, Allocator > & | b | ||
) |
Performs the "XOR" operator between two bitsets.
a | First bitset |
b | Second bitset |
Bitset< Block, Allocator >::PointerSequence Nz::Bitset< Block, Allocator >::Read | ( | const void * | ptr, |
std::size_t | bitCount | ||
) |
Read a byte sequence into a bitset.
This function extends the bitset with bits read from a byte sequence
ptr | A pointer to the start of the byte sequence |
bitCount | Number of bits to read from the byte sequence |
Bitset< Block, Allocator >::PointerSequence Nz::Bitset< Block, Allocator >::Read | ( | const PointerSequence & | sequence, |
std::size_t | bitCount | ||
) |
Read a byte sequence into a bitset.
This function extends the bitset with bits read from a pointer sequence (made of a pointer and a bit index)
sequence | A pointer sequence to the start of the byte sequence |
bitCount | Number of bits to read from the byte sequence |
void Nz::Bitset< Block, Allocator >::Reserve | ( | std::size_t | bitCount | ) |
Reserves enough blocks to contain bitCount bits.
bitCount | Number of bits to reserve |
void Nz::Bitset< Block, Allocator >::Reset | ( | std::size_t | bit | ) |
Resets the bit at the index.
bit | Index of the bit |
void Nz::Bitset< Block, Allocator >::Resize | ( | std::size_t | bitCount, |
bool | defaultVal = false |
||
) |
Resizes the bitset to the size of bitCount.
bitCount | Number of bits to resize |
defaultVal | Value of the bits if new size is greather than the old one |
void Nz::Bitset< Block, Allocator >::Reverse | ( | ) |
Reverse the order of bits in a bitset.
Reverse the order of bits in the bitset (first bit swap with the last one, etc.)
void Nz::Bitset< Block, Allocator >::Set | ( | bool | val = true | ) |
Sets the bitset to val.
val | Value of the bits |
void Nz::Bitset< Block, Allocator >::Set | ( | std::size_t | bit, |
bool | val = true |
||
) |
Sets the bit at the index.
bit | Index of the bit |
val | Value of the bit |
void Nz::Bitset< Block, Allocator >::SetBlock | ( | std::size_t | i, |
Block | block | ||
) |
Set the ith block.
i | Index of the block |
block | Block to set |
void Nz::Bitset< Block, Allocator >::ShiftLeft | ( | std::size_t | pos | ) |
Shift all the bits toward the left.
pos | Bit shifting to be applied |
void Nz::Bitset< Block, Allocator >::ShiftRight | ( | std::size_t | pos | ) |
Shift all the bits toward the right.
pos | Bit shifting to be applied |
void Nz::Bitset< Block, Allocator >::Swap | ( | Bitset< Block, Allocator > & | bitset | ) |
Swaps the two bitsets.
bitset | Other bitset to swap |
bool Nz::Bitset< Block, Allocator >::Test | ( | std::size_t | bit | ) | const |
Tests the ith bit.
bit | Index of the bit |
bool Nz::Bitset< Block, Allocator >::TestAll | ( | ) | const |
Tests each block.
bool Nz::Bitset< Block, Allocator >::TestAny | ( | ) | const |
Tests if one bit is set.
bool Nz::Bitset< Block, Allocator >::TestNone | ( | ) | const |
Tests if one bit is not set.
T Nz::Bitset< Block, Allocator >::To | ( | ) | const |
Converts the bitset to template type.
String Nz::Bitset< Block, Allocator >::ToString | ( | ) | const |
Gives a string representation.
void Nz::Bitset< Block, Allocator >::UnboundedReset | ( | std::size_t | bit | ) |
Resets the bit at the index.
bit | Index of the bit |
void Nz::Bitset< Block, Allocator >::UnboundedSet | ( | std::size_t | bit, |
bool | val = true |
||
) |
Sets the bit at the index.
bit | Index of the bit |
val | Value of the bit |
bool Nz::Bitset< Block, Allocator >::UnboundedTest | ( | std::size_t | bit | ) | const |