rttr::enum_flags< Enum > Class Template Reference

The enum_flags class template is used to store OR-combinations of enum values in a type-safe way. More...

#include <enum_flags.h>

Public Types

using enum_type
 
using type = Enum
 
using zero = enum_type*
 

Public Member Functions

constexpr enum_flags (detail::enum_flag v) noexcept
 Creates an enum_flags object initialized with the given integer value value.
 
constexpr enum_flags (Enum flag) noexcept
 Creates a enum_flags object with the given flag flag.
 
constexpr enum_flags (zero=nullptr) noexcept
 Creates an enum_flags object with no flags set.
 
constexpr operator enum_type () const noexcept
 Performs a bitwise XOR operation with f and store the result in this object.
 
constexpr bool operator! () const noexcept
 This will test whether a flag was set or not.
 
constexpr enum_flags operator& (Enum f) const noexcept
 Performs a bitwise AND operation on this object and f and return the result as new enum_flags object.
 
constexpr enum_flags operator& (int mask) const noexcept
 Performs a bitwise AND operation on this object and mask and return the result as new enum_flags object.
 
constexpr enum_flags operator& (uint32_t mask) const noexcept
 Performs a bitwise AND operation on this object and mask and return the result as new enum_flags object.
 
constexpr enum_flagsoperator&= (Enum mask) noexcept
 Performs a bitwise AND operation with mask and store the result in this object.
 
constexpr enum_flagsoperator&= (int mask) noexcept
 Performs a bitwise AND operation with mask and store the result in this object.
 
constexpr enum_flagsoperator&= (uint32_t mask) noexcept
 Performs a bitwise AND operation with mask and store the result in this object.
 
constexpr enum_flags operator^ (Enum f) const noexcept
 Performs a bitwise XOR operation on this object and f and return the result as new enum_flags object.
 
constexpr enum_flags operator^ (enum_flags f) const noexcept
 Performs a bitwise XOR operation on this object and f and return the result as new enum_flags object.
 
constexpr enum_flagsoperator^= (Enum f) noexcept
 Performs a bitwise XOR operation with f and store the result in this object.
 
constexpr enum_flagsoperator^= (enum_flags f) noexcept
 Performs a bitwise XOR operation with f and store the result in this object.
 
constexpr enum_flags operator| (Enum f) const noexcept
 Performs a bitwise OR operation on this object and f and return the result as new enum_flags object.
 
constexpr enum_flags operator| (enum_flags f) const noexcept
 Performs a bitwise OR operation on this object and f and return the result as new enum_flags object.
 
constexpr enum_flagsoperator|= (Enum f) noexcept
 Performs a bitwise OR operation with f and store the result in this object.
 
constexpr enum_flagsoperator|= (enum_flags f) noexcept
 Performs a bitwise OR operation with f and store the result in this object.
 
constexpr enum_flags operator~ () const noexcept
 Performs a bitwise negation of the current object and return the result as new enum_flags object.
 
constexpr bool test_flag (Enum flag) const noexcept
 This will test whether the given flag flag was set.
 

Detailed Description

template<typename Enum>
class rttr::enum_flags< Enum >

The enum_flags class template is used to store OR-combinations of enum values in a type-safe way.

The values are stored internally inside an integer (unsigned or signed, depending on the underlying type of the enum). Using values from other enums or raw integer (except 0) with this class will result in a compile time error.

In order to use this class with your own enum, use RTTR_DECLARE_FLAGS() and RTTR_DECLARE_ENUM_FLAGS_OPERATORS().

Typical Usage

