1.9
Public Types | Public Member Functions | Protected Attributes | List of all members
FlagsBase< T > Class Template Reference

Utility class for managing a set of flags. More...

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

Public Types

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

Public Member Functions

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 EGT_NODISCARD const 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...
 

Protected Attributes

Underlying m_flags {}
 The flags. More...
 

Detailed Description

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

Utility class for managing a set of 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.

Member Typedef Documentation

◆ Underlying

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.

Constructor & Destructor Documentation

◆ FlagsBase() [1/3]

constexpr FlagsBase ( )
constexprdefaultnoexcept

◆ FlagsBase() [2/3]

constexpr FlagsBase ( const T  flag)
inlineconstexprnoexcept

Construct with a single flag.

◆ FlagsBase() [3/3]

constexpr FlagsBase ( std::initializer_list< T >  flags)
inlineconstexprnoexcept

Construct with an initializer_list of flags.

Member Function Documentation

◆ clear() [1/2]

constexpr bool clear ( )
inlineconstexprnoexcept

Unset all flags.

Returns
true if changed.

◆ clear() [2/2]

constexpr bool clear ( const T  flag)
inlineconstexprnoexcept

Clear, or unset, the specified flag.

Parameters
flagFlag to clear.
Returns
True if the flag was deleted.

◆ empty()

constexpr EGT_NODISCARD bool empty ( ) const
inlineconstexprnoexcept

Returns true if there are no flags set.

Returns
true if no flags set.

◆ get()

EGT_NODISCARD std::set<T> get ( ) const
inline

Get a std::set of all set flags.

◆ is_set() [1/2]

constexpr EGT_NODISCARD bool is_set ( const T  flag) const
inlineconstexprnoexcept

Test if the specified flag is set.

Parameters
flagThe flag to test.

◆ is_set() [2/2]

constexpr EGT_NODISCARD bool is_set ( std::initializer_list< T >  flags) const
inlineconstexprnoexcept

Test if the specified flags are set.

All must be set to return true.

Parameters
flagsThe flags to test.

◆ raw() [1/2]

constexpr Underlying& raw ( )
inlineconstexpr

Get the raw underlying value.

◆ raw() [2/2]

constexpr EGT_NODISCARD const Underlying& raw ( ) const
inlineconstexpr

Get the raw underlying value.

◆ set() [1/2]

constexpr bool set ( const T  flag)
inlineconstexprnoexcept

Set the specified flag.

Parameters
flagThe flag to set.
Returns
True if a new item was added.

◆ set() [2/2]

constexpr bool set ( std::initializer_list< T >  flags)
inlineconstexprnoexcept

Set the specified flags.

Parameters
flagsFlags to set.
Returns
True if a new item was added.

Member Data Documentation

◆ m_flags

Underlying m_flags {}
protected

The flags.