cubos::core::reflection::MaskTrait class

Provides mask functionality to an enum mask type.

Public types

using Tester = bool(*)(const void*instance)
Function pointer to test if a bit is set on the mask.
using Setter = void(*)(void*instance)
Function pointer to set the bit on the mask.
using Clearer = void(*)(void*instance)
Function pointer to clear the bit on the mask.

Public static functions

static auto end() -> Iterator
Gets an iterator to the last bit of the type.

Constructors, destructors, conversion operators

MaskTrait() defaulted
Constructs.
MaskTrait(MaskTrait&& other) noexcept
Move constructs.
Bit(std::string name, Tester tester, Setter setter, Clearer clearer)
Constructs.
Iterator(const Bit* bit)
Constructs.
Iterator(const Iterator& iterator) defaulted
Copy constructs.
SetIterator(const Bit* bit, const void* instance)
Constructs.
SetIterator(const SetIterator& other) defaulted
Copy constructs.
View(const MaskTrait& trait, void* instance)
Constructs.
ConstView(const MaskTrait& trait, const void* instance)
Constructs.

Public functions

void addBit(std::string name, Tester tester, Setter setter, Clearer clearer)
Adds a bit to the type.
auto withBit(std::string name, Tester tester, Setter setter, Clearer clearer) && -> MaskTrait&&
Adds a bit to the type.
template<auto B>
auto withBit(std::string name) && -> MaskTrait&&
Adds a bit to the type.
auto contains(const std::string& name) const -> bool
Checks if a bit with the given name exists.
auto at(const std::string& name) const -> const Bit&
Gets the bit with the specified name.
auto begin() const -> Iterator
Gets an iterator to the first bit of the type.
auto size() const -> std::size_t
Returns how many bits there are in the trait.
auto view(void* instance) const -> View
Returns a view of the given mask instance.
auto view(const void* instance) const -> ConstView
Returns a view of the given mask instance.
auto test(const void* value) const -> bool
Tests if the given value has the bit set.
void set(void* value) const
Sets the bit on the given value.
void clear(void* value) const
Clears the bit on the given value.
auto name() const -> const std::string&
Gets the name of the bit.
auto next() const -> const Bit*
Returns the next bit in the linked list.
auto operator=(const Iterator&) -> Iterator& defaulted
Copy assigns.
auto operator==(const Iterator&) const -> bool defaulted
Compares with another iterator.
auto operator*() const -> const Bit&
Accesses the bit referenced by this iterator.
auto operator->() const -> const Bit*
Accesses the bit referenced by this iterator.
auto operator++() -> Iterator&
Advances the iterator.
auto operator==(const SetIterator& other) const -> bool defaulted
Compares two iterators.
auto operator*() const -> const Bit&
Accesses the bit referenced by this iterator.
auto operator->() const -> const Bit*
Accesses the bit referenced by this iterator.
auto operator++() -> SetIterator&
Advances the iterator.
auto test(const Bit& bit) const -> bool
Checks if the given bit is set on the mask.
auto test(const std::string& name) const -> bool
Checks if the given bit is set on the mask.
void set(const Bit& bit) const
Sets the given bit on the mask.
void set(const std::string& name) const
Sets the given bit on the mask.
void clear(const Bit& bit) const
Clears the given bit on the mask.
void clear(const std::string& name) const
Clears the given bit on the mask.
auto begin() const -> SetIterator
Gets an iterator to the first set bit.
auto end() const -> SetIterator
Gets an iterator representing the end of the set bits.
auto test(const Bit& bit) const -> bool
Checks if the given bit is set on the mask.
auto test(const std::string& name) const -> bool
Checks if the given bit is set on the mask.
auto begin() const -> SetIterator
Gets an iterator to the first set bit.
auto end() const -> SetIterator
Gets an iterator representing the end of the set bits.

Function documentation

static Iterator cubos::core::reflection::MaskTrait::end()

Gets an iterator to the last bit of the type.

Returns Iterator.

cubos::core::reflection::MaskTrait::MaskTrait(MaskTrait&& other) noexcept

Move constructs.

Parameters
other Other trait.

cubos::core::reflection::MaskTrait::Bit(std::string name, Tester tester, Setter setter, Clearer clearer)

Constructs.

Parameters
name Name.
tester Function to test if a bit is set on the mask.
setter Function to set a bit on the mask.
clearer Function to clear a bit on the mask.

cubos::core::reflection::MaskTrait::Iterator(const Bit* bit)

Constructs.

Parameters
bit Bit.

cubos::core::reflection::MaskTrait::Iterator(const Iterator& iterator) defaulted

Copy constructs.

Parameters
iterator Iterator.

cubos::core::reflection::MaskTrait::SetIterator(const Bit* bit, const void* instance)

Constructs.

Parameters
bit Bit to start from.
instance Mask instance.

cubos::core::reflection::MaskTrait::SetIterator(const SetIterator& other) defaulted

Copy constructs.

Parameters
other Other iterator.

cubos::core::reflection::MaskTrait::View(const MaskTrait& trait, void* instance)

Constructs.

Parameters
trait Trait.
instance Instance.

cubos::core::reflection::MaskTrait::ConstView(const MaskTrait& trait, const void* instance)

Constructs.

Parameters
trait Trait.
instance Instance.

void cubos::core::reflection::MaskTrait::addBit(std::string name, Tester tester, Setter setter, Clearer clearer)

Adds a bit to the type.

Parameters
name Bit name.
tester Function to test if a bit is set on the mask.
setter Function to set a bit on the mask.
clearer Function to clear a bit on the mask.

