Base Framework
Classes | Public Types | Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
BitSet Class Reference

Set of bits collection. More...

#include <base/collection/BitSet.h>

Inherits Collection.

Classes

class  BitPointer
 
class  BitReadPointer
 
class  BitReadReference
 
class  BitReference
 
class  BitSetEnumerator
 Non-modifying enumerator of elements of a bit set. More...
 
class  BitSetReadEnumerator
 Non-modifying enumerator of elements of a bit set. More...
 
class  Element
 
class  EnumeratorTraits
 
class  ReadEnumeratorTraits
 

Public Types

typedef BitSetEnumerator Enumerator
 
typedef BitSetReadEnumerator ReadEnumerator
 

Public Member Functions

 BitSet ()
 
 BitSet (unsigned int size, bool value)
 
 BitSet (const BitSet &copy) noexcept
 
BitSetoperator= (const BitSet &assign) noexcept
 
MemorySize getSize () const noexcept
 
bool isEmpty () const noexcept
 
bool getAt (MemorySize index) const
 
void setAt (MemorySize index, bool value)
 
BitSetset () noexcept
 
BitSetset (unsigned int index)
 
BitSetreset () noexcept
 
BitSetreset (MemorySize index)
 
BitSetflip () noexcept
 
BitSetflip (MemorySize index)
 
BitSetoperator&= (const BitSet &value) noexcept
 
BitSetoperator|= (const BitSet &value) noexcept
 
BitSetoperator^= (const BitSet &value) noexcept
 
BitSetoperator<<= (unsigned int count) noexcept
 
BitSetoperator>>= (unsigned int count) noexcept
 
BitSet operator~ () const noexcept
 
BitSet operator<< (unsigned int count) const noexcept
 
BitSet operator>> (unsigned int count) const noexcept
 
Element operator[] (MemorySize index)
 
bool operator[] (MemorySize index) const
 
Enumerator getEnumerator () noexcept
 
ReadEnumerator getReadEnumerator () const noexcept
 
void removeAll () noexcept
 
 operator bool () noexcept
 

Protected Member Functions

unsigned long * getElements ()
 
const unsigned long * getElements () const noexcept
 
void zeroExtend (MemorySize size)
 
void reinitialize () noexcept
 
void setSize (MemorySize size)
 

Static Protected Member Functions

static MemorySize getNumberOfElements (MemorySize size) noexcept
 
static unsigned int getElementIndex (unsigned int index) noexcept
 
static unsigned long getBitMask (unsigned int index) noexcept
 

Detailed Description

Set of bits collection.

An ordered sequence of boolean values (bits). The is offen used to represent a set of flags. This class does not take up as much memory as Array<bool>.

Version
1.0
Examples
testsuite/BitSet.cpp.

Constructor & Destructor Documentation

◆ BitSet() [1/3]

BitSet::BitSet ( )

Initializes an empty bit set.

◆ BitSet() [2/3]

BitSet::BitSet ( unsigned int  size,
bool  value 
)

Initializes array with the specified number of elements.

Parameters
sizeThe initial number of bits.
valueThe initial state of the bits.

◆ BitSet() [3/3]

BitSet::BitSet ( const BitSet copy)
inlinenoexcept

Initializes bit set from other bit set.

Member Function Documentation

◆ flip() [1/2]

BitSet& BitSet::flip ( )
noexcept

Inverts all the states of the bit set.

Examples
testsuite/BitSet.cpp.

◆ flip() [2/2]

BitSet& BitSet::flip ( MemorySize  index)

Inverts the state at the specified index. Raises OutOfRange if the index is invalid.

◆ getAt()

bool BitSet::getAt ( MemorySize  index) const

Returns the bit state at the specified index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element.

◆ getBitMask()

static unsigned long BitSet::getBitMask ( unsigned int  index)
inlinestaticprotectednoexcept

Returns the bit mask for the specified index.

◆ getElementIndex()

static unsigned int BitSet::getElementIndex ( unsigned int  index)
inlinestaticprotectednoexcept

Returns the index of the internal element holding the bit at the specified index.

◆ getElements() [1/2]

unsigned long* BitSet::getElements ( )
inlineprotected

Returns the elements of the internal array for modifying access.

