Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
Nz::Flags< E > Class Template Reference

Core class used to combine enumeration values into flags bitfield. More...

Public Types

using BitField = typename std::conditional<(EnumAsFlags< E >::max > 32), UInt64, UInt32 >::type
 

Public Member Functions

constexpr Flags (BitField value=0)
 Constructs a Flags object using a bitfield. More...
 
constexpr Flags (E enumVal)
 Constructs a Flags object using an Enum value. More...
 
constexpr operator bool () const
 Tests a Flags. More...
 
constexpr operator BitField () const
 Converts to a bitfield. More...
 
constexpr Flags operator~ () const
 Reverse flag states. More...
 
constexpr Flags operator & (const Flags &rhs) const
 
constexpr Flags operator| (const Flags &rhs) const
 Combine flag states. More...
 
constexpr Flags operator^ (const Flags &rhs) const
 XOR flag states. More...
 
constexpr bool operator== (const Flags &rhs) const
 Check equality with flag object. More...
 
constexpr bool operator!= (const Flags &rhs) const
 Check inequality with flag object. More...
 
Flagsoperator|= (const Flags &rhs)
 Combine flag states. More...
 
Flagsoperator &= (const Flags &rhs)
 
Flagsoperator^= (const Flags &rhs)
 XOR flag states. More...
 

Static Public Member Functions

static constexpr BitField GetFlagValue (E enumValue)
 Returns a bitfield corresponding to an enum value. More...
 

Static Public Attributes

static constexpr BitField ValueMask = ((BitField(1) << (EnumAsFlags<E>::max + 1)) - 1)
 

Detailed Description

template<typename E>
class Nz::Flags< E >

Core class used to combine enumeration values into flags bitfield.

Constructor & Destructor Documentation

◆ Flags() [1/2]

template<typename E >
constexpr Nz::Flags< E >::Flags ( BitField  value = 0)

Constructs a Flags object using a bitfield.

Parameters
valueBitfield to be used

Uses a bitfield to builds the flag value. (e.g. if bit 0 is active, then Enum value 0 will be set as active).

◆ Flags() [2/2]

template<typename E>
constexpr Nz::Flags< E >::Flags ( enumVal)

Constructs a Flags object using an Enum value.

Parameters
valueenumVal

Setup a Flags object with only one flag active (corresponding to the enum value passed as argument).

Member Function Documentation

◆ GetFlagValue()

template<typename E>
constexpr Flags< E >::BitField Nz::Flags< E >::GetFlagValue ( enumValue)
static

Returns a bitfield corresponding to an enum value.

Returns
Bitfield representation of the enum value
Parameters
enumValueEnumeration value to get as a bitfield.

Internally, every enum option is turned into a bit, this function allows to get a bitfield with only the bit of the enumeration value enabled.

◆ operator BitField()

template<typename E >
constexpr Nz::Flags< E >::operator BitField ( ) const
explicit

Converts to a bitfield.

Returns
Enabled flags as a bitfield.

This will convert to a bitfield value.

◆ operator bool()

template<typename E >
constexpr Nz::Flags< E >::operator bool ( ) const
explicit

Tests a Flags.

Returns
True if any flag is enabled.

This will convert to a boolean value allowing to check if any flag is set.

◆ operator!=()

template<typename E >
constexpr bool Nz::Flags< E >::operator!= ( const Flags< E > &  rhs) const

Check inequality with flag object.

Returns
True if both flags objects have different states.
Parameters
rhsFlags to compare with.

Compare two Flags object and returns true if the flag states are identical.

◆ operator==()

template<typename E >
constexpr bool Nz::Flags< E >::operator== ( const Flags< E > &  rhs) const

Check equality with flag object.

Returns
True if both flags objects have the same states.
Parameters
rhsFlags to compare with.

Compare two Flags object and returns true if the flag states are identical.

◆ operator^()

template<typename E >
constexpr Flags< E > Nz::Flags< E >::operator^ ( const Flags< E > &  rhs) const

XOR flag states.

Returns
XORed flags.
Parameters
rhsFlags to XOR with.

This performs a XOR (Exclusive OR) on a copy of the flag object. This will returns a copy of the object with disabled common flags and enabled unique ones.

◆ operator^=()

template<typename E >
Flags< E > & Nz::Flags< E >::operator^= ( const Flags< E > &  rhs)

XOR flag states.

Returns
A reference to the object.
Parameters
rhsFlags to XOR with.

This performs a XOR (Exclusive OR) on the flag object. This will disable flags enabled in both Flags objects and enable those enabled in only one of the Flags objects.

◆ operator|()

template<typename E >
constexpr Flags< E > Nz::Flags< E >::operator| ( const Flags< E > &  rhs) const

Combine flag states.

Returns
Combined flags

This will returns a copy of the Flags object with combined flags from the parameter.

Parameters
rhsFlags to combine with.

◆ operator|=()

template<typename E >
Flags< E > & Nz::Flags< E >::operator|= ( const Flags< E > &  rhs)

Combine flag states.

Returns
A reference to the object.
Parameters
rhsFlags to combine with.

This will enable flags which are enabled in parameter object and not in Flag object.

◆ operator~()

template<typename E >
constexpr Flags< E > Nz::Flags< E >::operator~ ( ) const

Reverse flag states.

Returns
Opposite enabled flags

This will returns a copy of the Flags object with reversed flags states.


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