A reimplementation of Mario Kart Wii's physics engine in C++
Loading...
Searching...
No Matches
Kinoko::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 Kinoko::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 324 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> Kinoko::EGG::TBitFlagExt< N, E >::EI
private

Definition at line 441 of file BitFlag.hh.

◆ T

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

Definition at line 485 of file BitFlag.hh.

Constructor & Destructor Documentation

◆ TBitFlagExt()

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

Default constructor, initializes all flags to off.

Matches the expression bits = 0.

Definition at line 328 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 > & Kinoko::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 369 of file BitFlag.hh.

◆ changeBit_()

template<size_t N, typename E >
void Kinoko::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 representing the bit to change.

Definition at line 463 of file BitFlag.hh.

◆ makeAllZero()

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

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

Returns
Reference for chaining.

Definition at line 334 of file BitFlag.hh.

◆ makeMask_() [1/2]

template<size_t N, typename E >
std::pair< T &, T > Kinoko::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 501 of file BitFlag.hh.

◆ makeMask_() [2/2]

template<size_t N, typename E >
std::pair< T, T > Kinoko::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 491 of file BitFlag.hh.

◆ offAllBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool Kinoko::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 425 of file BitFlag.hh.

◆ offAnyBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool Kinoko::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 436 of file BitFlag.hh.

◆ offBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool Kinoko::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 414 of file BitFlag.hh.

◆ offBit_()

template<size_t N, typename E >
bool Kinoko::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 480 of file BitFlag.hh.

◆ onAllBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool Kinoko::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 403 of file BitFlag.hh.

◆ onAnyBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool Kinoko::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 392 of file BitFlag.hh.

◆ onBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
bool Kinoko::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 381 of file BitFlag.hh.

◆ onBit_()

template<size_t N, typename E >
bool Kinoko::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 471 of file BitFlag.hh.

◆ resetBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
TBitFlagExt< N, E > & Kinoko::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 357 of file BitFlag.hh.

◆ resetBit_()

template<size_t N, typename E >
void Kinoko::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 454 of file BitFlag.hh.

◆ setBit()

template<size_t N, typename E >
template<typename... Es>
requires (std::is_same_v<Es, E> && ...)
TBitFlagExt< N, E > & Kinoko::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 346 of file BitFlag.hh.

◆ setBit_()

template<size_t N, typename E >
void Kinoko::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 446 of file BitFlag.hh.

Member Data Documentation

◆ bits

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

Definition at line 508 of file BitFlag.hh.

◆ C

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

Definition at line 507 of file BitFlag.hh.