Circus 0.0.1-alpha
C++ Serialization Framework
Loading...
Searching...
No Matches
circus::utils::enum_flag< T > Class Template Reference

A utility class for strongly typed enum flags with bitwise operations. More...

#include <enum_flag.hpp>

Public Types

using enum_type = T
 Underlying enum type.
using underlying_type = typename std::underlying_type<T>::type
 Enum underlying integer type.

Public Member Functions

 enum_flag ()=default
 Default constructor initializes with no flags set.
 enum_flag (T initial)
 Constructs enum_flag with an initial flag value.
enum_flagoperator= (T flags)
 Assignment operator from enum type.
constexpr enum_flagoperator|= (T fs)
 Bitwise OR assignment operator to add flags.
constexpr enum_flagoperator&= (T fs)
 Bitwise AND assignment operator to mask flags.
template<typename U>
constexpr bool has (U e) const noexcept
 Checks if this enum_flag contains all bits of a given flag.
template<typename... Args>
constexpr bool has_any (Args &&...args) const noexcept
 Checks if this enum_flag contains any of the specified flags.
template<typename... Args>
constexpr bool has_all (Args &&...args) const noexcept
 Checks if this enum_flag contains all of the specified flags.
constexpr bool operator== (const enum_flag< T > &other) const noexcept
 Equality operator.
constexpr bool operator!= (const enum_flag< T > &other) const noexcept
 Inequality operator.
constexpr bool operator() () const noexcept
 Boolean conversion operator indicating if any flag is set.
 ~enum_flag ()=default
 Destructor.

Public Attributes

underlying_type flags {0x00u}
 Stores the bit flags as underlying integer type.

Detailed Description

template<typename T>
requires (traits::Flaggable<T>)
class circus::utils::enum_flag< T >

A utility class for strongly typed enum flags with bitwise operations.

Template Parameters
TEnum type that meets the traits::Flaggable concept (must be enum with underlying type uint32_t or uint64_t).

This class wraps an enum type and provides bitwise flag manipulation methods and checks such as has, has_any, and has_all.

Constructor & Destructor Documentation

◆ enum_flag()

template<typename T>
circus::utils::enum_flag< T >::enum_flag ( T initial)
inline

Constructs enum_flag with an initial flag value.

Parameters
initialEnum flag to initialize with.

Member Function Documentation

◆ has()

template<typename T>
template<typename U>
bool circus::utils::enum_flag< T >::has ( U e) const
inlinenodiscardconstexprnoexcept

Checks if this enum_flag contains all bits of a given flag.

Template Parameters
UEnum type (must be same as T).
Parameters
eEnum flag to check.
Returns
true if all bits are set, false otherwise.

◆ has_all()

template<typename T>
template<typename... Args>
bool circus::utils::enum_flag< T >::has_all ( Args &&... args) const
inlinenodiscardconstexprnoexcept

Checks if this enum_flag contains all of the specified flags.

Template Parameters
ArgsVariadic enum flags.
Parameters
argsFlags to check.
Returns
true if all flags are set, false otherwise.

◆ has_any()

template<typename T>
template<typename... Args>
bool circus::utils::enum_flag< T >::has_any ( Args &&... args) const
inlinenodiscardconstexprnoexcept

Checks if this enum_flag contains any of the specified flags.

Template Parameters
ArgsVariadic enum flags.
Parameters
argsFlags to check.
Returns
true if any flag is set, false otherwise.

◆ operator&=()

template<typename T>
enum_flag & circus::utils::enum_flag< T >::operator&= ( T fs)
inlineconstexpr

Bitwise AND assignment operator to mask flags.

Parameters
fsFlag mask to AND with current flags.
Returns
Reference to self.

◆ operator()()

template<typename T>
bool circus::utils::enum_flag< T >::operator() ( ) const
inlineconstexprnoexcept

Boolean conversion operator indicating if any flag is set.

Returns
true if any flag is set, false otherwise.

◆ operator=()

template<typename T>
enum_flag & circus::utils::enum_flag< T >::operator= ( T flags)
inline

Assignment operator from enum type.

Parameters
flagsEnum flags to assign.
Returns
Reference to self.

◆ operator|=()

template<typename T>
enum_flag & circus::utils::enum_flag< T >::operator|= ( T fs)
inlineconstexpr

Bitwise OR assignment operator to add flags.

Parameters
fsFlag to OR with current flags.
Returns
Reference to self.

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