Template Class SafeEnum

Class Documentation

template<class ENUM, class UNDERLYING = typename std::underlying_type<ENUM>::type>
class SafeEnum

This class allows us to handle flags easily, instead of using strings.

For example enum ControlMethod_ { NONE = 0, POSITION = (1 << 0), VELOCITY = (1 << 1), EFFORT = (1 << 2), }; typedef SafeEnum<enum ControlMethod_> ControlMethod;

ControlMethod foo; foo |= POSITION // Foo has the position flag active foo & POSITION -> True // Check if position is active in the flag foo & VELOCITY -> False // Check if velocity is active in the flag

Public Functions

inline SafeEnum()
inline explicit SafeEnum(ENUM singleFlag)
inline SafeEnum(const SafeEnum &original)
inline SafeEnum &operator|=(ENUM addValue)
inline SafeEnum operator|(ENUM addValue)
inline SafeEnum &operator&=(ENUM maskValue)
inline SafeEnum operator&(ENUM maskValue)
inline SafeEnum operator~()
inline explicit operator bool()

Protected Attributes

UNDERLYING mFlags