regina::Flags< T > Class Template Reference
Utilities

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

`#include <utilities/flags.h>`

## Public Types

typedef T | Enum
| The underlying enumeration type. More...

## Public Member Functions

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

## Static Public Member Functions

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

## 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.

Python:
  Present only for some particular enumeration types T, when explicitly noted in the corresponding enum documentation.

## Member Typedef Documentation

template<typename T>

typedef T regina::Flags< T >::Enum

The underlying enumeration type.

## Constructor & Destructor Documentation

template<typename T>

regina::Flags< T >::Flags | ( |  | ) |

inline

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

template<typename T>

regina::Flags< T >::Flags | ( | T | init | ) |

inline

Creates a flag set initialised to the given value.

Parameters

  init | the initial value of this flag set.

template<typename T>

regina::Flags< T >::Flags | ( | const Flags< T > & | init | ) |

inline

Creates a clone of the given flag set.

Parameters

  init | the flag set to clone.

## Member Function Documentation

template<typename T>

void regina::Flags< T >::clear | ( | T | rhs | ) |

inline

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

Parameters

  rhs | the flag to clear from this set.

template<typename T>

void regina::Flags< T >::clear | ( | const Flags< T > & | rhs | ) |

inline

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

Parameters

  rhs | identifies the bits to clear from this set.

template<typename T>

void regina::Flags< T >::ensureOne | ( | T | default_,
|  | T | other
| ) |  |

inline

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.

Python:
  Not present, even for flag types that are exposed to Python.

Parameters

  default_ | the flag that will be set if any adjustments need to be made.
  other | the flag that will be cleared if any adjustments need to be made.

template<typename T>

void regina::Flags< T >::ensureOne | ( | T | default_,
|  | T | second,
|  | T | last
| ) |  |

inline

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.

Python:
  Not present, even for flag types that are exposed to Python.

Parameters

  default_ | the highest-priority flag.
  second | the second-highest-priority flag.
  last | the lowest-priority flag.

template<typename T>

void regina::Flags< T >::ensureOne | ( | T | default_,
|  | T | second,
|  | T | third,
|  | T | last
| ) |  |

inline

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.

Python:
  Not present, even for flag types that are exposed to Python.

Parameters

  default_ | the highest-priority flag.
  second | the second-highest-priority flag.
  third | the third-highest-priority flag.
  last | the lowest-priority flag.

template<typename T>

static Flags<T> regina::Flags< T >::fromInt | ( | int | value | ) |

inline static

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.

template<typename T>

bool regina::Flags< T >::has | ( | T | flag | ) | const

inline

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

  flag | the flag whose presence will be tested.

Returns
  `true` if and only if all of the bits of the given flag are set.

template<typename T>

bool regina::Flags< T >::has | ( | const Flags< T > & | rhs | ) | const

inline

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

  rhs | the 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.

template<typename T>

int regina::Flags< T >::intValue | ( |  | ) | const

inline

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.

template<typename T>

bool regina::Flags< T >::operator!= | ( | T | rhs | ) | const

inline

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

Parameters

  rhs | the flag to test this against.

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

template<typename T>

bool regina::Flags< T >::operator!= | ( | const Flags< T > & | rhs | ) | const

inline

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

Parameters

  rhs | the flag to test this against.

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

template<typename T>

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

inline

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

This flag set is not changed.

Parameters

  rhs | the flag to combine with this set.

Returns
  the combination of this set and the given flag.

template<typename T>

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

inline

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

This flag set is not changed.

Parameters

  rhs | the flag set to combine with this set.

Returns
  the combination of this and the given flag set.

template<typename T>

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

inline

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

Parameters

  rhs | the flag to combine with this set.

Returns
  a reference to this flag set.

template<typename T>

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

inline

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

Parameters

  rhs | the flag set to combine with this set.

Returns
  a reference to this flag set.

template<typename T>

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

inline

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

Parameters

  rhs | the new value of this flag set.

Returns
  a reference to this flag set.

template<typename T>

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

inline

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

Parameters

  rhs | the new value of this flag set.

Returns
  a reference to this flag set.

template<typename T>

bool regina::Flags< T >::operator== | ( | T | rhs | ) | const

inline

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

Parameters

  rhs | the flag to test this against.

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

template<typename T>

bool regina::Flags< T >::operator== | ( | const Flags< T > & | rhs | ) | const

inline

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

Parameters

  rhs | the flag set to test this against.

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

template<typename T>

Flags<T> regina::Flags< T >::operator^ | ( | T | rhs | ) | const

inline

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

This flag set is not changed.

Parameters

  rhs | the flag to combine with this set.

Returns
  the combination of this set and the given flag.

template<typename T>

Flags<T> regina::Flags< T >::operator^ | ( | const Flags< T > & | rhs | ) | const

inline

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

This flag set is not changed.

Parameters

  rhs | the flag set to combine with this set.

Returns
  the combination of this and the given flag set.

template<typename T>

Flags<T>& regina::Flags< T >::operator^= | ( | T | rhs | ) |

inline

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

Parameters

  rhs | the flag to combine with this set.

Returns
  a reference to this flag set.

template<typename T>

Flags<T>& regina::Flags< T >::operator^= | ( | const Flags< T > & | rhs | ) |

inline

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

Parameters

  rhs | the flag set to combine with this set.

Returns
  a reference to this flag set.

template<typename T>

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

inline

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

This flag set is not changed.

Parameters

  rhs | the flag to combine with this set.

Returns
  the combination of this set and the given flag.

template<typename T>

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

inline

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

This flag set is not changed.

Parameters

  rhs | the flag set to combine with this set.

Returns
  the combination of this and the given flag set.

template<typename T>

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

inline

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

Parameters

  rhs | the flag to combine with this set.

Returns
  a reference to this flag set.

template<typename T>

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

inline

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

Parameters

  rhs | the flag set to combine with this set.

Returns
  a reference to this flag set.

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

- utilities/flags.h

Copyright © 1999-2013, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).