Template Class Flags
Defined in File flags.hpp
Class Documentation
-
template<typename Enum>
class Flags Convenience class for organising boolean flags.
This class organises a group of flags (via enums) in a convenient and typesafe manner. It is essentially a container for flags (in the form of enums) with a convenient interface on top.
Usage:
Define an appropriate bit-arithmetic enum.
enum Settings { Fast 0x0001, Medium 0x0002, Slow 0x0004, Red 0x0010, Blue 0x0020 }
Pipe flags into the enum
settings = settings|Fast|Slow;
Set up a friend operator on the enum type for more convenient piping (see the dox).
Use one of the variety of mask/compliment/access operators for handling (see method documentation).
Public Functions
-
inline Flags()
-
inline ~Flags()
Raw constructor.
-
inline void clear()
Clear all flags.
-
inline operator int() const
-
inline Flags<Enum> operator&(int mask) const
Type compatibility with ints. Mask operator.
- Returns:
Flags<Enum> : new instance of the flag set.
-
inline Flags<Enum> operator&(Enum flag) const
Single flag masking operator.
- Returns:
Flags<Enum> : new instance of the flag set.
-
inline Flags<Enum> operator|(Flags<Enum> other) const
OR operator.
- Returns:
Flags<Enum> : new instance of the flag set.
-
inline Flags<Enum> operator|(Enum flag) const
Single flag OR operator.
- Returns:
Flags<Enum> : new instance of the flag set.
-
inline Flags<Enum> operator^(Flags<Enum> other) const
XOR operator.
- Returns:
Flags<Enum> : new instance of the flag set.
-
inline Flags<Enum> operator^(Enum flag) const
Single flag XOR operator.
- Returns:
Flags<Enum> : new instance of the flag set.
-
inline Flags<Enum> operator~() const
Complement operator.
- Returns:
Flags<Enum> : new instance of the flag set.
-
inline Flags<Enum> &operator=(const Flags<Enum> &other)
Assignment operator.
- Returns:
Flags<Enum> : updated instance of the flag set.
-
inline Flags<Enum> &operator=(const Enum &flag)
Assignment operator.
- Returns:
Flags<Enum> : updated instance of the flag set.
-
inline Flags<Enum> &operator&=(int mask)
Self operating mask.
- Returns:
Flags<Enum> : updated instance of the masked flag set.
-
inline Flags<Enum> &operator|=(Flags<Enum> other)
Self operating OR operation.
- Returns:
Flags<Enum> : updated instance of the masked flag set.
-
inline Flags<Enum> &operator|=(Enum flag)
Self operating OR operation with a single flag.
- Returns:
Flags<Enum> : updated instance of the masked flag set.