Regina 7.3 Calculation Engine
Public Member Functions | Static Public Member Functions | Friends | List of all members
regina::BoolSet Class Reference

A set of booleans. More...

#include <utilities/boolset.h>

Public Member Functions

constexpr BoolSet ()
 Creates a new empty set. More...
 
constexpr BoolSet (bool member)
 Creates a set containing a single boolean, which is passed as an argument. More...
 
constexpr BoolSet (const BoolSet &src)=default
 Creates a clone of the given set. More...
 
constexpr BoolSet (bool insertTrue, bool insertFalse)
 Creates a set specifying whether true and/or false should be a member. More...
 
constexpr bool hasTrue () const
 Determines if true is a member of this set. More...
 
constexpr bool hasFalse () const
 Determines if false is a member of this set. More...
 
constexpr bool contains (bool value) const
 Determines if the given boolean is a member of this set. More...
 
void insertTrue ()
 Inserts true into this set if it is not already present. More...
 
void insertFalse ()
 Inserts false into this set if it is not already present. More...
 
void removeTrue ()
 Removes true from this set if it is present. More...
 
void removeFalse ()
 Removes false from this set if it is present. More...
 
void empty ()
 Removes all elements from this set. More...
 
void fill ()
 Places both true and false into this set if they are not already present. More...
 
constexpr bool operator== (BoolSet other) const
 Determines if this set is equal to the given set. More...
 
constexpr bool operator!= (BoolSet other) const
 Determines if this set is not equal to the given set. More...
 
constexpr bool operator< (BoolSet other) const
 Determines if this set is a proper subset of the given set. More...
 
constexpr bool operator> (BoolSet other) const
 Determines if this set is a proper superset of the given set. More...
 
constexpr bool operator<= (BoolSet other) const
 Determines if this set is a subset of (possibly equal to) the given set. More...
 
constexpr bool operator>= (BoolSet other) const
 Determines if this set is a superset of (possibly equal to) the given set. More...
 
BoolSetoperator= (const BoolSet &cloneMe)=default
 Sets this set to be identical to the given set. More...
 
BoolSetoperator= (bool member)
 Sets this set to the single member set containing the given element. More...
 
BoolSetoperator|= (BoolSet other)
 Sets this set to be the union of this and the given set. More...
 
BoolSetoperator&= (BoolSet other)
 Sets this set to be the intersection of this and the given set. More...
 
BoolSetoperator^= (BoolSet other)
 Sets this set to be the symmetric difference of this and the given set. More...
 
constexpr BoolSet operator| (BoolSet other) const
 Returns the union of this set with the given set. More...
 
constexpr BoolSet operator& (BoolSet other) const
 Returns the intersection of this set with the given set. More...
 
constexpr BoolSet operator^ (BoolSet other) const
 Returns the symmetric difference of this set and the given set. More...
 
constexpr BoolSet operator~ () const
 Returns the complement of this set. More...
 
constexpr unsigned char byteCode () const
 Returns the byte code representing this boolean set. More...
 
bool setByteCode (unsigned char code)
 Sets this to be the boolean set represented by the given byte code. More...
 
const char * stringCode () const
 Returns the string code representing this boolean set. More...
 
bool setStringCode (const std::string &code)
 Sets this to be the boolean set represented by the given string code. More...
 

Static Public Member Functions

static constexpr BoolSet fromByteCode (unsigned char code)
 Creates a boolean set from the given byte code. More...
 

Friends

std::ostream & operator<< (std::ostream &out, BoolSet set)
 Writes the given boolean set to the given output stream. More...
 

Detailed Description

A set of booleans.

Note that there are only four possible such sets.

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.

Constructor & Destructor Documentation

◆ BoolSet() [1/4]

constexpr regina::BoolSet::BoolSet ( )
inlineconstexpr

Creates a new empty set.

◆ BoolSet() [2/4]

constexpr regina::BoolSet::BoolSet ( bool  member)
inlineconstexpr

Creates a set containing a single boolean, which is passed as an argument.

Parameters
memberthe single element to include in this set.

◆ BoolSet() [3/4]

constexpr regina::BoolSet::BoolSet ( const BoolSet src)
constexprdefault

