Magnum::Ui::BitStorage class new in Git master

Bit storage.

Owns or references a single bit or a bit sequence, allowing storage queries to toggle individual bits.

If you have a concrete enum or Containers::EnumSet in which you want to toggle individual values, an EnumStorage may be a better fit.

Base classes

class AbstractStorage new in Git master
Base for DataLayer storage implementations.

Constructors, destructors, conversion operators

template<class Owner>
BitStorage(Owner& owner, ValueInitT, StorageFlags flags = {}) explicit
Construct a value-initialized single-bit storage.
template<class Owner>
BitStorage(Owner& owner, ValueInitT, std::size_t size, StorageFlags flags = {}) explicit
Construct a value-initialized 1D storage.
template<class Owner>
BitStorage(Owner& owner, NoInitT, StorageFlags flags = {}) explicit
Construct a single-bit storage without initializing its contents.
template<class Owner>
BitStorage(Owner& owner, NoInitT, std::size_t size, StorageFlags flags = {}) explicit
Construct a 1D storage without initializing its contents.
template<class Owner>
BitStorage(Owner& owner, DirectInitT, bool value, StorageFlags flags = {}) explicit
Construct a direct-initialized single-bit storage.
template<class Owner>
BitStorage(Owner& owner, DirectInitT, std::size_t size, bool value, StorageFlags flags = {}) explicit
Construct a direct-initialized 1D storage.
template<class Owner>
BitStorage(Owner& owner, NonOwnedT, bool& value, StorageFlags flags = {}) explicit
Construct a non-owned single-bit storage.
template<class Owner>
BitStorage(Owner& owner, NonOwnedT, const bool& value, StorageFlags flags = {}) explicit
template<class Owner>
BitStorage(Owner& owner, NonOwnedT, bool&& value, StorageFlags flags = {}) deleted explicit
Constructing a non-owned storage from a r-value reference is not allowed.
template<class Owner>
BitStorage(Owner& owner, NonOwnedT, const bool&& value, StorageFlags flags = {}) deleted explicit
Constructing a non-owned storage from a r-value reference is not allowed.
template<class Owner>
BitStorage(Owner& owner, NonOwnedT, const Containers::MutableStridedBitArrayView1D& values, StorageFlags flags = {}) explicit
Construct a non-owned 1D storage.
template<class Owner>
BitStorage(Owner& owner, NonOwnedT, const Containers::StridedBitArrayView1D& values, StorageFlags flags = {}) explicit
template<class Owner, typename std::enable_if<std::is_convertible<Owner&, DataLayer&>::value||std::is_convertible<Owner&, AbstractUserInterface&>::value, int>::type = 0>
BitStorage(Owner& owner, StorageFlags flags = {}) explicit
Construct a value-initialized single-bit storage.
template<class Owner>
BitStorage(Owner& owner, std::size_t size, StorageFlags flags = {}) explicit
Construct a value-initialized 1D storage.
operator StorageQuery<bool>() const
Single-bit storage value.

Public functions

auto size() const -> std::size_t
Storage size.
auto isMutable() const -> bool
Whether the storage is mutable.
auto defaultValue() const -> bool
Default value.
auto setDefaultValue(bool value) const -> const BitStorage&
Set default value.
auto value() const -> StorageQuery<bool>
Single-item storage value.
auto operator->() const -> StorageQuery<bool>
Single-bit storage value.
auto operator[](std::size_t index) const -> StorageQuery<bool>
1D storage value at given index
auto data() const -> Containers::StridedBitArrayView1D
Raw storage data.
auto mutableData() const -> Containers::MutableStridedBitArrayView1D
Raw mutable storage data.

Function documentation

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, ValueInitT, StorageFlags flags = {}) explicit

Construct a value-initialized single-bit storage.

Equivalent to calling BitStorage(Owner&, ValueInitT, std::size_t, StorageFlags) with size being 1.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, ValueInitT, std::size_t size, StorageFlags flags = {}) explicit

Construct a value-initialized 1D storage.

Parameters
owner DataLayer to create the storage in or a UserInterface instance to take a UserInterface::dataLayer() from
size Storage size
flags Storage flags

Delegates to BitStorage(Owner&, NoInitT, std::size_t, StorageFlags) and then initializes the storage to zero values. See the documentation of BitStorage(Owner&, NoInitT, std::size_t, StorageFlags) for more information.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, NoInitT, StorageFlags flags = {}) explicit

Construct a single-bit storage without initializing its contents.

Equivalent to calling BitStorage(Owner&, NoInitT, std::size_t, StorageFlags) with size being 1.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, NoInitT, std::size_t size, StorageFlags flags = {}) explicit

Construct a 1D storage without initializing its contents.

Parameters
owner DataLayer to create the storage in or a UserInterface instance to take a UserInterface::dataLayer() from
size Storage size
flags Storage flags

Expects that the size is non-zero. If owner is a user interface reference, expects that it contains a DataLayer instance. While the stored values are not initialized in any way, the defaultValue() is set to T{}. You can use mutableData() to fill the storage upon creation.

Delegates to either AbstractStorage::AbstractStorage(DataLayer&, std::size_t, StorageFlags) or AbstractStorage::AbstractStorage(UserInterface&, std::size_t, StorageFlags), see their documentation for detailed description of all constraints.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, DirectInitT, bool value, StorageFlags flags = {}) explicit

Construct a direct-initialized single-bit storage.

Equivalent to calling BitStorage(Owner&, DirectInitT, std::size_t, bool, StorageFlags) with size being 1.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, DirectInitT, std::size_t size, bool value, StorageFlags flags = {}) explicit