◆ getElements() [2/2]

const unsigned long* BitSet::getElements ( ) const
inlineprotectednoexcept

Returns the elements of the internal array for non-modifying access.

◆ getEnumerator()

Enumerator BitSet::getEnumerator ( )
inlinenoexcept

Returns a modifying enumerator of the bit set. The elements are enumerated from most significant to the least significant.

Examples
testsuite/BitSet.cpp.

◆ getNumberOfElements()

static MemorySize BitSet::getNumberOfElements ( MemorySize  size)
inlinestaticprotectednoexcept

Returns the number of required elements to hold the specified number of bits.

◆ getReadEnumerator()

ReadEnumerator BitSet::getReadEnumerator ( ) const
inlinenoexcept

Returns a non-modifying enumerator of the bit set. The elements are enumerated from most significant to the least significant.

Examples
testsuite/BitSet.cpp.

◆ getSize()

MemorySize BitSet::getSize ( ) const
inlinenoexcept

Returns the number of bit in the bit set.

Examples
testsuite/BitSet.cpp.

◆ isEmpty()

bool BitSet::isEmpty ( ) const
inlinenoexcept

Returns true if the bit set is empty.

◆ operator bool()

BitSet::operator bool ( )
inlinenoexcept

Returns true if bitset is non-empty.

◆ operator&=()

BitSet& BitSet::operator&= ( const BitSet value)
noexcept

Binary AND of the bit sets.

◆ operator<<()

BitSet BitSet::operator<< ( unsigned int  count) const
inlinenoexcept

Returns a left-shifted bit set.

◆ operator<<=()

BitSet& BitSet::operator<<= ( unsigned int  count)
noexcept

Binary left shift.

Parameters
countThe number of bits to shift.

◆ operator=()

BitSet& BitSet::operator= ( const BitSet assign)
inlinenoexcept

Assignment of bit set to bit set.

◆ operator>>()

BitSet BitSet::operator>> ( unsigned int  count) const
inlinenoexcept

Returns a right-shifted bit set.

◆ operator>>=()

BitSet& BitSet::operator>>= ( unsigned int  count)
noexcept

Binary right shift.

Parameters
countThe number of bits to shift.

◆ operator[]() [1/2]

Element BitSet::operator[] ( MemorySize  index)
inline

Returns reference to the bit at the specified index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element.

◆ operator[]() [2/2]

bool BitSet::operator[] ( MemorySize  index) const
inline

Returns the bit at the specified index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element.

◆ operator^=()

BitSet& BitSet::operator^= ( const BitSet value)
noexcept

Binary EXCLUSIVE OR of the bit sets.

◆ operator|=()

BitSet& BitSet::operator|= ( const BitSet value)
noexcept

Binary OR of the bit sets.

◆ operator~()

BitSet BitSet::operator~ ( ) const
inlinenoexcept

Returns an inverted bit set.

◆ reinitialize()

void BitSet::reinitialize ( )
inlineprotectednoexcept

Resets any unused bits.

◆ removeAll()

void BitSet::removeAll ( )
noexcept

Removes all the bits.

◆ reset() [1/2]

BitSet& BitSet::reset ( )
noexcept

Resets (set to false) all the states of the bit set.

◆ reset() [2/2]

BitSet& BitSet::reset ( MemorySize  index)

Resets (sets to false) the state at the specified index. Raises OutOfRange if the index is invalid.

◆ set() [1/2]

BitSet& BitSet::set ( )
noexcept

Sets (sets to true) all the states of the bit set.

◆ set() [2/2]

BitSet& BitSet::set ( unsigned int  index)

Sets (sets to true) the state at the specified index. Raises OutOfRange if the index is invalid.

◆ setAt()

void BitSet::setAt ( MemorySize  index,
bool  value 
)

Sets the bit state at the specified index. Raises OutOfRange if the index is invalid.

Parameters
indexThe index of the element.
valueThe desired value.

◆ setSize()

void BitSet::setSize ( MemorySize  size)
inlineprotected

Sets the number of bits in the bit set.

◆ zeroExtend()

void BitSet::zeroExtend ( MemorySize  size)
protected

Zero-extends the bit set to the specified size.