MaskTrait&& cubos::core::reflection::MaskTrait::withBit(std::string name, Tester tester, Setter setter, Clearer clearer) &&

Adds a bit to the type.

Parameters
name Bit name.
tester Function to test if a bit is set on the mask.
setter Function to set a bit on the mask.
clearer Function to clear a bit on the mask.
Returns Trait.

template<auto B>
MaskTrait&& cubos::core::reflection::MaskTrait::withBit(std::string name) &&

Adds a bit to the type.

Template parameters
B Bit value.
Parameters
name Bit name.
Returns Trait.

The bit type must implement at least the operators '&', '|' and '~'.

bool cubos::core::reflection::MaskTrait::contains(const std::string& name) const

Checks if a bit with the given name exists.

Parameters
name Bit name.
Returns Whether the bit exists.

const Bit& cubos::core::reflection::MaskTrait::at(const std::string& name) const

Gets the bit with the specified name.

Parameters
name Bit name.
Returns Reference.

Iterator cubos::core::reflection::MaskTrait::begin() const

Gets an iterator to the first bit of the type.

Returns Iterator.

std::size_t cubos::core::reflection::MaskTrait::size() const

Returns how many bits there are in the trait.

Returns Bit count.

View cubos::core::reflection::MaskTrait::view(void* instance) const

Returns a view of the given mask instance.

Parameters
instance Mask instance.
Returns Mask view.

ConstView cubos::core::reflection::MaskTrait::view(const void* instance) const

Returns a view of the given mask instance.

Parameters
instance Mask instance.
Returns Mask view.

bool cubos::core::reflection::MaskTrait::test(const void* value) const

Tests if the given value has the bit set.

Parameters
value Pointer to value.
Returns Whether the value has the bit set.

void cubos::core::reflection::MaskTrait::set(void* value) const

Sets the bit on the given value.

Parameters
value Pointer to value.

void cubos::core::reflection::MaskTrait::clear(void* value) const

Clears the bit on the given value.

Parameters
value Pointer to value.

const std::string& cubos::core::reflection::MaskTrait::name() const

Gets the name of the bit.

Returns Bit name.

const Bit* cubos::core::reflection::MaskTrait::next() const

Returns the next bit in the linked list.

Returns Pointer to next bit or null if this is the last bit.

Iterator& cubos::core::reflection::MaskTrait::operator=(const Iterator&) defaulted

Copy assigns.

Returns This.

bool cubos::core::reflection::MaskTrait::operator==(const Iterator&) const defaulted

Compares with another iterator.

Returns Whether both point to the same variant.

const Bit& cubos::core::reflection::MaskTrait::operator*() const

Accesses the bit referenced by this iterator.

Returns Reference to the bit.

const Bit* cubos::core::reflection::MaskTrait::operator->() const

Accesses the bit referenced by this iterator.

Returns Pointer to the bit.

Iterator& cubos::core::reflection::MaskTrait::operator++()

Advances the iterator.

Returns Reference to this.

bool cubos::core::reflection::MaskTrait::operator==(const SetIterator& other) const defaulted

Compares two iterators.

Parameters
other Other iterator.
Returns Whether the iterators point to the same bit.

const Bit& cubos::core::reflection::MaskTrait::operator*() const

Accesses the bit referenced by this iterator.

Returns Bit.

const Bit* cubos::core::reflection::MaskTrait::operator->() const

Accesses the bit referenced by this iterator.

Returns Bit.

SetIterator& cubos::core::reflection::MaskTrait::operator++()

Advances the iterator.

Returns Reference to this.

bool cubos::core::reflection::MaskTrait::test(const Bit& bit) const

Checks if the given bit is set on the mask.

Parameters
bit Bit.
Returns Whether the bit is set.

bool cubos::core::reflection::MaskTrait::test(const std::string& name) const

Checks if the given bit is set on the mask.

Parameters
name Bit name.
Returns Whether the bit is set.

Aborts if the bit does not exist.

void cubos::core::reflection::MaskTrait::set(const Bit& bit) const

Sets the given bit on the mask.

Parameters
bit Bit.

void cubos::core::reflection::MaskTrait::set(const std::string& name) const

Sets the given bit on the mask.

Parameters
name Bit name.

Aborts if the bit does not exist.

void cubos::core::reflection::MaskTrait::clear(const Bit& bit) const

Clears the given bit on the mask.

Parameters
bit Bit.

void cubos::core::reflection::MaskTrait::clear(const std::string& name) const

Clears the given bit on the mask.

Parameters
name Bit name.

Aborts if the bit does not exist.

SetIterator cubos::core::reflection::MaskTrait::begin() const

Gets an iterator to the first set bit.

Returns Iterator.

SetIterator cubos::core::reflection::MaskTrait::end() const

Gets an iterator representing the end of the set bits.

Returns Iterator.

bool cubos::core::reflection::MaskTrait::test(const Bit& bit) const

Checks if the given bit is set on the mask.

Parameters
bit Bit.
Returns Whether the bit is set.

bool cubos::core::reflection::MaskTrait::test(const std::string& name) const

Checks if the given bit is set on the mask.

Parameters
name Bit name.
Returns Whether the bit is set.

Aborts if the bit does not exist.

SetIterator cubos::core::reflection::MaskTrait::begin() const

Gets an iterator to the first set bit.

Returns Iterator.

SetIterator cubos::core::reflection::MaskTrait::end() const

Gets an iterator representing the end of the set bits.

Returns Iterator.