xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::core::Flags< Flag > Class Template Reference

A set of flags that are indexed by an enum. More...

#include <xentara/utils/core/Flags.hpp>

Public Types

using size_type = std::underlying_type_t< Flag >
 The type used for the size.
 
using key_type = Flag
 The type used as a key.
 
using mapped_type = bool
 The type the set maps to.
 
using value_type = bool
 The type used as a key.
 
using reference = typename Bitset::reference
 The type used as a reference.
 

Public Member Functions

constexpr Flags () noexcept=default
 Creates an empty object with no flags set.
 
constexpr Flags (Flag flag) noexcept
 Creates an object with one flag set.
 
auto operator&= (const Flags &rhs) noexcept -> Flags &
 Clears flags not found in another object.
 
auto operator|= (const Flags &rhs) noexcept -> Flags &
 Sets flags found in another object.
 
auto operator^= (const Flags &rhs) noexcept -> Flags &
 Inverts flags found in another object.
 
auto operator&= (Flag rhs) noexcept -> Flags &
 Clears all but one flag.
 
auto operator|= (Flag rhs) noexcept -> Flags &
 Sets a single flag.
 
auto operator^= (Flag rhs) noexcept -> Flags &
 Inverts a single flag.
 
auto operator~ () const noexcept -> Flags
 Creates an Object with all flags inverted.
 
constexpr auto operator[] (Flag flag) const -> bool
 Gets the state of a certain flag.
 
auto operator[] (Flag flag) -> reference
 Gets the state of a certain flag.
 
auto operator== (const Flags &) const noexcept -> bool=default
 Comparison operator.
 
constexpr auto test (Flag flag) const -> bool
 Gets the state of a certain flag.
 
auto all () const noexcept -> bool
 Checks if all the bits are set.
 
auto any () const noexcept -> bool
 Checks if any of the bits are set.
 
auto none () const noexcept -> bool
 Checks if any the bits are cleared.
 
auto count () const noexcept -> size_type
 Returns the number of Flags that are set.
 
auto set () noexcept -> Flags &
 Sets all flags.
 
auto set (Flag flag, bool value=true) -> Flags &
 Sets or resets a certain flag.
 
auto reset () noexcept -> Flags &
 Resets all flags.
 
auto reset (Flag flag) -> Flags &
 Resets a certain flag.
 
auto flip () noexcept -> Flags &
 Inverts all flags.
 
auto flip (Flag flag) -> Flags &
 Inverts a certain flag.
 

Static Public Member Functions

static constexpr auto size () -> size_type
 Returns the number of Flags that the object can hold.
 

Related Symbols

(Note that these are not member symbols.)

template<xentara::utils::core::FlagEnum Flag>
constexpr auto operator| (Flag lhs, Flag rhs) -> xentara::utils::core::Flags< Flag >
 Generates the union between two flags.
 
template<xentara::utils::core::FlagEnum Flag>
constexpr auto operator& (Flag lhs, Flag rhs) -> xentara::utils::core::Flags< Flag >
 Generates the intersection between two flags.
 
template<xentara::utils::core::FlagEnum Flag>
constexpr auto operator^ (Flag lhs, Flag rhs) -> xentara::utils::core::Flags< Flag >
 Generates the symmetric difference between two flags.
 
template<xentara::utils::core::FlagEnum Flag>
constexpr auto operator~ (Flag flag) -> xentara::utils::core::Flags< Flag >
 Generates the inverse of a flag.
 

Detailed Description

template<FlagEnum Flag>
class xentara::utils::core::Flags< Flag >

A set of flags that are indexed by an enum.

Template Parameters
FlagThe type to use for the individual flags

Member Typedef Documentation

◆ key_type

template<FlagEnum Flag>
using xentara::utils::core::Flags< Flag >::key_type = Flag

The type used as a key.

◆ mapped_type

template<FlagEnum Flag>
using xentara::utils::core::Flags< Flag >::mapped_type = bool

The type the set maps to.

◆ reference

template<FlagEnum Flag>
using xentara::utils::core::Flags< Flag >::reference = typename Bitset::reference

The type used as a reference.

◆ size_type

template<FlagEnum Flag>
using xentara::utils::core::Flags< Flag >::size_type = std::underlying_type_t<Flag>

The type used for the size.

◆ value_type

template<FlagEnum Flag>
using xentara::utils::core::Flags< Flag >::value_type = bool

The type used as a key.

Constructor & Destructor Documentation

◆ Flags() [1/2]

template<FlagEnum Flag>
constexpr xentara::utils::core::Flags< Flag >::Flags ( )
constexprdefaultnoexcept

Creates an empty object with no flags set.

◆ Flags() [2/2]

template<FlagEnum Flag>
constexpr xentara::utils::core::Flags< Flag >::Flags ( Flag  flag)
constexprnoexcept

Creates an object with one flag set.

Parameters
flagThe flag to set

Member Function Documentation

◆ all()

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::all ( ) const -> bool
noexcept

Checks if all the bits are set.

Returns
A Boolean designating whether all flags are set

