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

#include <flagsbase.h>

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.
 

Public Member Functions

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.
 

Protected Attributes

Underlying m_flags {}
 The flags.
 

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

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

Constructor & Destructor Documentation

◆ FlagsBase() [1/3]

template<class T >
constexpr FlagsBase ( )
constexprdefaultnoexcept

◆ FlagsBase() [2/3]

template<class T >
constexpr FlagsBase ( const T  flag)
inlineconstexprnoexcept

Construct with a single flag.

◆ FlagsBase() [3/3]

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

Construct with an initializer_list of flags.

Member Function Documentation

◆ clear() [1/2]

template<class T >
constexpr bool clear ( )
inlineconstexprnoexcept

Unset all flags.

Returns
true if changed.

◆ clear() [2/2]

template<class T >
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()

template<class T >
EGT_NODISCARD constexpr bool empty ( ) const
inlineconstexprnoexcept

Returns true if there are no flags set.

Returns
true if no flags set.

◆ get()

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

Get a std::set of all set flags.

◆ is_set() [1/2]

template<class T >
EGT_NODISCARD constexpr bool is_set ( const T  flag) const
inlineconstexprnoexcept

Test if the specified flag is set.

Parameters
flagThe flag to test.

◆ is_set() [2/2]

template<class T >
EGT_NODISCARD constexpr 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]

template<class T >
constexpr Underlying & raw ( )
inlineconstexpr

Get the raw underlying value.

◆ raw() [2/2]

template<class T >
EGT_NODISCARD constexpr const Underlying & raw ( ) const
inlineconstexpr

Get the raw underlying value.

◆ set() [1/2]

template<class T >
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]

template<class T >
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

template<class T >
Underlying m_flags {}
protected

The flags.