A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
EGG::TBitFlagExt< N, E > Class Template Reference

#include <BitFlag.hh>

Description

template<size_t N, typename E>
requires (std::is_enum_v<E> && N > 64)
class EGG::TBitFlagExt< N, E >

Wrapper around a variable length bitfield with an enum corresponding to its bits.

Template Parameters
NThe number of bits in the bitfield. Must be >= 64 to distinguish from TBitFlag.
EThe enum to correspond to.

Definition at line 322 of file BitFlag.hh.

Public Member Functions

constexpr TBitFlagExt ()
 Default constructor, initializes all flags to off.
 
constexpr TBitFlagExt< N, E > & makeAllZero ()
 Resets all the bits to zero across the entire bitfield array.
 
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
constexpr TBitFlagExt< N, E > & setBit (Es... es)
 Sets the corresponding bits for the provided enum values.
 
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
constexpr TBitFlagExt< N, E > & resetBit (Es... es)
 Resets the corresponding bits for the provided enum values.
 
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
constexpr TBitFlagExt< N, E > & changeBit (bool on, Es... es)
 Changes the state of the corresponding bits for the provided enum values.
 
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
constexpr bool onBit (Es... es) const
 Checks if any of the corresponding bits for the provided enum values are on.
 
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
constexpr bool onAnyBit (Es... es) const
 Checks if any of the corresponding bits for the provided enum values are on.
 
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
constexpr bool onAllBit (Es... es) const
 Checks if all of the corresponding bits for the provided enum values are on.
 
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
constexpr bool offBit (Es... es) const
 Checks if all of the corresponding bits for the provided enum values are off.
 
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
constexpr bool offAllBit (Es... es) const
 Checks if all of the corresponding bits for the provided enum values are off.
 
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
constexpr bool offAnyBit (Es... es) const
 Checks if any of the corresponding bits for the provided enum values are off.
 

Private Types

typedef std::underlying_type_t< E > EI
 
typedef u32 T
 

Private Member Functions

constexpr void setBit_ (E e)
 Internal. Sets a specific bit.
 
constexpr void resetBit_ (E e)
 Internal. Resets a specific bit.
 
constexpr void changeBit_ (bool on, E e)
 Internal. Changes a specific bit.
 
constexpr bool onBit_ (E e) const
 Checks if a specific bit is on.
 
constexpr bool offBit_ (E e) const
 Checks if a specific bit is off.
 
constexpr std::pair< T, T > makeMask_ (E e) const
 Gets bit index and mask for a specific bit.
 
constexpr std::pair< T &, T > makeMask_ (E e)
 Gets bit index and mask for a specific bit.
 

Private Attributes

std::array< T,(N+C - 1)/C > bits
 

Static Private Attributes

static constexpr size_t C = 8 * sizeof(T)
 

Member Typedef Documentation

◆ EI

template<size_t N, typename E >
std::underlying_type_t<E> EGG::TBitFlagExt< N, E >::EI
private

Definition at line 439 of file BitFlag.hh.

◆ T

template<size_t N, typename E >
u32 EGG::TBitFlagExt< N, E >::T
private

Definition at line 483 of file BitFlag.hh.

Constructor & Destructor Documentation

◆ TBitFlagExt()

template<size_t N, typename E >
EGG::TBitFlagExt< N, E >::TBitFlagExt ( )
inlineconstexpr

Default constructor, initializes all flags to off.

Matches the expression bits = 0.

Definition at line 326 of file BitFlag.hh.

Member Function Documentation

◆ changeBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
TBitFlagExt< N, E > & EGG::TBitFlagExt< N, E >::changeBit ( bool on,
Es... es )
inlineconstexpr

Changes the state of the corresponding bits for the provided enum values.

Template Parameters
...EsVariadic template for packing.
Parameters
onDetermines whether to set or reset the bits.
...esEnum values representing the bits to change.
Returns
Reference for chaining.

Definition at line 367 of file BitFlag.hh.

◆ changeBit_()

template<size_t N, typename E >
void EGG::TBitFlagExt< N, E >::changeBit_ ( bool on,
E e )
inlinenodiscardconstexprprivate

Internal. Changes a specific bit.

Validates that e is in the range of N.

Parameters
onDetermines whether to set or reset the bit.
eEnum value respresenting the bit to change.

Definition at line 461 of file BitFlag.hh.

◆ makeAllZero()

template<size_t N, typename E >
TBitFlagExt< N, E > & EGG::TBitFlagExt< N, E >::makeAllZero ( )
inlineconstexpr

Resets all the bits to zero across the entire bitfield array.

Returns
Reference for chaining.

Definition at line 332 of file BitFlag.hh.

◆ makeMask_() [1/2]

template<size_t N, typename E >
std::pair< T &, T > EGG::TBitFlagExt< N, E >::makeMask_ ( E e)
inlinenodiscardconstexprprivate

Gets bit index and mask for a specific bit.

Matches the expression (1 << e). Validates that e is in the range of N.

Parameters
eEnum value representing the bit to make.
Returns
The index and mask for the specified bit.

Definition at line 499 of file BitFlag.hh.

◆ makeMask_() [2/2]

template<size_t N, typename E >
std::pair< T, T > EGG::TBitFlagExt< N, E >::makeMask_ ( E e) const
inlinenodiscardconstexprprivate

Gets bit index and mask for a specific bit.

Matches the expression (1 << e). Validates that e is in the range of N.