enum class my_option
{
OPTION_1 = 1,
OPTION_2 = 2,
OPTION_3 = 4,
};
{
if (flags.test_flag(my_option::OPTION_1)
{
// ...
}
if (flags.test_flag(my_option::OPTION_2)
{
// ...
}
}
The array_range class provides a view into an underlying data structure with lower and upper limits.
Definition array_range.h:64
#define RTTR_DECLARE_FLAGS(Flags, Enum)
This macro expands to:
Definition enum_flags.h:294
#define RTTR_DECLARE_ENUM_FLAGS_OPERATORS(Flags)
This macro declares the a global operator | for enums of type enum_flags<T>
Definition enum_flags.h:301

Member Typedef Documentation

◆ enum_type

template<typename Enum >
using rttr::enum_flags< Enum >::enum_type
Initial value:
detail::conditional_t<std::is_signed<typename std::underlying_type<Enum>::type>::value,
int32_t,
uint32_t>
detail::enum_data< Enum_Type > value(string_view, Enum_Type value)
The value function should be used to add a mapping from enum name to value during the registration pr...

◆ type

template<typename Enum >
using rttr::enum_flags< Enum >::type = Enum

◆ zero

Constructor & Destructor Documentation

◆ enum_flags() [1/3]

template<typename Enum >
constexpr rttr::enum_flags< Enum >::enum_flags ( zero = nullptr)
constexprnoexcept

Creates an enum_flags object with no flags set.

◆ enum_flags() [2/3]

template<typename Enum >
constexpr rttr::enum_flags< Enum >::enum_flags ( Enum flag)
constexprnoexcept

Creates a enum_flags object with the given flag flag.

◆ enum_flags() [3/3]

template<typename Enum >
constexpr rttr::enum_flags< Enum >::enum_flags ( detail::enum_flag v)
constexprnoexcept

Creates an enum_flags object initialized with the given integer value value.

Remarks
enum_flag is a wrapper class around an integer to avoid creation of enum_flags object from enum values.

Member Function Documentation

◆ operator enum_type()

template<typename Enum >
constexpr rttr::enum_flags< Enum >::operator enum_type ( ) const
constexprnoexcept

Performs a bitwise XOR operation with f and store the result in this object.

Returns
A reference to this object.

◆ operator!()

template<typename Enum >
constexpr bool rttr::enum_flags< Enum >::operator! ( ) const
constexprnoexcept

This will test whether a flag was set or not.

Returns
true, when no flag is set, otherwise false.

◆ operator&() [1/3]

template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator& ( Enum f) const
constexprnoexcept

Performs a bitwise AND operation on this object and f and return the result as new enum_flags object.

Returns
A enum_flags object containing the result of the bitwise AND operation on this object and f.

◆ operator&() [2/3]

template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator& ( int mask) const
constexprnoexcept

Performs a bitwise AND operation on this object and mask and return the result as new enum_flags object.

Returns
A enum_flags object containing the result of the bitwise AND operation on this object and mask.

◆ operator&() [3/3]

template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator& ( uint32_t mask) const
constexprnoexcept

Performs a bitwise AND operation on this object and mask and return the result as new enum_flags object.

Returns
A enum_flags object containing the result of the bitwise AND operation on this object and mask.

◆ operator&=() [1/3]

template<typename Enum >
constexpr enum_flags & rttr::enum_flags< Enum >::operator&= ( Enum mask)
constexprnoexcept

Performs a bitwise AND operation with mask and store the result in this object.

Returns
A reference to this object.

◆ operator&=() [2/3]

template<typename Enum >
constexpr enum_flags & rttr::enum_flags< Enum >::operator&= ( int mask)
constexprnoexcept

Performs a bitwise AND operation with mask and store the result in this object.

Returns
A reference to this object.

◆ operator&=() [3/3]

template<typename Enum >
constexpr enum_flags & rttr::enum_flags< Enum >::operator&= ( uint32_t mask)
constexprnoexcept

Performs a bitwise AND operation with mask and store the result in this object.

Returns
A reference to this object.

◆ operator^() [1/2]

template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator^ ( Enum f) const
constexprnoexcept

Performs a bitwise XOR operation on this object and f and return the result as new enum_flags object.

Returns
A enum_flags object containing the result of the bitwise XOR operation on this object and f.

◆ operator^() [2/2]

template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator^ ( enum_flags< Enum > f) const
constexprnoexcept

Performs a bitwise XOR operation on this object and f and return the result as new enum_flags object.

Returns
A enum_flags object containing the result of the bitwise XOR operation on this object and f.

◆ operator^=() [1/2]

template<typename Enum >
constexpr enum_flags & rttr::enum_flags< Enum >::operator^= ( Enum f)
constexprnoexcept

Performs a bitwise XOR operation with f and store the result in this object.

Returns
A reference to this object.

◆ operator^=() [2/2]

template<typename Enum >
constexpr enum_flags & rttr::enum_flags< Enum >::operator^= ( enum_flags< Enum > f)
constexprnoexcept

Performs a bitwise XOR operation with f and store the result in this object.

Returns
A reference to this object.

◆ operator|() [1/2]

template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator| ( Enum f) const
constexprnoexcept

Performs a bitwise OR operation on this object and f and return the result as new enum_flags object.

Returns
A enum_flags object containing the result of the bitwise OR operation on this object and f.

◆ operator|() [2/2]

template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator| ( enum_flags< Enum > f) const
constexprnoexcept

Performs a bitwise OR operation on this object and f and return the result as new enum_flags object.

Returns
A enum_flags object containing the result of the bitwise OR operation on this object and f.

◆ operator|=() [1/2]

template<typename Enum >
constexpr enum_flags & rttr::enum_flags< Enum >::operator|= ( Enum f)
constexprnoexcept

Performs a bitwise OR operation with f and store the result in this object.

Returns
A reference to this object.

◆ operator|=() [2/2]

template<typename Enum >
constexpr enum_flags & rttr::enum_flags< Enum >::operator|= ( enum_flags< Enum > f)
constexprnoexcept

Performs a bitwise OR operation with f and store the result in this object.

Returns
A reference to this object.

◆ operator~()

template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator~ ( ) const
constexprnoexcept

Performs a bitwise negation of the current object and return the result as new enum_flags object.

Returns
A enum_flags object that contains the bitwise negation of this object.

◆ test_flag()

template<typename Enum >
constexpr bool rttr::enum_flags< Enum >::test_flag ( Enum flag) const
constexprnoexcept

This will test whether the given flag flag was set.

Returns
true, when the flag is set, otherwise false.

The documentation for this class was generated from the following file: