Regina 7.4 Calculation Engine
regina::Flags< T > Class Template Reference

A class representing a bitwise combination of flags defined by an enumeration type. More...

#include <utilities/flags.h>

Public Types

using Enum = T
 The underlying enumeration type.
 

Public Member Functions

constexpr Flags ()
 Creates an empty flag set, with no flags set at all.
 
constexpr Flags (T init)
 Creates a flag set initialised to the given value.
 
constexpr Flags (const Flags< T > &)=default
 Creates a clone of the given flag set.
 
constexpr int intValue () const
 Returns the integer representation of this set.
 
constexpr operator bool () const
 Determines whether this flag set is non-empty.
 
constexpr bool has (T flag) const
 Returns whether the given flag is set.
 
constexpr bool has (const Flags< T > &rhs) const
 Returns whether all of the flags in the given set are set.
 
constexpr bool operator== (T rhs) const
 Determines whether this set is precisely equal to the given flag.
 
constexpr bool operator== (const Flags< T > &) const =default
 Determines whether this set is precisely equal to the given flag set.
 
constexpr Flags< T > & operator= (T rhs)
 Sets this flag set to contain precisely the given flag only.
 
constexpr Flags< T > & operator= (const Flags< T > &)=default
 Sets this flag set to contain a copy of the given flag set.
 
constexpr Flags< T > & operator|= (T rhs)
 Changes this flag set by taking a bitwise OR with the given flag.
 
constexpr Flags< T > & operator|= (const Flags< T > &rhs)
 Changes this flag set by taking a bitwise OR with the given flag set.
 
constexpr Flags< T > & operator&= (T rhs)
 Changes this flag set by taking a bitwise AND with the given flag.
 
constexpr Flags< T > & operator&= (const Flags< T > &rhs)
 Changes this flag set by taking a bitwise AND with the given flag set.
 
constexpr Flags< T > & operator^= (T rhs)
 Changes this flag set by taking a bitwise XOR with the given flag.
 
constexpr Flags< T > & operator^= (const Flags< T > &rhs)
 Changes this flag set by taking a bitwise XOR with the given flag set.
 
constexpr Flags< T > operator| (T rhs) const
 Returns the bitwise OR of this set and the given flag.
 
constexpr Flags< T > operator| (const Flags< T > &rhs) const
 Returns the bitwise OR of this and the given flag set.
 
constexpr Flags< T > operator& (T rhs) const
 Returns the bitwise AND of this set and the given flag.
 
constexpr Flags< T > operator& (const Flags< T > &rhs) const
 Returns the bitwise AND of this and the given flag set.
 
constexpr Flags< T > operator^ (T rhs) const
 Returns the bitwise XOR of this set and the given flag.
 
constexpr Flags< T > operator^ (const Flags< T > &rhs) const
 Returns the bitwise XOR of this and the given flag set.
 
constexpr void clear (T rhs)
 Clears all bits from this set that appear in the given flag.
 
constexpr void clear (const Flags< T > &rhs)
 Clears all bits from this set that appear in the given set.
 
constexpr void ensureOne (T default_, T other)
 Adjust this set so that exactly one and only one of the two given flags are included.
 
constexpr void ensureOne (T default_, T second, T last)
 Adjust this set so that exactly one and only one of the three given flags are included.
 
constexpr void ensureOne (T default_, T second, T third, T last)
 Adjust this set so that exactly one and only one of the four given flags are included.
 

Static Public Member Functions

static constexpr Flags< T > fromInt (int value)
 Returns the set corresponding to the given integer value.
 

Detailed Description

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

A class representing a bitwise combination of flags defined by an enumeration type.

The enumeration type is given in the template parameter T. This class allows the user to form and test bitwise combinations of the individual enum values, without losing type safety.

There is usually no need for end users to refer to the type Flags<T> explicitly by name. If a function takes an argument of type Flags<T>, then you can pass a single flag of type T, or a bitwise combination of such flags (flag1 | flag2), or empty braces {} to indicate no flags at all.

These objects are small enough to pass by value and swap with std::swap(), with no need for any specialised move operations or swap functions.

Python
Present only for some particular enumeration types T, when explicitly noted in the corresponding enum documentation. The Python name of the flags class will be the enumeration type name with the prefix Flags_; for instance, the C++ type Flags<NormalAlg> will appear in Python as Flags_NormalAlg.
Template Parameters
Tthe enumeration type holding the individual flags that can be combined. This may be a scoped or unscoped enumeration; however, for now we do insist that the underlying native integer type is int.

Member Typedef Documentation

◆ Enum

template<typename T >
using regina::Flags< T >::Enum = T

The underlying enumeration type.

Constructor & Destructor Documentation

◆ Flags() [1/3]

template<typename T >
regina::Flags< T >::Flags ( )
inlineconstexpr

Creates an empty flag set, with no flags set at all.

◆ Flags() [2/3]

template<typename T >
regina::Flags< T >::Flags ( T init)
inlineconstexpr

Creates a flag set initialised to the given value.

Parameters
initthe initial value of this flag set.

◆ Flags() [3/3]

template<typename T >
regina::Flags< T >::Flags ( const Flags< T > & )
inlineconstexprdefault

Creates a clone of the given flag set.

Member Function Documentation

◆ clear() [1/2]

template<typename T >
void regina::Flags< T >::clear ( const Flags< T > & rhs)
inlineconstexpr

Clears all bits from this set that appear in the given set.

Parameters
rhsidentifies the bits to clear from this set.

◆ clear() [2/2]

template<typename T >
void regina::Flags< T >::clear ( T rhs)
inlineconstexpr

Clears all bits from this set that appear in the given flag.

Parameters
rhsthe flag to clear from this set.

◆ ensureOne() [1/3]

template<typename T >
void regina::Flags< T >::ensureOne ( T default_,
T other )
inlineconstexpr

Adjust this set so that exactly one and only one of the two given flags are included.

If neither flag is present or both flags are present, this set will be adjusted so that default_ is present and other is not.

Precondition
Both default_ and other are each single-bit flags.
Parameters
default_the flag that will be set if any adjustments need to be made.
otherthe flag that will be cleared if any adjustments need to be made.

◆ ensureOne() [2/3]

template<typename T >
void regina::Flags< T >::ensureOne ( T default_,
T second,
T last )
inlineconstexpr

Adjust this set so that exactly one and only one of the three given flags are included.

If neither flag is present, then default_ will be used. If multiple flags are present, then the flag that appears earlier in the argument list for this routine will be used.

Precondition
Each of the given flags is single-bit.
Parameters
default_the highest-priority flag.
secondthe second-highest-priority flag.
lastthe lowest-priority flag.

◆ ensureOne() [3/3]

template<typename T >
void regina::Flags< T >::ensureOne ( T default_,
T second,
T third,
T last )
inlineconstexpr

Adjust this set so that exactly one and only one of the four given flags are included.

If neither flag is present, then default_ will be used. If multiple flags are present, then the flag that appears earlier in the argument list for this routine will be used.

Precondition
Each of the given flags is single-bit.
Parameters
default_the highest-priority flag.
secondthe second-highest-priority flag.
thirdthe third-highest-priority flag.
lastthe lowest-priority flag.

◆ fromInt()

template<typename T >
static constexpr Flags< T > regina::Flags< T >::fromInt ( int value)
inlinestaticconstexpr

Returns the set corresponding to the given integer value.

This is suitable for file input and/or output.

Warning
This function should not be used widely, since it effectively works around inbuilt type safety mechanisms.
Returns
the set corresponding to the given integer value.

◆ has() [1/2]

template<typename T >
bool regina::Flags< T >::has ( const Flags< T > & rhs) const
inlineconstexpr

Returns whether all of the flags in the given set are set.

This requires all of the bits of all of the flags in the given set to be present in this set. The test is equivalent to (*this & rhs) == rhs.

Parameters
rhsthe set whose presence will be tested.
Returns
true if and only if all of the bits of the given set are present in this set.

◆ has() [2/2]

template<typename T >
bool regina::Flags< T >::has ( T flag) const
inlineconstexpr

Returns whether the given flag is set.

This requires all of the bits of the given flag to be set. The test is equivalent to (*this & flag) == flag.

Parameters
flagthe flag whose presence will be tested.
Returns
true if and only if all of the bits of the given flag are set.

◆ intValue()

template<typename T >
int regina::Flags< T >::intValue ( ) const
inlineconstexpr

Returns the integer representation of this set.

This is suitable for file input and/or output.

Warning
This function should not be used widely, since it effectively works around inbuilt type safety mechanisms.
Returns
the integer value of this set.

◆ operator bool()

template<typename T >
regina::Flags< T >::operator bool ( ) const
inlineconstexpr

Determines whether this flag set is non-empty.

An empty flag set has no bits set at all.

Returns
true if and only if this flag set is non-empty.

◆ operator&() [1/2]

template<typename T >
Flags< T > regina::Flags< T >::operator& ( const Flags< T > & rhs) const
inlineconstexpr

Returns the bitwise AND of this and the given flag set.

This flag set is not changed.