Parameters
eEnum value representing the bit to make.
Returns
The index and mask for the specified bit.

Definition at line 489 of file BitFlag.hh.

◆ offAllBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool EGG::TBitFlagExt< N, E >::offAllBit ( Es... es) const
inlinenodiscardconstexpr

Checks if all of the corresponding bits for the provided enum values are off.

Matches the expression (bits & mask) == 0.

Template Parameters
...EsVariadic template for packing.
Parameters
...esEnum values representing the bits to check.
Returns
True if all of the specified bits are off, otherwise false.

Definition at line 423 of file BitFlag.hh.

◆ offAnyBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool EGG::TBitFlagExt< N, E >::offAnyBit ( Es... es) const
inlinenodiscardconstexpr

Checks if any of the corresponding bits for the provided enum values are off.

Matches the expression (bits & mask) != mask.

Template Parameters
...EsVariadic template for packing.
Parameters
...esEnum values representing the bits to check.
Returns
True if any of the specified bits are off, otherwise false.

Definition at line 434 of file BitFlag.hh.

◆ offBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool EGG::TBitFlagExt< N, E >::offBit ( Es... es) const
inlinenodiscardconstexpr

Checks if all of the corresponding bits for the provided enum values are off.

Matches the expression (bits & mask) == 0.

Template Parameters
...EsVariadic template for packing.
Parameters
...esEnum values representing the bits to check.
Returns
True if all of the specified bits are off, otherwise false.

Definition at line 412 of file BitFlag.hh.

◆ offBit_()

template<size_t N, typename E >
bool EGG::TBitFlagExt< N, E >::offBit_ ( E e) const
inlinenodiscardconstexprprivate

Checks if a specific bit is off.

Validates that e is in the range of N.

Parameters
eEnum value representing the bit to change.
Returns
True if the specified bit is off, otherwise false.

Definition at line 478 of file BitFlag.hh.

◆ onAllBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool EGG::TBitFlagExt< N, E >::onAllBit ( Es... es) const
inlinenodiscardconstexpr

Checks if all of the corresponding bits for the provided enum values are on.

Matches the expression (bits & mask) == mask.

Template Parameters
...EsVariadic template for packing.
Parameters
...esEnum values representing the bits to check.
Returns
True if all of the specified bits are on, otherwise false.

Definition at line 401 of file BitFlag.hh.

◆ onAnyBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool EGG::TBitFlagExt< N, E >::onAnyBit ( Es... es) const
inlinenodiscardconstexpr

Checks if any of the corresponding bits for the provided enum values are on.

Matches the expression (bits & mask) != 0.

Template Parameters
...EsVariadic template for packing.
Parameters
...esEnum values representing the bits to check.
Returns
True if one of the specified bits are on, otherwise false.

Definition at line 390 of file BitFlag.hh.

◆ onBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool EGG::TBitFlagExt< N, E >::onBit ( Es... es) const
inlinenodiscardconstexpr

Checks if any of the corresponding bits for the provided enum values are on.

Matches the expression (bits & mask) != 0.

Template Parameters
...EsVariadic template for packing.
Parameters
...esEnum values representing the bits to check.
Returns
True if one of the specified bits are on, otherwise false.

Definition at line 379 of file BitFlag.hh.

◆ onBit_()

template<size_t N, typename E >
bool EGG::TBitFlagExt< N, E >::onBit_ ( E e) const
inlinenodiscardconstexprprivate

Checks if a specific bit is on.

Validates that e is in the range of N.

Parameters
eEnum value representing the bit to change.
Returns
True if the specified bit is on, otherwise false.

Definition at line 469 of file BitFlag.hh.

◆ resetBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
TBitFlagExt< N, E > & EGG::TBitFlagExt< N, E >::resetBit ( Es... es)
inlineconstexpr

Resets the corresponding bits for the provided enum values.

Template Parameters
...EsVariadic template for packing.
Parameters
...esEnum values representing the bits to reset.
Returns
Reference for chaining.

Definition at line 355 of file BitFlag.hh.

◆ resetBit_()

template<size_t N, typename E >
void EGG::TBitFlagExt< N, E >::resetBit_ ( E e)
inlineconstexprprivate

Internal. Resets a specific bit.

Validates that e is in the range of N.

Parameters
eEnum value representing the bit to set.

Definition at line 452 of file BitFlag.hh.

◆ setBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
TBitFlagExt< N, E > & EGG::TBitFlagExt< N, E >::setBit ( Es... es)
inlineconstexpr

Sets the corresponding bits for the provided enum values.

Matches the expression bits |= mask.

Template Parameters
...EsVariadic template for packing.
Parameters
...esEnum values representing the bits to set.
Returns
Reference for chaining.

Definition at line 344 of file BitFlag.hh.

◆ setBit_()

template<size_t N, typename E >
void EGG::TBitFlagExt< N, E >::setBit_ ( E e)
inlineconstexprprivate

Internal. Sets a specific bit.

Validates that e is in the range of N.

Parameters
eEnum value representing the bit to set.

Definition at line 444 of file BitFlag.hh.

Member Data Documentation

◆ bits

template<size_t N, typename E >
std::array<T, (N + C - 1) / C> EGG::TBitFlagExt< N, E >::bits
private

Definition at line 506 of file BitFlag.hh.

◆ C

template<size_t N, typename E >
size_t EGG::TBitFlagExt< N, E >::C = 8 * sizeof(T)
staticconstexprprivate

Definition at line 505 of file BitFlag.hh.