modm API documentation
modm::Flags< Enum, T > Struct Template Reference

#include <modm/architecture/interface/register.hpp>

Inheritance diagram for modm::Flags< Enum, T >:
modm::FlagsOperators< Enum, T > modm::Register< T >

Public Typedefs

typedef Enum EnumType
 The enum type.
 
typedef T UnderlyingType
 The integer type internally used to represent the register.
 

Public Member Functions

constexpr operator bool () const
 
constexpr bool operator! () const
 Returns true if value is zero.
 
constexpr FlagsOperators operator~ () const
 bitwise negation
 
constexpr FlagsOperators operator& (FlagsOperators const &o) const
 bitwise AND with multiple bits
 
constexpr FlagsOperators operator^ (FlagsOperators const &o) const
 bitwise XOR with multiple bits
 
constexpr FlagsOperators operator| (FlagsOperators const &o) const
 bitwise OR with multiple bits
 
FlagsOperatorsoperator&= (FlagsOperators const &o)
 bitwise AND with multiple bits
 
FlagsOperatorsoperator^= (FlagsOperators const &o)
 bitwise XOR with multiple bits
 
FlagsOperatorsoperator|= (FlagsOperators const &o)
 bitwise OR with multiple bits
 
FlagsOperatorsoperator&= (Enum const &flag)
 bitwise AND with a single bit
 
FlagsOperatorsoperator^= (Enum const &flag)
 bitwise XOR with a single bit
 
FlagsOperatorsoperator|= (Enum const &flag)
 bitwise OR with a single bit
 
constexpr Flags ()
 default constructor initializes value to zero
 
constexpr Flags (Enum flag)
 constructs itself out of a strongly-typed enum
 
constexpr Flags (FlagsOperators< Enum, T > const &flag)
 
constexpr Flags (UnderlyingType flag)
 When explicitly called, this class constructs itself out of the underlying type.
 
constexpr Flags (Register< T > const &o)
 When explicitly called, this class constructs itself out of the superclass.
 
constexpr Flags (Flags const &o) = default
 Copy constructor.
 
constexpr Flags (Flags &&o) = default
 Move constructor.
 
Flags & operator= (Flags const &o) = default
 Copy assignment.
 
Flags & operator= (Flags &&o) = default
 Move assignment.
 
void set (Enum const &flag)
 Sets a single bit.
 
void set (Flags const &o)
 Sets multiple bits.
 
void reset (Enum const &flag)
 Clears a single bit.
 
void reset (Flags const &o)
 Clears multiple bits.
 
void toggle (Enum const &flag)
 Toggles a single bit.
 
void toggle (Flags const &o)
 Toggles multiple bits.
 
void update (Enum const &flag, bool valueToCompare)
 Sets a single bit, when valueToCompare is true, clears it otherwise.
 
void update (Flags const &o, bool valueToCompare)
 Sets multiple bits, when valueToCompare is true, clears them otherwise.
 
constexpr bool all (Enum const &flag) const
 Returns true if bit is set.
 
constexpr bool any (Enum const &flag) const
 Returns true if bit is set.
 
constexpr bool none (Enum const &flag) const
 Returns true if bit is not set.
 
constexpr bool all (Flags const &o) const
 Returns true if all of the passed bits are set.
 
constexpr bool any (Flags const &o) const
 Returns true if any of the passed bits are set.
 
constexpr bool none (Flags const &o) const
 Returns true if none of the passed bits are set.
 

Static Public Member Functions

static constexpr FlagsOperators mask ()
 returns the mask of the integer type
 

Public Attributes

UnderlyingType value
 The underlying integer value.
 

Detailed Description

template<typename Enum, typename T>
struct modm::Flags< Enum, T >

Class for operating on a register.

This class extends the FlagsOperators base class by adding constructor overloading and convenience functions between a strongly-typed enum and itself.

This class makes heavy use of constexpr, so that as many values and operation can take place at compile time for efficiency.

Unfortunately, you cannot typedef this class directly, you must use the MODM_FLAGS macro, which add the required external operator overloads for Enum OP Enum. The macro MODM_FLAGS8(Enum) expands as follows:

typedef modm::Flags8<Enum> Enum_t;
MODM_INT_TYPE_FLAGS(Enum_t);

The MODM_FLAGS macro by default only works in a class or struct, as this is the primary use-case in modm. To use it outside of a struct, use this:

typedef modm::Flags8<Enum> Enum_t;
Template Parameters
Enuma strongly-typed enum containing the bit masks
Tthe underlying integer type to be for internal representation
See also
Flags8, Flags16, Flags32
MODM_FLAGS8, MODM_FLAGS16, MODM_FLAGS32
Author
Niklas Hauser

Member Function Documentation

template<typename T >
constexpr modm::Register< T >::operator bool ( ) const
inheritedinlineexplicitconstexpr

Returns true if value is non-zero

The compiler will allow implicit conversions to bool in the following contexts:

  • conditions of if, while, for, do-while statements
  • logical operators (&&, ||)
  • negation (operator !)
  • static_assert

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