Dune::Copasi
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
Dune::Copasi::BitFlags< Enum > Class Template Reference

Bit flags for enumerators. More...

#include <bit_flags.hh>

Public Member Functions

constexpr BitFlags ()
 Default constructor.
 
constexpr BitFlags (const Enum &value)
 Enum constructor.
 
 BitFlags (const BitSet &bit_set)
 Bit set constructor.
 
constexpr BitSet as_bitset () const
 Return bitflag as bitset.
 
constexpr UnderlyingType as_underlying () const
 Return bitflag as its underlying type.
 
constexpr UnderlyingType & as_underlying ()
 Return bitflag as its underlying type.
 
constexpr Enum as_enum () const
 Return bitflag as its underlying enum.
 
constexpr Enumas_enum ()
 Return bitflag as its underlying enum.
 
constexpr operator Enum () const
 Implicit conversion to underlying enum.
 
constexpr BitFlags operator| (const BitFlags &rhs) const
 Bitwise or operator with another bitflag.
 
constexpr BitFlags operator& (const BitFlags &rhs) const
 Bitwise and operator with another bitflag.
 
constexpr BitFlags operator^ (const BitFlags &rhs) const
 Bitwise xor operator with another bitflag.
 
constexpr BitFlags operator<< (std::size_t pos) const
 Bitwise left shift operator.
 
constexpr BitFlags operator>> (std::size_t pos) const
 Bitwise right shift operator.
 
BitFlagsoperator|= (const BitFlags &rhs)
 Bitwise or operator with this bitflag.
 
BitFlagsoperator&= (const BitFlags &rhs)
 Bitwise and operator with this bitflag.
 
BitFlagsoperator^= (const BitFlags &rhs)
 Bitwise xor operator with this bitflag.
 
BitFlagsoperator<<= (std::size_t pos)
 Bitwise left shift operator with this bitflag.
 
BitFlagsoperator>>= (std::size_t pos)
 Bitwise right shift operator with this bitflag.
 
constexpr BitFlags operator~ () const
 Bitwise not operator of this bitflag.
 
constexpr bool test (const BitFlags &flag) const
 Test if the required flag is active in the bitflag.
 
void reset (const BitFlags &flag)
 Reset the required flags in the bitflag.
 
void set (const BitFlags &flag, bool value=true)
 Set the required flags to true.
 
void flip (const BitFlags &flag)
 Flip the required flags.
 
constexpr bool all () const
 Checks if all flags are set to true.
 
constexpr bool any () const
 Checks if any flags are set to true.
 
constexpr bool none () const
 Checks if none flags are set to true.
 

Static Public Member Functions

static constexpr BitFlags< Enumall_flags ()
 Bitflag with all flags turned on.
 
static constexpr BitFlags< Enumno_flags ()
 Bitflag with all flags turned off.
 

Detailed Description

template<typename Enum>
class Dune::Copasi::BitFlags< Enum >

Bit flags for enumerators.

This class allows that an enum can be operated as a bit set of flags. When an enum is a bit flags (see is_bitflags) most operators expected for bits are enabled to operate directly on that enum. This object is different than a std::bitset because it is fully constexpr and because operators on the underlying enum are automatic.

// Notice that each option correspond to a different bit
enum class MyEnum {option_a = 0b01, option_b = 0b10};
// `my_enum` is deduced as `BitFlags<MyEnum>` type because operator | on
// `MyEnum` was overloaded to do so
auto my_enum = MyEnum::option_a | MyEnum::option_b;
assert(my_enum.test(MyEnum::option_a));
constexpr bool is_bitflags_v
Alias for Bitflag indicator.
Definition bit_flags.hh:24
See also
is_bitflags
Template Parameters
EnumEnumerator to be converted into a bit flag

Constructor & Destructor Documentation

◆ BitFlags() [1/3]

template<typename Enum >
constexpr Dune::Copasi::BitFlags< Enum >::BitFlags ( )
inlineconstexpr

Default constructor.

◆ BitFlags() [2/3]

template<typename Enum >
constexpr Dune::Copasi::BitFlags< Enum >::BitFlags ( const Enum & value)
inlineconstexpr

Enum constructor.

◆ BitFlags() [3/3]

template<typename Enum >
Dune::Copasi::BitFlags< Enum >::BitFlags ( const BitSet & bit_set)
inlineexplicit

Bit set constructor.

Member Function Documentation

◆ all()

template<typename Enum >
constexpr bool Dune::Copasi::BitFlags< Enum >::all ( ) const
inlineconstexpr

Checks if all flags are set to true.

◆ all_flags()

template<typename Enum >
static constexpr BitFlags< Enum > Dune::Copasi::BitFlags< Enum >::all_flags ( )
inlinestaticconstexpr

