1.1
Public Member Functions | Static Public Attributes | List of all members
Flags< T > Class Template Reference

Utility class for managing a set of flags with the ability to observe changes to the flags. More...

Inheritance diagram for Flags< T >:
Inheritance graph
[legend]

Public Member Functions

constexpr Flags () noexcept=default
 
 Flags (const char *str)
 
constexpr Flags (const Flags &rhs) noexcept
 Copy constructor. More...
 
 Flags (const std::string &str)
 
 Flags (Flags &&) noexcept=default
 
constexpr Flags (T flag) noexcept
 Set a single flag. More...
 
 ~Flags () noexcept=default
 
bool clear () noexcept
 Clear all flags. More...
 
bool clear (T flag) noexcept
 Clear a single flag. More...
 
void from_string (const std::string &str)
 Convert from string. More...
 
constexpr Flags< T > operator& (const T &flag) const noexcept
 And operator. More...
 
Flagsoperator= (const Flags &rhs)
 Assignment operator. More...
 
Flagsoperator= (Flags &&) noexcept=default
 
constexpr Flags< T > operator| (const T &flag) const noexcept
 Or operator. More...
 
bool set (std::initializer_list< T > flags) noexcept
 Set multiple flags. More...
 
bool set (T flag) noexcept
 Set a single flag. More...
 
EGT_NODISCARD std::string to_string () const
 Convert the flags to strings. More...
 
- Public Member Functions inherited from FlagsBase< T >
constexpr FlagsBase () noexcept=default
 
constexpr FlagsBase (const T flag) noexcept
 Construct with a single flag. More...
 
constexpr FlagsBase (std::initializer_list< T > flags) noexcept
 Construct with an initializer_list of flags. More...
 
constexpr bool clear () noexcept
 Unset all flags. More...
 
constexpr bool clear (const T flag) noexcept
 Clear, or unset, the specified flag. More...
 
constexpr EGT_NODISCARD bool empty () const noexcept
 Returns true if there are no flags set. More...
 
EGT_NODISCARD std::set< T > get () const
 Get a std::set of all set flags. More...
 
constexpr EGT_NODISCARD bool is_set (const T flag) const noexcept
 Test if the specified flag is set. More...
 
constexpr EGT_NODISCARD bool is_set (std::initializer_list< T > flags) const noexcept
 Test if the specified flags are set. More...
 
constexpr Underlyingraw ()
 Get the raw underlying value. More...
 
constexpr const EGT_NODISCARD Underlyingraw () const
 Get the raw underlying value. More...
 
constexpr bool set (const T flag) noexcept
 Set the specified flag. More...
 
constexpr bool set (std::initializer_list< T > flags) noexcept
 Set the specified flags. More...
 

Public Attributes

Signal on_change
 Event signal. More...
 

Static Public Attributes

constexpr static const char FLAGS_DELIMITER = '|'
 Delimiter used to separate flags in string representation. More...
 

Additional Inherited Members

- Public Types inherited from FlagsBase< T >
using Underlying = typename std::underlying_type< T >::type
 This is the underlying type of the flags, which is used internally for efficient bitwise operation on flags. More...
 
- Protected Attributes inherited from FlagsBase< T >
Underlying m_flags {}
 The flags. More...
 

Detailed Description

template<class T>
class egt::v1::Flags< T >

Utility class for managing a set of flags with the ability to observe changes to the flags.

This supports at most flag values supported by the number of bits in the underlying enum type.

Warning
All flags must be a power of 2.

Constructor & Destructor Documentation

◆ Flags() [1/6]

constexpr Flags ( )
constexprdefaultnoexcept

◆ Flags() [2/6]

Flags ( const std::string &  str)
inlineexplicit
Parameters
[in]strString representation of flags.

◆ Flags() [3/6]

Flags ( const char *  str)
inlineexplicit
Parameters
[in]strString representation of flags.

◆ Flags() [4/6]

constexpr Flags ( flag)
inlineconstexprnoexcept

Set a single flag.

◆ Flags() [5/6]

constexpr Flags ( const Flags< T > &  rhs)
inlineconstexprnoexcept

Copy constructor.

◆ Flags() [6/6]

Flags ( Flags< T > &&  )
defaultnoexcept

◆ ~Flags()

~Flags ( )
defaultnoexcept

Member Function Documentation

◆ clear() [1/2]

bool clear ( )
inlinenoexcept

Clear all flags.

◆ clear() [2/2]

bool clear ( flag)
inlinenoexcept

Clear a single flag.

◆ from_string()

void from_string ( const std::string &  str)
inline

Convert from string.

Note
This will clear any existing flags first.

◆ operator&()

constexpr Flags<T> operator& ( const T &  flag) const
inlineconstexprnoexcept

And operator.

◆ operator=() [1/2]

Flags& operator= ( const Flags< T > &  rhs)
inline

Assignment operator.

◆ operator=() [2/2]

Flags& operator= ( Flags< T > &&  )
defaultnoexcept

◆ operator|()

constexpr Flags<T> operator| ( const T &  flag) const
inlineconstexprnoexcept

Or operator.

◆ set() [1/2]

bool set ( std::initializer_list< T >  flags)
inlinenoexcept

Set multiple flags.

◆ set() [2/2]

bool set ( flag)
inlinenoexcept

Set a single flag.

◆ to_string()

EGT_NODISCARD std::string to_string ( ) const
inline

Convert the flags to strings.

Member Data Documentation

◆ FLAGS_DELIMITER

constexpr static const char FLAGS_DELIMITER = '|'
staticconstexpr

Delimiter used to separate flags in string representation.

◆ on_change

Signal on_change

Event signal.

Invoked when the flags are changed.