OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
ot::Flags< T > Class Template Reference

The Flags class is a wrapper around a enum that allows bitwise operations (flags). OT_ADD_FLAG_FUNCTIONS or custom bitwise operations must be provided for the enum. The type should be an enumeration where every value represents a single bit in a 32/64 bit value. More...

#include "Flags.h"

Public Member Functions

 Flags ()
 Data.
 
 Flags (T _initialData)
 Assignment constructor.
 
 Flags (const Flags< T > &_other)
 Copy constructor.
 
 Flags (Flags &&_other) noexcept
 Move constructor.
 
data (void) const
 Returns a copy of the data.
 
void set (T _data)
 Replace the current data.
 
void setFlag (T _flag)
 Set the provided flag.
 
void setFlag (T _flag, bool _flagIsSet)
 Set or remove the provided flag.
 
void removeFlag (T _flag)
 Remove the provided flag.
 
bool flagIsSet (T _flag) const
 Returns true if the provided flag is set.
 
 operator T (void) const
 Operator T is used to assign the Flags to a enum variable with the same type that is managed by Flags.
 
 operator bool (void) const
 Returns true if at least one flag is set (assuming 0 = no flags).
 
Flags< T > & operator= (T _flag)
 
Flags< T > & operator= (const Flags< T > &_other)
 
Flags< T > & operator= (Flags< T > &&_other)
 
Flags< T > operator| (T _flag) const
 
Flags< T > operator| (const Flags< T > &_other) const
 
Flags< T > operator& (T _flag) const
 
Flags< T > operator& (const Flags< T > &_other) const
 
Flags< T > & operator|= (T _flag)
 
Flags< T > & operator|= (const Flags< T > &_other)
 
Flags< T > & operator&= (T _flag)
 
Flags< T > & operator&= (const Flags< T > &_other)
 
Flags< T > operator~ (void) const
 
bool operator== (T _flag) const
 
bool operator== (const Flags< T > &_other) const
 
bool operator!= (T _flag) const
 
bool operator!= (const Flags< T > &_other) const
 

Detailed Description

template<typename T>
class ot::Flags< T >

The Flags class is a wrapper around a enum that allows bitwise operations (flags). OT_ADD_FLAG_FUNCTIONS or custom bitwise operations must be provided for the enum. The type should be an enumeration where every value represents a single bit in a 32/64 bit value.

// This enum contains values represeting single bits,
// or masks used for bitwise operations.
enum EnumName {
    // This should always be provided as somewhat of default value,
    // since ot::Flags<EnumName> will assume 0x00 to be the default.
    //                                   // +------+------+---------+
    //                                   // | Hex  | Bin  |  Info   |
    //                                   // +------+------+---------+
    EmptyFlags = 0 << 0,                 // | 0x00 | 0000 | Default |
    EnumValue1 = 1 << 0,                 // | 0x01 | 0001 | Value 1 |
    EnumValue2 = 1 << 1,                 // | 0x02 | 0010 | Value 2 |
    EnumMask1  = EnumValue1 | EnumValue2 // | 0x03 | 0011 | Mask 1  |
    EnumValue3 = 1 << 2,                 // | 0x04 | 0100 | Value 3 |
    ...                                  // +------+------+---------+
};
Note
Only enumration types are allowed. The enumerations should provided const expressions in the same (or higher) scope the flags are used at.

OT_ADD_FLAG_FUNCTIONS OT_ADD_FRIEND_FLAG_FUNCTIONS

Constructor & Destructor Documentation

◆ Flags() [1/4]

template<typename T >
ot::Flags< T >::Flags ( )
inline

Data.

Default constructor. Initializes the data with 0.

◆ Flags() [2/4]

template<typename T >
ot::Flags< T >::Flags ( T _initialData)
inline

Assignment constructor.

Parameters
_initialDataInitial data.

◆ Flags() [3/4]

template<typename T >
ot::Flags< T >::Flags ( const Flags< T > & _other)
inline

Copy constructor.

Parameters
_otherOther flags.

◆ Flags() [4/4]

template<typename T >
ot::Flags< T >::Flags ( Flags< T > && _other)
inlinenoexcept

Move constructor.

Parameters
_otherOther flags.

Member Function Documentation

◆ data()

template<typename T >
T ot::Flags< T >::data ( void ) const
inline

Returns a copy of the data.

◆ flagIsSet()

template<typename T >
bool ot::Flags< T >::flagIsSet ( T _flag) const
inline

Returns true if the provided flag is set.

Parameters
_flagthe flag that should be checked

◆ operator bool()

template<typename T >
ot::Flags< T >::operator bool ( void ) const
inline

Returns true if at least one flag is set (assuming 0 = no flags).

◆ operator T()

template<typename T >
ot::Flags< T >::operator T ( void ) const
inline

Operator T is used to assign the Flags to a enum variable with the same type that is managed by Flags.

◆ operator!=() [1/2]

template<typename T >
bool ot::Flags< T >::operator!= ( const Flags< T > & _other) const
inline

◆ operator!=() [2/2]

template<typename T >
bool ot::Flags< T >::operator!= ( T _flag) const
inline

◆ operator&() [1/2]

template<typename T >
Flags< T > ot::Flags< T >::operator& ( const Flags< T > & _other) const
inline

◆ operator&() [2/2]

template<typename T >
Flags< T > ot::Flags< T >::operator& ( T _flag) const
inline

◆ operator&=() [1/2]

template<typename T >
Flags< T > & ot::Flags< T >::operator&= ( const Flags< T > & _other)
inline

◆ operator&=() [2/2]

template<typename T >
Flags< T > & ot::Flags< T >::operator&= ( T _flag)
inline

◆ operator=() [1/3]

template<typename T >
Flags< T > & ot::Flags< T >::operator= ( const Flags< T > & _other)
inline

◆ operator=() [2/3]

template<typename T >
Flags< T > & ot::Flags< T >::operator= ( Flags< T > && _other)
inline

◆ operator=() [3/3]

template<typename T >
Flags< T > & ot::Flags< T >::operator= ( T _flag)
inline

◆ operator==() [1/2]

template<typename T >
bool ot::Flags< T >::operator== ( const Flags< T > & _other) const
inline

◆ operator==() [2/2]

template<typename T >
bool ot::Flags< T >::operator== ( T _flag) const
inline

◆ operator|() [1/2]

template<typename T >
Flags< T > ot::Flags< T >::operator| ( const Flags< T > & _other) const
inline

◆ operator|() [2/2]

template<typename T >
Flags< T > ot::Flags< T >::operator| ( T _flag) const
inline

◆ operator|=() [1/2]

template<typename T >
Flags< T > & ot::Flags< T >::operator|= ( const Flags< T > & _other)
inline

◆ operator|=() [2/2]

template<typename T >
Flags< T > & ot::Flags< T >::operator|= ( T _flag)
inline

◆ operator~()

template<typename T >
Flags< T > ot::Flags< T >::operator~ ( void ) const
inline

◆ removeFlag()

template<typename T >
void ot::Flags< T >::removeFlag ( T _flag)
inline

Remove the provided flag.

Parameters
_flagThe flag to remove

◆ set()

template<typename T >
void ot::Flags< T >::set ( T _data)
inline

Replace the current data.

Parameters
_dataThe data that should be replaced with

◆ setFlag() [1/2]

template<typename T >
void ot::Flags< T >::setFlag ( T _flag)
inline

Set the provided flag.

Parameters
_flagThe flag to set

◆ setFlag() [2/2]

template<typename T >
void ot::Flags< T >::setFlag ( T _flag,
bool _flagIsSet )
inline

Set or remove the provided flag.

Parameters
_flagThe flag to set
_flagIsSetIf true the flag will be set, otherwise removed

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