Construct a direct-initialized 1D storage.

Parameters
owner DataLayer to create the storage in or a UserInterface instance to take a UserInterface::dataLayer() from
size Storage size
value Value to initialize the storage with
flags Storage flags

Delegates to BitStorage(Owner&, NoInitT, std::size_t, StorageFlags) and then initializes the storage using value. The value is subsequently also used as the default value instead of T{}. See the documentation of BitStorage(Owner&, NoInitT, std::size_t, StorageFlags) for more information.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, NonOwnedT, bool& value, StorageFlags flags = {}) explicit

Construct a non-owned single-bit storage.

Equivalent to calling BitStorage(Owner&, NonOwnedT, const Containers::MutableStridedBitArrayView1D&, StorageFlags) with value turned into a view of size 1 and bit offset of 0. If you need to reference a non- bool type or a different bit, pass an appropriate Containers::MutableBitArrayView instance instead.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, NonOwnedT, const bool& value, StorageFlags flags = {}) explicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, NonOwnedT, bool&& value, StorageFlags flags = {}) explicit deleted

Constructing a non-owned storage from a r-value reference is not allowed.

This prevents the storage to be accidentally constructed from a temporary value.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, NonOwnedT, const bool&& value, StorageFlags flags = {}) explicit deleted

Constructing a non-owned storage from a r-value reference is not allowed.

This prevents the storage to be accidentally constructed from a temporary value.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, NonOwnedT, const Containers::MutableStridedBitArrayView1D& values, StorageFlags flags = {}) explicit

Construct a non-owned 1D storage.

Parameters
owner DataLayer to create the storage in or a UserInterface instance to take a UserInterface::dataLayer() from
values Value view
flags Storage flags

Uses the values view as the storage instead of allocating it. If owner is a user interface reference, expects that it contains a DataLayer instance. The values view is expected to be non-empty with its contents staying in scope for the whole storage lifetime. If the values are a const view, data updates through the storage are not possible.

It's expected that setDirty() is called whenever the values are modified externally.

Delegates to either AbstractStorage::AbstractStorage(DataLayer&, std::size_t, StorageFlags) or AbstractStorage::AbstractStorage(UserInterface&, std::size_t, StorageFlags), see their documentation for detailed description of all constraints.

template<class Owner>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, NonOwnedT, const Containers::StridedBitArrayView1D& values, StorageFlags flags = {}) explicit

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class Owner, typename std::enable_if<std::is_convertible<Owner&, DataLayer&>::value||std::is_convertible<Owner&, AbstractUserInterface&>::value, int>::type = 0>
Magnum::Ui::BitStorage::BitStorage(Owner& owner, StorageFlags flags = {}) explicit

Construct a value-initialized single-bit storage.

Alias to BitStorage(Owner&, ValueInitT, StorageFlags).

Magnum::Ui::BitStorage::operator StorageQuery<bool>() const

Single-bit storage value.

Equivalent to value(), see its documentation for more information.

std::size_t Magnum::Ui::BitStorage::size() const

Storage size.

Returns just the last component of AbstractStorage::size() as the storage is at most 1D.

bool Magnum::Ui::BitStorage::isMutable() const

Whether the storage is mutable.

Returns true if the storage is owned (i.e., created using the ValueInit, NoInit or DirectInit constructor) or if it's created using the NonOwned constructor from a mutable view or bit reference, false otherwise.

Immutable storages return immutable queries from value() and operator[]() and don't allow accessing mutableData().

const BitStorage& Magnum::Ui::BitStorage::setDefaultValue(bool value) const

Set default value.

Returns Reference to self (for method chaining)

The default value is used when calling StorageQuery::reset(). Initially is set to either false or the value that was passed to the BitStorage(Owner&, DirectInitT, std::size_t, bool, StorageFlags) constructor.

Calling this function does not cause the storage to be marked as dirty, as it doesn't have any effect on existing values.

StorageQuery<bool> Magnum::Ui::BitStorage::value() const

Single-item storage value.

Expects that size() is 1. If it's not, use operator[]().

See documentation of operator[]() for details about what is all supported by the returned query.

StorageQuery<bool> Magnum::Ui::BitStorage::operator->() const

Single-bit storage value.

Equivalent to value(), see its documentation for more information.

StorageQuery<bool> Magnum::Ui::BitStorage::operator[](std::size_t index) const

1D storage value at given index

Expects that index is less than size().

Unless the storage is non-owned and immutable, the query implements also an updater accepting StorageOperation::Set, Reset and Toggle.

Containers::StridedBitArrayView1D Magnum::Ui::BitStorage::data() const

Raw storage data.

For mutable access use either mutableData() or the StorageQuery instances returned by value() and operator[]().

In case of an owned storage (created using the ValueInit, NoInit or DirectInit constructor variants) the returned view is contiguous with a size of size(), and the view is only guaranteed to be valid for as long as no new storages are created in the underlying DataLayer. In case of a non-owned storage (created using the NonOwned constructor) the returned view matches the one passed to the constructor.

Containers::MutableStridedBitArrayView1D Magnum::Ui::BitStorage::mutableData() const

Raw mutable storage data.

Like data() const, but returns a mutable view. Expects that the storage is either owned or non-owned and mutable. Meant to be used mainly for filling a storage created using the NoInit constructor variant, or for batch updates. Note that the user is responsible for calling setDirty() upon a modification in order to correctly trigger updates on associated data bindings.