Creates a clone of the given set.

Parameters
srcthe set to clone.

◆ BoolSet() [4/4]

constexpr regina::BoolSet::BoolSet ( bool  insertTrue,
bool  insertFalse 
)
inlineconstexpr

Creates a set specifying whether true and/or false should be a member.

Parameters
insertTrueshould the new set include the element true?
insertFalseshould the new set include the element false?

Member Function Documentation

◆ byteCode()

constexpr unsigned char regina::BoolSet::byteCode ( ) const
inlineconstexpr

Returns the byte code representing this boolean set.

The byte code is sufficient to reconstruct the set and is thus a useful means for passing boolean sets to and from the engine.

The lowest order bit of the byte code is 1 if and only if true is in the set. The next lowest order bit is 1 if and only if false is in the set. All other bits are 0. Therefore sets {}, {true}, {false} and {true, false} have byte codes 0, 1, 2 and 3 respectively.

Returns
the byte code representing this set.

◆ contains()

constexpr bool regina::BoolSet::contains ( bool  value) const
inlineconstexpr

Determines if the given boolean is a member of this set.

Parameters
valuethe boolean to search for in this set.
Returns
true if and only if the given boolean is a member of this set.

◆ empty()

void regina::BoolSet::empty ( )
inline

Removes all elements from this set.

◆ fill()

void regina::BoolSet::fill ( )
inline

Places both true and false into this set if they are not already present.

◆ fromByteCode()

constexpr BoolSet regina::BoolSet::fromByteCode ( unsigned char  code)
inlinestaticconstexpr

Creates a boolean set from the given byte code.

See byteCode() for more information on byte codes.

Precondition
code is 0, 1, 2 or 3.
Parameters
codethe byte code from which the new set will be created.

◆ hasFalse()

constexpr bool regina::BoolSet::hasFalse ( ) const
inlineconstexpr

Determines if false is a member of this set.

Returns
true if and only if false is a member of this set.

◆ hasTrue()

constexpr bool regina::BoolSet::hasTrue ( ) const
inlineconstexpr

Determines if true is a member of this set.

Returns
true if and only if true is a member of this set.

◆ insertFalse()

void regina::BoolSet::insertFalse ( )
inline

Inserts false into this set if it is not already present.

◆ insertTrue()

void regina::BoolSet::insertTrue ( )
inline

Inserts true into this set if it is not already present.

◆ operator!=()

constexpr bool regina::BoolSet::operator!= ( BoolSet  other) const
inlineconstexpr

Determines if this set is not equal to the given set.

Parameters
otherthe set to compare with this.
Returns
true if and only if this and the given set are not equal.

◆ operator&()

constexpr BoolSet regina::BoolSet::operator& ( BoolSet  other) const
inlineconstexpr

Returns the intersection of this set with the given set.

The result is a set containing precisely the elements that belong to both original sets. This set is not changed.

Parameters
otherthe set to intersect with this set.
Returns
the intersection of this and the given set.

◆ operator&=()

BoolSet & regina::BoolSet::operator&= ( BoolSet  other)
inline

Sets this set to be the intersection of this and the given set.

The result is a set containing precisely the elements that belong to both original sets. Note that this set will be modified.

Parameters
otherthe set to intersect with this set.
Returns
a reference to this set.

◆ operator<()

constexpr bool regina::BoolSet::operator< ( BoolSet  other) const
inlineconstexpr

Determines if this set is a proper subset of the given set.

Parameters
otherthe set to compare with this.
Returns
true if and only if this is a proper subset of the given set.

◆ operator<=()

constexpr bool regina::BoolSet::operator<= ( BoolSet  other) const
inlineconstexpr

Determines if this set is a subset of (possibly equal to) the given set.

Parameters
otherthe set to compare with this.
Returns
true if and only if this is a subset of the given set.

◆ operator=() [1/2]

BoolSet & regina::BoolSet::operator= ( bool  member)
inline

Sets this set to the single member set containing the given element.

Parameters
memberthe single element to include in this set.
Returns
a reference to this set.

◆ operator=() [2/2]

BoolSet & regina::BoolSet::operator= ( const BoolSet cloneMe)
default

