Skip to content

FlagSet

#include <tpau-cpp-kernal/FlagSet.h>

INCLUDE FILE
#include <tpau-cpp-kernal/FlagSet.h>

class FlagSet

A set of flags. The possible flags are defined by an enum type.

This is meant to be used with enum types that don't explicitly define the values of their members. Do not define the values as powers of two. Values must be between 0 and 63, inclusive.

DEFINITION
template <typename Flag> requires std::is_enum_v<Flag> class FlagSet;

constructor FlagSet

Create a FlagSet with all flags disabled.

DEFINITION
FlagSet ( );

constructor FlagSet

Create a FlagSet with the given flags enabled.

DEFINITION
template <typename...Args> requires ((std::same_as<std::remove_cvref_t<Args>, Flag> || std::same_as<std::remove_cvref_t<Args>, FlagSet<Flag>>) && ...)
constexpr  FlagSet ( Args...  args );
PARAMETERDESCRIPTION
args

The flags to enable. Arguments can be of type Flag or other FlagSet.

RETURNSDESCRIPTION
constexpr

constructor FlagSet

Create a FlagSet from a raw bitmask.

DEFINITION
constexpr  FlagSet ( uint64_t  flag_mask );
PARAMETERDESCRIPTION
flag_mask

The bitmask of the flags to enable.

RETURNSDESCRIPTION
constexpr

method all_enabledconst

Check if all flags from another FlagSet are enabled.

DEFINITION
bool  all_enabled ( const FlagSet & other ) const;
PARAMETERDESCRIPTION
other
RETURNSDESCRIPTION
bool

method any_enabledconst

Check if any flag from another FlagSet is enabled.

DEFINITION
bool  any_enabled ( const FlagSet & other ) const;
PARAMETERDESCRIPTION
other
RETURNSDESCRIPTION
bool

true if any flag is enabled, false otherwise.

method disable

Disable a flag.

DEFINITION
void  disable ( Flag  flag );
PARAMETERDESCRIPTION
flag

The flag to disable.

method disable

Disable all flags set in another FlagSet.

DEFINITION
void  disable ( const FlagSet & other );
PARAMETERDESCRIPTION
other

The FlagSet containing the flags to disable.

method emptyconst

Check if no flags are enabled.

DEFINITION
bool  empty ( ) const;
RETURNSDESCRIPTION
bool

true if no flags are enabled, false otherwise.

method enable

Enable a flag.

DEFINITION
void  enable ( Flag  flag );
PARAMETERDESCRIPTION
flag

The flag to enable.

method enable

Enable all flags set in another FlagSet.

DEFINITION
void  enable ( const FlagSet & other );
PARAMETERDESCRIPTION
other

method get_maskstatic

Get the bitmask for a flag.

DEFINITION
static uint64_t  get_mask ( Flag  flag );
PARAMETERDESCRIPTION
flag

The flag to get the bitmask for.

RETURNSDESCRIPTION
uint64_t

The bitmask for the flag.

method is_enabledconst

Check if a flag is enabled.

DEFINITION
bool  is_enabled ( Flag  flag ) const;
PARAMETERDESCRIPTION
flag

The flag to check.

RETURNSDESCRIPTION
bool

true if the flag is enabled, false otherwise.

method operator boolconst

Interpret as bool: Check if any flags are enabled.

DEFINITION
operator bool ( ) const;

method operator==const

Compare two FlagSets for equality.

DEFINITION
bool  operator== ( const FlagSet & other ) const;
PARAMETERDESCRIPTION
other

The other FlagSet to compare with.

RETURNSDESCRIPTION
bool

true if both FlagSets have the same flags enabled, false otherwise.

method operator[]const

Check if a flag is enabled.

DEFINITION
bool  operator[] ( Flag  flag ) const;
PARAMETERDESCRIPTION
flag

The flag to check.

RETURNSDESCRIPTION
bool

true if the flag is enabled, false otherwise.