NDEVR
API Documentation
BitFlag

A bitset that stores 8 bits (elements with only two possible values: 0 or 1, true or false, ...). More...

Public Member Functions

constexpr operator uint01 () const
 Cast that converts the given to an uint01.
constexpr BitFlag operator& (const BitFlag &mask) const
 Bitwise 'and' operator.
constexpr BitFlag operator& (uint01 mask) const
 Bitwise 'and' operator.
constexpr void operator&= (const BitFlag &mask)
 Bitwise 'and' assignment operator.
constexpr void operator&= (uint01 mask)
 Bitwise 'and' assignment operator.
constexpr void operator() (const uint01 bit_index, bool value)
 Operator used to set a bit in the bitflag to the given value Parameters:
constexpr bool operator[] (uint01 bit_index) const
 Accesses the value at bit position specified by index.
constexpr BitFlag operator^ (const BitFlag &mask) const
 Bitwise 'exclusive or' operator.
constexpr BitFlag operator^ (uint01 mask) const
 Bitwise 'exclusive or' operator.
constexpr void operator|= (const BitFlag &mask)
 Bitwise 'or' assignment operator.
constexpr BitFlag operator~ () const
 Bitwise 'ones complement' operator.

Static Public Member Functions

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 to value_a and values with a bit of mask 0 will be set to b in the returning bitflag.
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_bits will be set to value_a and values with a bit of mask 0 will be set to b in the returning bitflag.

Detailed Description

A bitset that stores 8 bits (elements with only two possible values: 0 or 1, true or false, ...).


The class emulates an array of 8 bool elements, but optimized for space allocation: generally, each element occupies only one bit (which, on most systems, is eight times less than the smallest elemental type: int01).

Each bit position can be accessed individually: for example, for a given bitset named foo, the expression foo[3] accesses its fourth bit, just like a regular array accesses its elements. But because no elemental type is a single bit, operator(bit, value) must be used to set values.

Bitsets have the feature of being able to be constructed from and converted to both integer values and binary strings (see its constructor and members to_ulong and to_string). They can also be directly inserted and extracted from streams in binary format

(see applicable operators).

Definition at line 54 of file BitFlag.hpp.

Member Function Documentation

◆ merge() [1/2]

constexpr BitFlag BitFlag::merge ( const BitFlag & value_a,
const BitFlag & value_b,
const BitFlag & mask )
inlinestaticconstexpr

Given bit value_a and bit value_b merges the bits such that indices with a mask of false will be set to value_a and values with a bit of mask 0 will be set to b in the returning bitflag.

Parameters
[in]value_aA BitFlag to process where values of mask 0 will be used.
[in]value_bA BitFlag to process where values of mask 1 will be used.
[in]maskThe mask used to determine which bits will be used.
Returns
A BitFlag consisting of the merging of value_a and value_b as defined by the mask.

Definition at line 237 of file BitFlag.hpp.

◆ merge() [2/2]

constexpr BitFlag BitFlag::merge ( const BitFlag & value_a,
const BitFlag & value_b,
uint01 num_of_bits )
inlinestaticconstexpr

Given bit value_a and bit value_b merges the bits such that indices with a value lower than num_of_bits will be set to value_a and values with a bit of mask 0 will be set to b in the returning bitflag.

Parameters
[in]value_aA BitFlag to process where values of mask 0 will be used.
[in]value_bA BitFlag to process where values of mask 1 will be used.
[in]num_of_bitsThe bits used to use from value_a.
Returns
A BitFlag consisting of the merging of value_a and value_b as defined by the num_of_bits.

Definition at line 250 of file BitFlag.hpp.

References cast().

◆ operator uint01()

BitFlag::operator uint01 ( ) const
inlineconstexpr

Cast that converts the given to an uint01.

Returns
The result of the operation.

Definition at line 131 of file BitFlag.hpp.

◆ operator&() [1/2]

BitFlag BitFlag::operator& ( const BitFlag & mask) const
inlineconstexpr

Bitwise 'and' operator.

Parameters
[in]mask- The mask.
Returns
The result of the operation.

Definition at line 174 of file BitFlag.hpp.

References cast().

◆ operator&() [2/2]

BitFlag BitFlag::operator& ( uint01 mask) const
inlineconstexpr

Bitwise 'and' operator.

Parameters
[in]mask- The mask.
Returns
The result of the operation.

Definition at line 194 of file BitFlag.hpp.

References cast().

◆ operator&=() [1/2]

void BitFlag::operator&= ( const BitFlag & mask)
inlineconstexpr

Bitwise 'and' assignment operator.

Parameters
[in]maskThe mask.

Definition at line 155 of file BitFlag.hpp.

◆ operator&=() [2/2]

void BitFlag::operator&= ( uint01 mask)
inlineconstexpr

Bitwise 'and' assignment operator.

Parameters
[in]maskThe mask.

Definition at line 164 of file BitFlag.hpp.

◆ operator()()

void BitFlag::operator() ( const uint01 bit_index,
bool value )
inlineconstexpr

Operator used to set a bit in the bitflag to the given value Parameters:

Parameters
[in]bit_indexThe index of the bit you wish to set
[in]valueThe value to set the bit

Definition at line 119 of file BitFlag.hpp.

◆ operator[]()

bool BitFlag::operator[] ( uint01 bit_index) const
inlineconstexpr

Accesses the value at bit position specified by index.

Note this function may have more overhead than traditional [] since an operation will be used. Can only be a read-only value.

Parameters
[in]bit_indexThe index of the bit you wish to access
Returns
The indexed value.

Definition at line 107 of file BitFlag.hpp.

◆ operator^() [1/2]

BitFlag BitFlag::operator^ ( const BitFlag & mask) const
inlineconstexpr

Bitwise 'exclusive or' operator.

Parameters
[in]mask- The mask.
Returns
The result of the operation.

Definition at line 184 of file BitFlag.hpp.

References cast().

◆ operator^() [2/2]

BitFlag BitFlag::operator^ ( uint01 mask) const
inlineconstexpr

Bitwise 'exclusive or' operator.

Parameters
[in]mask- The mask.
Returns
The result of the operation.

Definition at line 204 of file BitFlag.hpp.

References cast().

◆ operator|=()

void BitFlag::operator|= ( const BitFlag & mask)
inlineconstexpr

Bitwise 'or' assignment operator.

Parameters
[in]maskThe mask.

Definition at line 140 of file BitFlag.hpp.

◆ operator~()

BitFlag BitFlag::operator~ ( ) const
inlineconstexpr

Bitwise 'ones complement' operator.

Returns
The result of the operation.

Definition at line 213 of file BitFlag.hpp.

References cast().


The documentation for this class was generated from the following file: