API Documentation
Loading...
Searching...
No Matches
BitFlag Class Reference

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

#include <BitFlag.hpp>

Public Member Functions

constexpr BitFlag ()
 
constexpr BitFlag (sint04 flags)
 
constexpr BitFlag (uint01 flags)
 
constexpr BitFlag (bool flag)
 
template<class t_type >
 BitFlag (std::initializer_list< t_type > active_list)
 
constexpr bool operator[] (uint01 bit_index) const
 
constexpr void operator() (const uint01 bit_index, bool value)
 
constexpr operator uint01 () const
 
constexpr void operator|= (const BitFlag &mask)
 
constexpr void operator^= (const BitFlag &mask)
 
constexpr void operator&= (const BitFlag &mask)
 
constexpr void operator&= (uint01 mask)
 
constexpr BitFlag operator& (const BitFlag &mask) const
 
constexpr BitFlag operator^ (const BitFlag &mask) const
 
constexpr BitFlag operator& (uint01 mask) const
 
constexpr BitFlag operator^ (uint01 mask) const
 
constexpr BitFlag operator~ () const
 
constexpr bool operator!= (const BitFlag &other) const
 
constexpr bool operator== (const BitFlag &other) const
 
uint01 bits () const
 

Static Public Member Functions

static constexpr BitFlag merge (const BitFlag &value_a, const BitFlag &value_b, const BitFlag &mask)
 
static constexpr BitFlag merge (const BitFlag &a, const BitFlag &b, uint01 num_of_bits)
 

Detailed Description

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


Class: BitFlag

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).

Author: Tyler Parke

Date: 2017-11-17

Constructor & Destructor Documentation

◆ BitFlag() [1/5]

BitFlag ( )
inlineconstexpr

◆ BitFlag() [2/5]

BitFlag ( sint04 flags)
inlineconstexpr

◆ BitFlag() [3/5]

BitFlag ( uint01 flags)
inlineconstexpr

◆ BitFlag() [4/5]

BitFlag ( bool flag)
inlineexplicitconstexpr

◆ BitFlag() [5/5]

template<class t_type >
BitFlag ( std::initializer_list< t_type > active_list)
inline

Member Function Documentation

◆ bits()

uint01 bits ( ) const
inlinenodiscard

◆ merge() [1/2]

static constexpr BitFlag merge ( const BitFlag & a,
const BitFlag & b,
uint01 num_of_bits )
inlinestaticconstexpr

Fn: constexpr static BitFlag 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 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

Author: Tyler Parke

Date: 2017-11-17

Parameters: value_a - A BitFlag to process where values of mask 0 will be used. value_b - A BitFlag to process where values of mask 1 will be used. num_of_bits - The 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.

◆ merge() [2/2]

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

Fn: constexpr static BitFlag 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

Author: Tyler Parke

Date: 2017-11-17

Parameters: value_a - A BitFlag to process where values of mask 0 will be used. value_b - A BitFlag to process where values of mask 1 will be used. mask - The 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.

◆ operator uint01()

operator uint01 ( ) const
inlineconstexpr

Fn: constexpr operator BitFlag::uint01() const

Cast that converts the given to an uint01.

Author: Tyler Parke

Date: 2017-11-17

Returns: The result of the operation.

◆ operator!=()

bool operator!= ( const BitFlag & other) const
inlineconstexpr

◆ operator&() [1/2]

BitFlag operator& ( const BitFlag & mask) const
inlineconstexpr

Fn: constexpr BitFlag BitFlag::operator&(const BitFlag& mask) const

Bitwise 'and' operator.

Author: Tyler Parke

Date: 2017-11-17

Parameters: mask - The mask.

Returns: The result of the operation.

◆ operator&() [2/2]

BitFlag operator& ( uint01 mask) const
inlineconstexpr

Fn: constexpr BitFlag BitFlag::operator&(uint01 mask) const

Bitwise 'and' operator.

Author: Tyler Parke

Date: 2017-11-17

Parameters: mask - The mask.

Returns: The result of the operation.

◆ operator&=() [1/2]

void operator&= ( const BitFlag & mask)
inlineconstexpr

Fn: constexpr void BitFlag::operator&=(const BitFlag& mask)

Bitwise 'and' assignment operator.

Author: Tyler Parke

Date: 2017-11-17

Parameters:

mask - The mask.

◆ operator&=() [2/2]

void operator&= ( uint01 mask)
inlineconstexpr

Fn: constexpr void BitFlag::operator&=(uint01 mask)

Bitwise 'and' assignment operator.

Author: Tyler Parke

Date: 2017-11-17

Parameters:

mask - The mask.

◆ operator()()

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

Fn: constexpr void BitFlag::operator()(const uint01 index, bool value)

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

Author: Tyler Parke

Date: 2017-11-17

Parameters: index - The index of the bit you wish to set

value - The value to set the bit

◆ operator==()

bool operator== ( const BitFlag & other) const
inlineconstexpr

◆ operator[]()

bool operator[] ( uint01 bit_index) const
inlineconstexpr

Fn: constexpr bool BitFlag::operator[](uint01 index) const

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.

Author: Tyler Parke

Date: 2017-11-17

Parameters: bit_index - The index of the bit you wish to access

Returns: The indexed value.

◆ operator^() [1/2]

BitFlag operator^ ( const BitFlag & mask) const
inlineconstexpr

Fn: constexpr BitFlag BitFlag::operator^(const BitFlag& mask) const

Bitwise 'exclusive or' operator.

Author: Tyler Parke

Date: 2017-11-17

Parameters: mask - The mask.

Returns: The result of the operation.

◆ operator^() [2/2]

BitFlag operator^ ( uint01 mask) const
inlineconstexpr

Fn: constexpr BitFlag BitFlag::operator^(uint01 mask) const

Bitwise 'exclusive or' operator.

Author: Tyler Parke

Date: 2017-11-17

Parameters: mask - The mask.

Returns: The result of the operation.

◆ operator^=()

void operator^= ( const BitFlag & mask)
inlineconstexpr

◆ operator|=()

void operator|= ( const BitFlag & mask)
inlineconstexpr

Fn: constexpr void BitFlag::operator|=(const BitFlag& mask)

Bitwise 'or' assignment operator.

Author: Tyler Parke

Date: 2017-11-17

Parameters:

mask - The mask.

◆ operator~()

BitFlag operator~ ( ) const
inlineconstexpr

Fn: constexpr BitFlag BitFlag::operator~() const

Bitwise 'ones complement' operator.

Author: Tyler Parke

Date: 2017-11-17

Returns: The result of the operation.


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