Parameters
rhsthe flag set to combine with this set.
Returns
the combination of this and the given flag set.

◆ operator&() [2/2]

template<typename T >
Flags< T > regina::Flags< T >::operator& ( T rhs) const
inlineconstexpr

Returns the bitwise AND of this set and the given flag.

This flag set is not changed.

Parameters
rhsthe flag to combine with this set.
Returns
the combination of this set and the given flag.

◆ operator&=() [1/2]

template<typename T >
Flags< T > & regina::Flags< T >::operator&= ( const Flags< T > & rhs)
inlineconstexpr

Changes this flag set by taking a bitwise AND with the given flag set.

Parameters
rhsthe flag set to combine with this set.
Returns
a reference to this flag set.

◆ operator&=() [2/2]

template<typename T >
Flags< T > & regina::Flags< T >::operator&= ( T rhs)
inlineconstexpr

Changes this flag set by taking a bitwise AND with the given flag.

Parameters
rhsthe flag to combine with this set.
Returns
a reference to this flag set.

◆ operator=() [1/2]

template<typename T >
Flags< T > & regina::Flags< T >::operator= ( const Flags< T > & )
constexprdefault

Sets this flag set to contain a copy of the given flag set.

Returns
a reference to this flag set.

◆ operator=() [2/2]

template<typename T >
Flags< T > & regina::Flags< T >::operator= ( T rhs)
inlineconstexpr

Sets this flag set to contain precisely the given flag only.

Parameters
rhsthe new value of this flag set.
Returns
a reference to this flag set.

◆ operator==() [1/2]

template<typename T >
bool regina::Flags< T >::operator== ( const Flags< T > & ) const
constexprdefault

Determines whether this set is precisely equal to the given flag set.

Returns
true if and only if this and the given flag set are identical.

◆ operator==() [2/2]

template<typename T >
bool regina::Flags< T >::operator== ( T rhs) const
inlineconstexpr

Determines whether this set is precisely equal to the given flag.

Parameters
rhsthe flag to test this against.
Returns
true if and only if this and the given flag are identical.

◆ operator^() [1/2]

template<typename T >
Flags< T > regina::Flags< T >::operator^ ( const Flags< T > & rhs) const
inlineconstexpr

Returns the bitwise XOR of this and the given flag set.

This flag set is not changed.

Parameters
rhsthe flag set to combine with this set.
Returns
the combination of this and the given flag set.

◆ operator^() [2/2]

template<typename T >
Flags< T > regina::Flags< T >::operator^ ( T rhs) const
inlineconstexpr

Returns the bitwise XOR of this set and the given flag.

This flag set is not changed.

Parameters
rhsthe flag to combine with this set.
Returns
the combination of this set and the given flag.

◆ operator^=() [1/2]

template<typename T >
Flags< T > & regina::Flags< T >::operator^= ( const Flags< T > & rhs)
inlineconstexpr

Changes this flag set by taking a bitwise XOR with the given flag set.

Parameters
rhsthe flag set to combine with this set.
Returns
a reference to this flag set.

◆ operator^=() [2/2]

template<typename T >
Flags< T > & regina::Flags< T >::operator^= ( T rhs)
inlineconstexpr

Changes this flag set by taking a bitwise XOR with the given flag.

Parameters
rhsthe flag to combine with this set.
Returns
a reference to this flag set.

◆ operator|() [1/2]

template<typename T >
Flags< T > regina::Flags< T >::operator| ( const Flags< T > & rhs) const
inlineconstexpr

Returns the bitwise OR of this and the given flag set.

This flag set is not changed.

Parameters
rhsthe flag set to combine with this set.
Returns
the combination of this and the given flag set.

◆ operator|() [2/2]

template<typename T >
Flags< T > regina::Flags< T >::operator| ( T rhs) const
inlineconstexpr

Returns the bitwise OR of this set and the given flag.

This flag set is not changed.

Parameters
rhsthe flag to combine with this set.
Returns
the combination of this set and the given flag.

◆ operator|=() [1/2]

template<typename T >
Flags< T > & regina::Flags< T >::operator|= ( const Flags< T > & rhs)
inlineconstexpr

Changes this flag set by taking a bitwise OR with the given flag set.

Parameters
rhsthe flag set to combine with this set.
Returns
a reference to this flag set.

◆ operator|=() [2/2]

template<typename T >
Flags< T > & regina::Flags< T >::operator|= ( T rhs)
inlineconstexpr

Changes this flag set by taking a bitwise OR with the given flag.

Parameters
rhsthe flag to combine with this set.
Returns
a reference to this flag set.

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