xpcc
xpcc::Flags< Enum, T > Struct Template Reference

Class for operating on a register. More...

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

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

Public Types

typedef Enum EnumType
 The enum type.
 
- Public Types inherited from xpcc::FlagsOperators< Enum, T >
typedef Enum EnumType
 The enum type.
 
- Public Types inherited from xpcc::Register< T >
typedef T UnderlyingType
 The integer type internally used to represent the register.
 

Public Member Functions

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)
 default constructor initializes value to zero
 
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.
 
Flagsoperator= (Flags const &o)=default
 Copy assignment.
 
Flagsoperator= (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 value)
 Sets a single bit, when value is true, clears it otherwise.
 
void update (Flags const &o, bool value)
 Sets multiple bits, when value 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.
 
- Public Member Functions inherited from xpcc::FlagsOperators< Enum, T >
constexpr FlagsOperators operator~ () const
 bitwise negation
 
constexpr FlagsOperators ()
 default constructor initializes value to zero
 
constexpr FlagsOperators (Enum flag)
 constructs itself out of a strongly-typed enum
 
constexpr FlagsOperators (UnderlyingType flag)
 When explicitly called, this class constructs itself out of the underlying type.
 
constexpr FlagsOperators (Register< T > const &o)
 When explicitly called, this class constructs itself out of the superclass.
 
constexpr FlagsOperators (FlagsOperators const &o)=default
 Copy constructor.
 
constexpr FlagsOperators (FlagsOperators &&o)=default
 Move constructor.
 
FlagsOperatorsoperator= (FlagsOperators const &o)=default
 Copy assignment.
 
FlagsOperatorsoperator= (FlagsOperators &&o)=default
 Move assignment.
 
constexpr FlagsOperators operator & (FlagsOperators const &o) const
 bitwise AND with multiple bits
 
constexpr FlagsOperators operator| (FlagsOperators const &o) const
 bitwise OR with multiple bits
 
constexpr FlagsOperators operator^ (FlagsOperators const &o) const
 bitwise XOR with multiple bits
 
FlagsOperatorsoperator &= (FlagsOperators const &o)
 bitwise AND with multiple bits
 
FlagsOperatorsoperator|= (FlagsOperators const &o)
 bitwise OR with multiple bits
 
FlagsOperatorsoperator^= (FlagsOperators const &o)
 bitwise XOR with multiple bits
 
FlagsOperatorsoperator &= (Enum const &flag)
 bitwise AND with a single bit
 
FlagsOperatorsoperator|= (Enum const &flag)
 bitwise OR with a single bit
 
FlagsOperatorsoperator^= (Enum const &flag)
 bitwise XOR with a single bit
 
- Public Member Functions inherited from xpcc::Register< T >
constexpr Register ()
 Default constructor initializes value to zero.
 
constexpr operator bool () const
 Returns true if value is non-zero. More...
 
constexpr bool operator! () const
 Returns true if value is zero.
 

Additional Inherited Members

- Static Public Member Functions inherited from xpcc::FlagsOperators< Enum, T >
static constexpr FlagsOperators mask ()
 returns the mask of the integer type
 
- Public Attributes inherited from xpcc::Register< T >
UnderlyingType value
 The underlying integer value.
 
- Protected Member Functions inherited from xpcc::Register< T >
constexpr Register (UnderlyingType value)
 This class is meant to be subclassed.
 

Detailed Description

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

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 XPCC_FLAGS macro, which add the required external operator overloads for Enum OP Enum. The macro XPCC_FLAGS8(Enum) expands as follows:

typedef xpcc::Flags8<Enum> Enum_t;
XPCC_INT_TYPE_FLAGS(Enum_t);

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

typedef xpcc::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
XPCC_FLAGS8, XPCC_FLAGS16, XPCC_FLAGS32
Author
Niklas Hauser

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