◆ any()

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::any ( ) const -> bool
noexcept

Checks if any of the bits are set.

Returns
A Boolean designating whether any flags are set

◆ count()

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::count ( ) const -> size_type
noexcept

Returns the number of Flags that are set.

Returns
The set flag count

◆ flip() [1/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::flip ( ) -> Flags &
noexcept

Inverts all flags.

Returns
A Reference to this object

◆ flip() [2/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::flip ( Flag  flag) -> Flags &

Inverts a certain flag.

Parameters
flagThe flag to invert
Returns
A Reference to this object

◆ none()

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::none ( ) const -> bool
noexcept

Checks if any the bits are cleared.

Returns
A Boolean designating whether all flags are cleared

◆ operator&=() [1/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::operator&= ( const Flags< Flag > &  rhs) -> Flags &
noexcept

Clears flags not found in another object.

Parameters
rhsThe other object
Returns
A Reference to this object

◆ operator&=() [2/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::operator&= ( Flag  rhs) -> Flags &
noexcept

Clears all but one flag.

Parameters
rhsThe flag
Returns
A Reference to this object

◆ operator==()

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::operator== ( const Flags< Flag > &  ) const -> bool=default
defaultnoexcept

Comparison operator.

Returns
The comparison result

◆ operator[]() [1/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::operator[] ( Flag  flag) -> reference

Gets the state of a certain flag.

Parameters
flagThe flag
Returns
A reference to the flag

◆ operator[]() [2/2]

template<FlagEnum Flag>
constexpr auto xentara::utils::core::Flags< Flag >::operator[] ( Flag  flag) const -> bool
constexpr

Gets the state of a certain flag.

Parameters
flagThe flag
Returns
A Boolean designating whether the flag is set

◆ operator^=() [1/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::operator^= ( const Flags< Flag > &  rhs) -> Flags &
noexcept

Inverts flags found in another object.

Parameters
rhsThe other object
Returns
A Reference to this object

◆ operator^=() [2/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::operator^= ( Flag  rhs) -> Flags &
noexcept

Inverts a single flag.

Parameters
rhsThe flag
Returns
A Reference to this object

◆ operator|=() [1/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::operator|= ( const Flags< Flag > &  rhs) -> Flags &
noexcept

Sets flags found in another object.

Parameters
rhsThe other object
Returns
A Reference to this object

◆ operator|=() [2/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::operator|= ( Flag  rhs) -> Flags &
noexcept

Sets a single flag.

Parameters
rhsThe flag
Returns
A Reference to this object

◆ operator~()

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::operator~ ( ) const -> Flags
noexcept

Creates an Object with all flags inverted.

Returns
The inverse object

◆ reset() [1/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::reset ( ) -> Flags &
noexcept

Resets all flags.

Returns
A Reference to this object

◆ reset() [2/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::reset ( Flag  flag) -> Flags &

Resets a certain flag.

Parameters
flagThe flag to reset
Returns
A Reference to this object

◆ set() [1/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::set ( ) -> Flags &
noexcept

Sets all flags.

Returns
A Reference to this object

◆ set() [2/2]

template<FlagEnum Flag>
auto xentara::utils::core::Flags< Flag >::set ( Flag  flag,
bool  value = true 
) -> Flags &

Sets or resets a certain flag.

Parameters
flagThe flag to set
valueThe new value for the flag
Returns
A Reference to this object

◆ size()

template<FlagEnum Flag>
static constexpr auto xentara::utils::core::Flags< Flag >::size ( ) -> size_type
staticconstexpr

Returns the number of Flags that the object can hold.

Returns
The set flag count

◆ test()

template<FlagEnum Flag>
constexpr auto xentara::utils::core::Flags< Flag >::test ( Flag  flag) const -> bool
constexpr

Gets the state of a certain flag.

Parameters
flagThe flag
Returns
A Boolean designating whether the flag is set

Friends And Related Symbol Documentation

◆ operator&()

constexpr auto operator& ( Flag  lhs,
Flag  rhs 
) -> xentara::utils::core::Flags<Flag>
related

Generates the intersection between two flags.

Parameters
lhsThe first flag
rhsThe second flag
Returns
An object containing the flags if they are the same, or an empty object otherwise

◆ operator^()

constexpr auto operator^ ( Flag  lhs,
Flag  rhs 
) -> xentara::utils::core::Flags<Flag>
related

Generates the symmetric difference between two flags.

Parameters
lhsThe first flag
rhsThe second flag
Returns
An object containing the flags if they are not the same, or an empty object otherwise

◆ operator|()

constexpr auto operator| ( Flag  lhs,
Flag  rhs 
) -> xentara::utils::core::Flags<Flag>
related

Generates the union between two flags.

Parameters
lhsThe first flag
rhsThe second flag
Returns
An object containing both flags

◆ operator~()

constexpr auto operator~ ( Flag  flag) -> xentara::utils::core::Flags<Flag>
related

Generates the inverse of a flag.

Parameters
flagThe flag
Returns
An object containing all flags except the given flag