Dataflow Runtime API  3.1.1.0
Public Member Functions | List of all members
imt::base::core::util::Flags< EnumType, BaseType > Class Template Reference

A template to create a type safe flags type from an enum. More...

#include <Imt.Base.Core.Util/Flags.h>

Public Member Functions

 Flags (void)
 Default constructor. More...
 
 Flags (const typename EnumType::Id flag)
 User defined constructor. More...
 
 Flags (const BaseType flags)
 User defined constructor. More...
 
 Flags (const Flags &other)
 Copy constructor. More...
 
virtual ~Flags (void)
 Destructor. More...
 
void set (const typename EnumType::Id flag)
 Sets the given flag. More...
 
void clear (const typename EnumType::Id flag)
 Clears the given flag. More...
 
bool isSet (const typename EnumType::Id flag) const
 Checks whether the given flag is set. More...
 
const BaseType & toInteger (void) const
 Returns the base type. More...
 
Flags combine (const Flags &other) const
 Combines the flags with another instance. More...
 
Flags intersect (const Flags &other) const
 Intersects the flags with another instance. More...
 
Flagsoperator= (const Flags &other)
 Assignment operator. More...
 
bool operator== (const Flags< EnumType, BaseType > &other) const
 Compare for equality operator. More...
 
bool operator!= (const Flags< EnumType, BaseType > &other) const
 Compare for equality operator. More...
 

Detailed Description

template<typename EnumType, typename BaseType = uint32_t>
class imt::base::core::util::Flags< EnumType, BaseType >

A template to create a type safe flags type from an enum.

Parameters
EnumTypeA struct that contains the flags and provides the following features: MIN The lowest possible flag (equals to 0). MAX The highest possible flag (equals to COUNT - 1). COUNT A constant that contains the number of flags in the struct. Id The actual enum with the flags. The enumerators must range from MIN to MAX
BaseTypeAn unsigned integer type that is large enough to fit the enum type
Note
The enum must not skip enumerators, if there are unused flags, add those but name them as unused.

Example for a well formed enum struct to pass as EnumType:

struct MyFlagEnum { enum Id { Bit1, _unused_Bit2, Bit3 };

static const uint32_t MIN = 0U; static const uint32_t MAX = static_cast<uint32_t>(Bit3); static const uint32_t COUNT = MAX + 1U; };

Constructor & Destructor Documentation

◆ Flags() [1/4]

template<typename EnumType , typename BaseType >
imt::base::core::util::Flags< EnumType, BaseType >::Flags ( void  )

Default constructor.

Creates an instance with no flag set.

◆ Flags() [2/4]

template<typename EnumType , typename BaseType >
imt::base::core::util::Flags< EnumType, BaseType >::Flags ( const typename EnumType::Id  flag)
explicit

User defined constructor.

Creates an instance with the given flag set.

Parameters
flagFlag.

◆ Flags() [3/4]

template<typename EnumType , typename BaseType >
imt::base::core::util::Flags< EnumType, BaseType >::Flags ( const BaseType  flags)
explicit

User defined constructor.

Creates an instance with the given base value.

Parameters
flagsFlags.

◆ Flags() [4/4]

template<typename EnumType , typename BaseType >
imt::base::core::util::Flags< EnumType, BaseType >::Flags ( const Flags< EnumType, BaseType > &  other)

Copy constructor.

Parameters
otherOther Flags object to copy.

◆ ~Flags()

template<typename EnumType , typename BaseType >
imt::base::core::util::Flags< EnumType, BaseType >::~Flags ( void  )
virtual

Destructor.

Member Function Documentation

◆ clear()

template<typename EnumType , typename BaseType >
void imt::base::core::util::Flags< EnumType, BaseType >::clear ( const typename EnumType::Id  flag)

Clears the given flag.

Parameters
flagFlag to clear.

◆ combine()

template<typename EnumType , typename BaseType >
Flags< EnumType, BaseType > imt::base::core::util::Flags< EnumType, BaseType >::combine ( const Flags< EnumType, BaseType > &  other) const

Combines the flags with another instance.

This will return a flags instance that has all flags set which are set in any of the given instances.

Parameters
otherOther flags to combine with.
Returns
Flags object with the combined flags set.

◆ intersect()

template<typename EnumType , typename BaseType >
Flags< EnumType, BaseType > imt::base::core::util::Flags< EnumType, BaseType >::intersect ( const Flags< EnumType, BaseType > &  other) const

Intersects the flags with another instance.

This will return a flags instance that has all flags set which are set in both of the given instances.

Parameters
otherOther flags to intersect with.
Returns
Flags object with the intersected flags set.

◆ isSet()

template<typename EnumType , typename BaseType >
bool imt::base::core::util::Flags< EnumType, BaseType >::isSet ( const typename EnumType::Id  flag) const

Checks whether the given flag is set.

Parameters
flagFlag to check.
Returns
True if flag is set.

◆ operator!=()

template<typename EnumType , typename BaseType >
bool imt::base::core::util::Flags< EnumType, BaseType >::operator!= ( const Flags< EnumType, BaseType > &  other) const

Compare for equality operator.

Will return true if at least one flags is not the same in both instances.

Parameters
otherOther flags to compare with.
Returns
True if flags are not equal.

◆ operator=()

template<typename EnumType , typename BaseType >
Flags< EnumType, BaseType > & imt::base::core::util::Flags< EnumType, BaseType >::operator= ( const Flags< EnumType, BaseType > &  other)

Assignment operator.

Parameters
otherOther flags to assign.
Returns
Reference to this Flag object.

◆ operator==()

template<typename EnumType , typename BaseType >
bool imt::base::core::util::Flags< EnumType, BaseType >::operator== ( const Flags< EnumType, BaseType > &  other) const

Compare for equality operator.

Will return true if exactly the same flags are set in both instances.

Parameters
otherOther flags to compare with.
Returns
True if flags are equal.

◆ set()

template<typename EnumType , typename BaseType >
void imt::base::core::util::Flags< EnumType, BaseType >::set ( const typename EnumType::Id  flag)

Sets the given flag.

Parameters
flagFlag to set.

◆ toInteger()

template<typename EnumType , typename BaseType >
const BaseType & imt::base::core::util::Flags< EnumType, BaseType >::toInteger ( void  ) const

Returns the base type.

Returns
Reference to BaseType representing the flags.

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