33#include <NDEVR/BaseValues.h>
34#include <NDEVR/LibAssert.h>
57 static constexpr uint01 kBitMask[8] = {
67 static constexpr uint01 kBitMaskInv[8] = {
81 constexpr BitFlag(
sint04 flags)
84 lib_assert(flags <= 255,
"Bad bitflag");
86 constexpr BitFlag(
uint01 flags)
89 explicit constexpr BitFlag(
bool flag)
90 : m_bits(flag ? 255U : 0U)
93 template<
class t_type>
94 BitFlag(std::initializer_list<t_type> active_list)
97 for (
auto i : active_list)
109 lib_assert(bit_index < 8,
"Tried to access large bit value");
110 return (m_bits & kBitMask[bit_index]) != 0;
122 m_bits |= kBitMask[bit_index];
124 m_bits &= kBitMaskInv[bit_index];
142 m_bits |= mask.m_bits;
146 constexpr void operator^=(
const BitFlag& mask)
148 m_bits ^= mask.m_bits;
157 m_bits &= mask.m_bits;
221 return m_bits != other.m_bits;
223 constexpr bool operator==(
const BitFlag& other)
const
225 return m_bits == other.m_bits;
237 constexpr static BitFlag
merge(
const BitFlag& value_a,
const BitFlag& value_b,
const BitFlag& mask)
239 return value_b ^ ((value_b ^ value_a) & mask);
250 constexpr static BitFlag
merge(
const BitFlag& value_a,
const BitFlag& value_b,
uint01 num_of_bits)
253 return value_b ^ ((value_b ^ value_a) & mask);
256 [[nodiscard]]
uint01 bits()
const
269 struct b4lo {
unsigned __int8 v : 4;
unsigned __int8 _ : 4; };
270 struct b4hi {
unsigned __int8 _ : 4;
unsigned __int8 v : 4; };
271 struct b8 {
unsigned __int8 _; };
272 struct b32 { __int32 _; };
A bitset that stores 8 bits (elements with only two possible values: 0 or 1, true or false,...
constexpr void operator()(const uint01 bit_index, bool value)
Operator used to set a bit in the bitflag to the given value Parameters:
static constexpr BitFlag merge(const BitFlag &value_a, const BitFlag &value_b, const BitFlag &mask)
Given bit value_a and bit value_b merges the bits such that indices with a mask of false will be set ...
constexpr void operator|=(const BitFlag &mask)
Bitwise 'or' assignment operator.
constexpr BitFlag operator~() const
Bitwise 'ones complement' operator.
constexpr BitFlag operator^(uint01 mask) const
Bitwise 'exclusive or' operator.
static constexpr BitFlag merge(const BitFlag &value_a, const BitFlag &value_b, uint01 num_of_bits)
Given bit value_a and bit value_b merges the bits such that indices with a value lower than num_of_bi...
constexpr BitFlag operator&(uint01 mask) const
Bitwise 'and' operator.
constexpr bool operator[](uint01 bit_index) const
Accesses the value at bit position specified by index.
constexpr void operator&=(const BitFlag &mask)
Bitwise 'and' assignment operator.
constexpr BitFlag operator^(const BitFlag &mask) const
Bitwise 'exclusive or' operator.
constexpr BitFlag operator&(const BitFlag &mask) const
Bitwise 'and' operator.
constexpr void operator&=(uint01 mask)
Bitwise 'and' assignment operator.
The primary namespace for the NDEVR SDK.
constexpr bool operator!=(const Vector< t_dims, t_type > &vec_a, const Vector< t_dims, t_type > &vec_b)
Inequality operator.
int32_t sint04
-Defines an alias representing a 4 byte, signed integer.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.