Bitflag with all flags turned on.

◆ any()

template<typename Enum >
constexpr bool Dune::Copasi::BitFlags< Enum >::any ( ) const
inlineconstexpr

Checks if any flags are set to true.

◆ as_bitset()

template<typename Enum >
constexpr BitSet Dune::Copasi::BitFlags< Enum >::as_bitset ( ) const
inlineconstexpr

Return bitflag as bitset.

◆ as_enum() [1/2]

template<typename Enum >
constexpr Enum & Dune::Copasi::BitFlags< Enum >::as_enum ( )
inlineconstexpr

Return bitflag as its underlying enum.

◆ as_enum() [2/2]

template<typename Enum >
constexpr Enum Dune::Copasi::BitFlags< Enum >::as_enum ( ) const
inlineconstexpr

Return bitflag as its underlying enum.

◆ as_underlying() [1/2]

template<typename Enum >
constexpr UnderlyingType & Dune::Copasi::BitFlags< Enum >::as_underlying ( )
inlineconstexpr

Return bitflag as its underlying type.

◆ as_underlying() [2/2]

template<typename Enum >
constexpr UnderlyingType Dune::Copasi::BitFlags< Enum >::as_underlying ( ) const
inlineconstexpr

Return bitflag as its underlying type.

◆ flip()

template<typename Enum >
void Dune::Copasi::BitFlags< Enum >::flip ( const BitFlags< Enum > & flag)
inline

Flip the required flags.

◆ no_flags()

template<typename Enum >
static constexpr BitFlags< Enum > Dune::Copasi::BitFlags< Enum >::no_flags ( )
inlinestaticconstexpr

Bitflag with all flags turned off.

◆ none()

template<typename Enum >
constexpr bool Dune::Copasi::BitFlags< Enum >::none ( ) const
inlineconstexpr

Checks if none flags are set to true.

◆ operator Enum()

template<typename Enum >
constexpr Dune::Copasi::BitFlags< Enum >::operator Enum ( ) const
inlineexplicitconstexpr

Implicit conversion to underlying enum.

◆ operator&()

template<typename Enum >
constexpr BitFlags Dune::Copasi::BitFlags< Enum >::operator& ( const BitFlags< Enum > & rhs) const
inlineconstexpr

Bitwise and operator with another bitflag.

◆ operator&=()

Bitwise and operator with this bitflag.

◆ operator<<()

template<typename Enum >
constexpr BitFlags Dune::Copasi::BitFlags< Enum >::operator<< ( std::size_t pos) const
inlineconstexpr

Bitwise left shift operator.

◆ operator<<=()

template<typename Enum >
BitFlags & Dune::Copasi::BitFlags< Enum >::operator<<= ( std::size_t pos)
inline

Bitwise left shift operator with this bitflag.

◆ operator>>()

template<typename Enum >
constexpr BitFlags Dune::Copasi::BitFlags< Enum >::operator>> ( std::size_t pos) const
inlineconstexpr

Bitwise right shift operator.

◆ operator>>=()

template<typename Enum >
BitFlags & Dune::Copasi::BitFlags< Enum >::operator>>= ( std::size_t pos)
inline

Bitwise right shift operator with this bitflag.

◆ operator^()

template<typename Enum >
constexpr BitFlags Dune::Copasi::BitFlags< Enum >::operator^ ( const BitFlags< Enum > & rhs) const
inlineconstexpr

Bitwise xor operator with another bitflag.

◆ operator^=()

Bitwise xor operator with this bitflag.

◆ operator|()

template<typename Enum >
constexpr BitFlags Dune::Copasi::BitFlags< Enum >::operator| ( const BitFlags< Enum > & rhs) const
inlineconstexpr

Bitwise or operator with another bitflag.

◆ operator|=()

Bitwise or operator with this bitflag.

◆ operator~()

template<typename Enum >
constexpr BitFlags Dune::Copasi::BitFlags< Enum >::operator~ ( ) const
inlineconstexpr

Bitwise not operator of this bitflag.

◆ reset()

template<typename Enum >
void Dune::Copasi::BitFlags< Enum >::reset ( const BitFlags< Enum > & flag)
inline

Reset the required flags in the bitflag.

◆ set()

template<typename Enum >
void Dune::Copasi::BitFlags< Enum >::set ( const BitFlags< Enum > & flag,
bool value = true )
inline

Set the required flags to true.

◆ test()

template<typename Enum >
constexpr bool Dune::Copasi::BitFlags< Enum >::test ( const BitFlags< Enum > & flag) const
inlineconstexpr

Test if the required flag is active in the bitflag.


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