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

#include <flags.h>

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

Public Attributes

Signal on_change
 Event signal.
 

Static Public Attributes

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

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.
 
- Protected Attributes inherited from FlagsBase< T >
Underlying m_flags {}
 The flags.
 

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]

template<class T >
constexpr Flags ( )
constexprdefaultnoexcept

◆ Flags() [2/6]

template<class T >
Flags ( const std::string &  str)
inlineexplicit
Parameters
[in]strString representation of flags.

◆ Flags() [3/6]

template<class T >
Flags ( const char *  str)
inlineexplicit
Parameters
[in]strString representation of flags.

◆ Flags() [4/6]

template<class T >
constexpr Flags ( flag)
inlineconstexprnoexcept

Set a single flag.

◆ Flags() [5/6]

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

Copy constructor.

◆ Flags() [6/6]

template<class T >
Flags ( Flags< T > &&  )
defaultnoexcept

◆ ~Flags()

template<class T >
~Flags ( )
defaultnoexcept

Member Function Documentation

◆ clear() [1/2]

template<class T >
bool clear ( )
inlinenoexcept

Clear all flags.

◆ clear() [2/2]

template<class T >
bool clear ( flag)
inlinenoexcept

Clear a single flag.

◆ from_string()

template<class T >
void from_string ( const std::string &  str)
inline

Convert from string.

Note
This will clear any existing flags first.

◆ operator&()

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

And operator.

◆ operator=() [1/2]

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

Assignment operator.

◆ operator=() [2/2]

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

◆ operator|()

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

Or operator.

◆ set() [1/2]

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

Set multiple flags.

◆ set() [2/2]

template<class T >
bool set ( flag)
inlinenoexcept

Set a single flag.

◆ to_string()

template<class T >
EGT_NODISCARD std::string to_string ( ) const
inline

Convert the flags to strings.

Member Data Documentation

◆ FLAGS_DELIMITER

template<class T >
constexpr const char FLAGS_DELIMITER = '|'
staticconstexpr

Delimiter used to separate flags in string representation.

◆ on_change

template<class T >
Signal on_change

Event signal.

Invoked when the flags are changed.