Sets this set to be identical to the given set.

Parameters
cloneMethe set whose value this set will take.
Returns
a reference to this set.

◆ operator==()

constexpr bool regina::BoolSet::operator== ( BoolSet  other) const
inlineconstexpr

Determines if this set is equal to the given set.

Parameters
otherthe set to compare with this.
Returns
true if and only if this and the given set are equal.

◆ operator>()

constexpr bool regina::BoolSet::operator> ( BoolSet  other) const
inlineconstexpr

Determines if this set is a proper superset of the given set.

Parameters
otherthe set to compare with this.
Returns
true if and only if this is a proper superset of the given set.

◆ operator>=()

constexpr bool regina::BoolSet::operator>= ( BoolSet  other) const
inlineconstexpr

Determines if this set is a superset of (possibly equal to) the given set.

Parameters
otherthe set to compare with this.
Returns
true if and only if this is a superset of the given set.

◆ operator^()

constexpr BoolSet regina::BoolSet::operator^ ( BoolSet  other) const
inlineconstexpr

Returns the symmetric difference of this set and the given set.

The result is a set containing precisely the elements that belong to one but not both of the original sets. This set is not changed.

Parameters
otherthe set whose symmetric difference with this set is to be found.
Returns
the symmetric difference of this and the given set.

◆ operator^=()

BoolSet & regina::BoolSet::operator^= ( BoolSet  other)
inline

Sets this set to be the symmetric difference of this and the given set.

The result is a set containing precisely the elements that belong to one but not both of the original sets. Note that this set will be modified.

Parameters
otherthe set whose symmetric difference with this set is to be found.
Returns
a reference to this set.

◆ operator|()

constexpr BoolSet regina::BoolSet::operator| ( BoolSet  other) const
inlineconstexpr

Returns the union of this set with the given set.

The result is a set containing precisely the elements that belong to either of the original sets. This set is not changed.

Parameters
otherthe set to union with this set.
Returns
the union of this and the given set.

◆ operator|=()

BoolSet & regina::BoolSet::operator|= ( BoolSet  other)
inline

Sets this set to be the union of this and the given set.

The result is a set containing precisely the elements that belong to either of the original sets. Note that this set will be modified.

Parameters
otherthe set to union with this set.
Returns
a reference to this set.

◆ operator~()

constexpr BoolSet regina::BoolSet::operator~ ( ) const
inlineconstexpr

Returns the complement of this set.

The result is a set containing precisely the elements that this set does not contain. This set is not changed.

Returns
the complement of this set.

◆ removeFalse()

void regina::BoolSet::removeFalse ( )
inline

Removes false from this set if it is present.

◆ removeTrue()

void regina::BoolSet::removeTrue ( )
inline

Removes true from this set if it is present.

◆ setByteCode()

bool regina::BoolSet::setByteCode ( unsigned char  code)
inline

Sets this to be the boolean set represented by the given byte code.

See byteCode() for more information on byte codes.

If code is not a value byte code, then this routine will do nothing and return false.

Parameters
codethe byte code that will determine the new value of this set.
Returns
true if and only if code is a valid byte code.

◆ setStringCode()

bool regina::BoolSet::setStringCode ( const std::string &  code)

Sets this to be the boolean set represented by the given string code.

See stringCode() for more information on string codes.

If code is not a value string code, then this routine will do nothing and return false.

Parameters
codethe string code that will determine the new value of this set.
Returns
true if and only if code is a valid string code.

◆ stringCode()

const char * regina::BoolSet::stringCode ( ) const
inline

Returns the string code representing this boolean set.

String codes are a more human-readable alternative to byte codes; in particular, they are used in XML data files.

Every string code contains precisely two characters (plus a terminating null). Sets {}, {true}, {false} and {true, false} have string codes --, T-, -F and TF respectively.

Returns
the two-character string code representing this set.

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
BoolSet  set 
)
friend

Writes the given boolean set to the given output stream.

The set will be written in the form { true, false }, { true }, { false } or { }.

Parameters
outthe output stream to which to write.
setthe boolean set to write.
Returns
a reference to out.

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

Copyright © 1999-2023, 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@maths.uq.edu.au).