rttr::enum_flags< Enum > Class Template - 0.9.6 |RTTR
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 = detail::conditional_t< std::is_signed< typename std::underlying_type< Enum >::type >::value, int32_t, uint32_t >
 
using type = Enum
 
using zero = enum_type *
 

Public Member Functions

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

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
{
ALL_DISABLED = 0,
OPTION_1 = 1,
OPTION_2 = 2,
OPTION_3 = 4,
OPTION_4 = 8
};
RTTR_DECLARE_FLAGS(my_options, my_option)
void my_func(my_options flags)
{
if (flags.test_flag(my_option::OPTION_1)
{
// ...
}
if (flags.test_flag(my_option::OPTION_2)
{
// ...
}
}

Member Typedef Documentation

template<typename Enum >
using rttr::enum_flags< Enum >::enum_type = detail::conditional_t<std::is_signed<typename std::underlying_type<Enum>::type>::value, int32_t, uint32_t>
template<typename Enum >
using rttr::enum_flags< Enum >::type = Enum
template<typename Enum >
using rttr::enum_flags< Enum >::zero = enum_type*

Constructor & Destructor Documentation

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

Creates an enum_flags object with no flags set.

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

Creates a enum_flags object with the given flag flag.

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

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

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

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

Returns
A reference to this object.
template<typename Enum >
constexpr bool rttr::enum_flags< Enum >::operator! ( ) const
noexcept

This will test whether a flag was set or not.

Returns
true, when no flag is set, otherwise false.
template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator& ( Enum  f) const
noexcept

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.
template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator& ( int  mask) const
noexcept

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.
template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::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.

Returns
A enum_flags object containing the result of the bitwise AND operation on this object and mask.
template<typename Enum >
constexpr enum_flags& rttr::enum_flags< Enum >::operator&= ( int  mask)
noexcept

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

Returns
A reference to this object.
template<typename Enum >
constexpr enum_flags& rttr::enum_flags< Enum >::operator&= ( uint32_t  mask)
noexcept

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

Returns
A reference to this object.
template<typename Enum >
constexpr enum_flags& rttr::enum_flags< Enum >::operator&= ( Enum  mask)
noexcept

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

Returns
A reference to this object.
template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator^ ( Enum  f) const
noexcept

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.
template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator^ ( enum_flags< Enum >  f) const
noexcept

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.
template<typename Enum >
constexpr enum_flags& rttr::enum_flags< Enum >::operator^= ( enum_flags< Enum >  f)
noexcept

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

Returns
A reference to this object.
template<typename Enum >
constexpr enum_flags& rttr::enum_flags< Enum >::operator^= ( Enum  f)
noexcept

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

Returns
A reference to this object.
template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator| ( Enum  f) const
noexcept

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.
template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator| ( enum_flags< Enum >  f) const
noexcept

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.
template<typename Enum >
constexpr enum_flags& rttr::enum_flags< Enum >::operator|= ( enum_flags< Enum >  f)
noexcept

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

Returns
A reference to this object.
template<typename Enum >
constexpr enum_flags& rttr::enum_flags< Enum >::operator|= ( Enum  f)
noexcept

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

Returns
A reference to this object.
template<typename Enum >
constexpr enum_flags rttr::enum_flags< Enum >::operator~ ( ) const
noexcept

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.
template<typename Enum >
constexpr bool rttr::enum_flags< Enum >::test_flag ( Enum  flag) const
noexcept

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: