SPH
Public Member Functions | Static Public Member Functions | List of all members
Flags< TEnum > Class Template Reference

Wrapper of an integral value providing functions for reading and modifying individual bits. More...

#include <Flags.h>

Public Member Functions

constexpr Flags ()=default
 Constructs empty flags. More...
 
constexpr Flags (const Flags &other)
 Constucts flags by copying other object. More...
 
template<typename... TArgs>
constexpr Flags (const TEnum flag, const TArgs... others)
 Constructs object given a list of flags. More...
 
constexpr Flags (const EmptyFlags)
 Constructs empty flags. More...
 
Flagsoperator= (const Flags &other)
 Copies other Flags object. More...
 
Flagsoperator= (const TEnum flag)
 Assigns a single flag, all previous flags are deleted. More...
 
Flagsoperator= (const EmptyFlags)
 Deletes all flags. More...
 
constexpr INLINE bool has (const TEnum flag) const
 Checks if the object has a given flag. More...
 
template<typename... TArgs>
constexpr INLINE bool hasAny (const TEnum flag, const TArgs... others) const
 Checks if the object has any of given flags. More...
 
template<typename... TArgs>
constexpr INLINE bool hasAll (const TEnum flag, const TArgs... others) const
 Checks if the object has all of given flags. More...
 
INLINE void set (const TEnum flag)
 Adds a single flag into the object. All previously stored flags are kept unchanged. More...
 
INLINE void unset (const TEnum flag)
 Removed a single flag. More...
 
INLINE void setIf (const TEnum flag, const bool use)
 Sets or removes given flag based given boolean value. More...
 
INLINE TValue value () const
 Returns the underlying value. More...
 
constexpr INLINE Flags operator| (const TEnum flag) const
 Returns a Flags object by adding a single flag to currently stored values. More...
 
INLINE bool operator== (const Flags &other) const
 Checks for equality with other Flags object. More...
 
INLINE bool operator!= (const Flags &other) const
 Checks for inequality with other Flags object. More...
 

Static Public Member Functions

constexpr static Flags fromValue (const TValue value)
 Constructs object from underlying value. More...
 

Detailed Description

template<typename TEnum>
class Flags< TEnum >

Wrapper of an integral value providing functions for reading and modifying individual bits.

Definition at line 20 of file Flags.h.

Constructor & Destructor Documentation

◆ Flags() [1/4]

template<typename TEnum >
constexpr Flags< TEnum >::Flags ( )
constexprdefault

Constructs empty flags.

◆ Flags() [2/4]

template<typename TEnum >
constexpr Flags< TEnum >::Flags ( const Flags< TEnum > &  other)
inlineconstexpr

Constucts flags by copying other object.

Definition at line 30 of file Flags.h.

◆ Flags() [3/4]

template<typename TEnum >
template<typename... TArgs>
constexpr Flags< TEnum >::Flags ( const TEnum  flag,
const TArgs...  others 
)
inlineconstexpr

Constructs object given a list of flags.

Every parameter must be a power of 2, checked by assert.

Definition at line 37 of file Flags.h.

◆ Flags() [4/4]

template<typename TEnum >
constexpr Flags< TEnum >::Flags ( const  EmptyFlags)
inlineconstexpr

Constructs empty flags.

Use global constant EMPTY_FLAGS to construct empty Flags object.

Definition at line 43 of file Flags.h.

Member Function Documentation

◆ fromValue()

template<typename TEnum >
constexpr static Flags Flags< TEnum >::fromValue ( const TValue  value)
inlinestaticconstexpr

Constructs object from underlying value.

Useful when using flags as a parameter in settings. Does not check if the input value can be represented by TEnum flags, use sparingly.

Definition at line 49 of file Flags.h.

◆ has()

template<typename TEnum >
constexpr INLINE bool Flags< TEnum >::has ( const TEnum  flag) const
inlineconstexpr

Checks if the object has a given flag.

Definition at line 77 of file Flags.h.

◆ hasAll()

template<typename TEnum >
template<typename... TArgs>
constexpr INLINE bool Flags< TEnum >::hasAll ( const TEnum  flag,
const TArgs...  others 
) const
inlineconstexpr

Checks if the object has all of given flags.

Definition at line 89 of file Flags.h.

◆ hasAny()

template<typename TEnum >
template<typename... TArgs>
constexpr INLINE bool Flags< TEnum >::hasAny ( const TEnum  flag,
const TArgs...  others 
) const
inlineconstexpr

Checks if the object has any of given flags.

Definition at line 83 of file Flags.h.

◆ operator!=()

template<typename TEnum >
INLINE bool Flags< TEnum >::operator!= ( const Flags< TEnum > &  other) const
inline

Checks for inequality with other Flags object.

Definition at line 136 of file Flags.h.

◆ operator=() [1/3]

template<typename TEnum >
Flags& Flags< TEnum >::operator= ( const  EmptyFlags)
inline

Deletes all flags.

Definition at line 71 of file Flags.h.

◆ operator=() [2/3]

template<typename TEnum >
Flags& Flags< TEnum >::operator= ( const Flags< TEnum > &  other)
inline

Copies other Flags object.

Definition at line 56 of file Flags.h.

◆ operator=() [3/3]

template<typename TEnum >
Flags& Flags< TEnum >::operator= ( const TEnum  flag)
inline

Assigns a single flag, all previous flags are deleted.

The flag must be a power of 2.

Definition at line 64 of file Flags.h.

◆ operator==()

template<typename TEnum >
INLINE bool Flags< TEnum >::operator== ( const Flags< TEnum > &  other) const
inline

Checks for equality with other Flags object.

Definition at line 131 of file Flags.h.

◆ operator|()

template<typename TEnum >
constexpr INLINE Flags Flags< TEnum >::operator| ( const TEnum  flag) const
inlineconstexpr

Returns a Flags object by adding a single flag to currently stored values.

Definition at line 123 of file Flags.h.

◆ set()

template<typename TEnum >
INLINE void Flags< TEnum >::set ( const TEnum  flag)
inline

Adds a single flag into the object. All previously stored flags are kept unchanged.

Definition at line 94 of file Flags.h.

◆ setIf()

template<typename TEnum >
INLINE void Flags< TEnum >::setIf ( const TEnum  flag,
const bool  use 
)
inline

Sets or removes given flag based given boolean value.

Definition at line 108 of file Flags.h.

◆ unset()

template<typename TEnum >
INLINE void Flags< TEnum >::unset ( const TEnum  flag)
inline

Removed a single flag.

If the flag is not stored, function does nothing.

Definition at line 102 of file Flags.h.

◆ value()

template<typename TEnum >
INLINE TValue Flags< TEnum >::value ( ) const
inline

Returns the underlying value.

Definition at line 118 of file Flags.h.


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