template<class T>
Magnum::Ui::EnumStorage class new in Git master

Enum value storage.

Owns or references a single enum value or their list, allowing storage queries to either access and update the enum value directly, or toggle individual choices in the enum.

The template can be used for any enum, enum class as well as builtin integer types, and a Containers::EnumSet. It's not allowed to use this storage with a bool type, use a BitStorage in that case instead.

Base classes

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

Public types

using Type = T
Storage and query type.
using ValueType = Implementation::EnumStorageTraits<T>::ValueType
Enum value type.

Constructors, destructors, conversion operators

template<class Owner>
EnumStorage(Owner& owner, ValueInitT, StorageFlags flags = {}) explicit
Construct a value-initialized single-item storage.
template<class Owner>
EnumStorage(Owner& owner, ValueInitT, std::size_t size, StorageFlags flags = {}) explicit
Construct a value-initialized 1D storage.
template<class Owner>
EnumStorage(Owner& owner, NoInitT, StorageFlags flags = {}) explicit
Construct a single-item storage without initializing its contents.
template<class Owner>
EnumStorage(Owner& owner, NoInitT, std::size_t size, StorageFlags flags = {}) explicit
Construct a 1D storage without initializing its contents.
template<class Owner>
EnumStorage(Owner& owner, DirectInitT, T value, StorageFlags flags = {}) explicit
Construct a direct-initialized single-item storage.
template<class Owner>
EnumStorage(Owner& owner, DirectInitT, std::size_t size, T value, StorageFlags flags = {}) explicit
Construct a direct-initialized 1D storage.
template<class Owner>
EnumStorage(Owner& owner, NonOwnedT, T& value, StorageFlags flags = {}) explicit
Construct a non-owned single-item storage.
template<class Owner>
EnumStorage(Owner& owner, NonOwnedT, const T& value, StorageFlags flags = {}) explicit
template<class Owner>
EnumStorage(Owner& owner, NonOwnedT, T&& value, StorageFlags flags = {}) deleted explicit
Constructing a non-owned storage from a r-value reference is not allowed.
template<class Owner>
EnumStorage(Owner& owner, NonOwnedT, const T&& value, StorageFlags flags = {}) deleted explicit
Constructing a non-owned storage from a r-value reference is not allowed.
template<class Owner>
EnumStorage(Owner& owner, NonOwnedT, const Containers::StridedArrayView1D<T>& values, StorageFlags flags = {}) explicit
Construct a non-owned 1D storage.
template<class Owner>
EnumStorage(Owner& owner, NonOwnedT, const Containers::StridedArrayView1D<const T>& 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>
EnumStorage(Owner& owner, StorageFlags flags = {}) explicit
Construct a value-initialized single-item storage.
template<class Owner>
EnumStorage(Owner& owner, std::size_t size, StorageFlags flags = {}) explicit
Construct a value-initialized 1D storage.
operator StorageQuery<T>() const
Single-item storage value.

Public functions

auto size() const -> std::size_t
Storage size.
auto isMutable() const -> bool
Whether the storage is mutable.
auto defaultValue() const -> T
Default value.
auto setDefaultValue(T value) const -> const EnumStorage<T>&
Set default value.
auto isEnumSet() const -> bool
Whether the storage behaves like an enum set.
auto setEnumSet(bool set) const -> const EnumStorage<T>&
Set the storage to behave like an enum set.
auto value() const -> StorageQuery<T>
Single-item storage value.
auto operator->() const -> StorageQuery<T>
Single-item storage value.
auto operator[](std::size_t index) const -> StorageQuery<T>
1D storage value at given index
template<ValueType expected>
auto value() const -> StorageQuery<bool>
Single-item storage value presence.
template<ValueType expected>
auto value(std::size_t index) const -> StorageQuery<bool>
1D storage value presence at given index
auto data() const -> Containers::StridedArrayView1D<const T>
Raw storage data.
auto mutableData() const -> Containers::StridedArrayView1D<T>
Raw mutable storage data.

Typedef documentation

template<class T>
typedef Implementation::EnumStorageTraits<T>::ValueType Magnum::Ui::EnumStorage<T>::ValueType

Enum value type.

Equal to Type for enum and integer types, and to Containers::EnumSet::Type for an Containers::EnumSet.

Function documentation

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

Construct a value-initialized single-item storage.

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

template<class T> template<class Owner>
Magnum::Ui::EnumStorage<T>::EnumStorage(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 EnumStorage(Owner&, NoInitT, std::size_t, StorageFlags) and then initializes the storage to zero values. See the documentation of EnumStorage(Owner&, NoInitT, std::size_t, StorageFlags) for more information.

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

Construct a single-item storage without initializing its contents.

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

template<class T> template<class Owner>
Magnum::Ui::EnumStorage<T>::EnumStorage(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 T> template<class Owner>
Magnum::Ui::EnumStorage<T>::EnumStorage(Owner& owner, DirectInitT, T value, StorageFlags flags = {}) explicit

Construct a direct-initialized single-item storage.

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

template<class T> template<class Owner>
Magnum::Ui::EnumStorage<T>::EnumStorage(Owner& owner, DirectInitT, std::size_t size, T 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 EnumStorage(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 EnumStorage(Owner&, NoInitT, std::size_t, StorageFlags) for more information.

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

Construct a non-owned single-item storage.

Equivalent to calling EnumStorage(Owner&, NonOwnedT, const Containers::StridedArrayView1D<T>&, StorageFlags) with value turned into a view of size 1.

template<class T> template<class Owner>
Magnum::Ui::EnumStorage<T>::EnumStorage(Owner& owner, NonOwnedT, const T& 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 T> template<class Owner>
Magnum::Ui::EnumStorage<T>::EnumStorage(Owner& owner, NonOwnedT, T&& 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 T> template<class Owner>
Magnum::Ui::EnumStorage<T>::EnumStorage(Owner& owner, NonOwnedT, const T&& 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 T> template<class Owner>
Magnum::Ui::EnumStorage<T>::EnumStorage(Owner& owner, NonOwnedT, const Containers::StridedArrayView1D<T>& 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 T> template<class Owner>
Magnum::Ui::EnumStorage<T>::EnumStorage(Owner& owner, NonOwnedT, const Containers::StridedArrayView1D<const T>& 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 T> template<class Owner, typename std::enable_if<std::is_convertible<Owner&, DataLayer&>::value||std::is_convertible<Owner&, AbstractUserInterface&>::value, int>::type = 0>
Magnum::Ui::EnumStorage<T>::EnumStorage(Owner& owner, StorageFlags flags = {}) explicit

Construct a value-initialized single-item storage.

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

template<class T>
Magnum::Ui::EnumStorage<T>::operator StorageQuery<T>() const

Single-item storage value.

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

template<class T>
std::size_t Magnum::Ui::EnumStorage<T>::size() const

Storage size.

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

template<class T>
bool Magnum::Ui::EnumStorage<T>::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 value reference, false otherwise.

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

template<class T>
const EnumStorage<T>& Magnum::Ui::EnumStorage<T>::setDefaultValue(T 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 T{} or the value that was passed to the EnumStorage(Owner&, DirectInitT, std::size_t, T, 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.

template<class T>
const EnumStorage<T>& Magnum::Ui::EnumStorage<T>::setEnumSet(bool set) const

Set the storage to behave like an enum set.

By default, for enum types and plain integers, the storage behaves like an enum, allowing to pick exactly one of the possible enumerated values via the value<expected>() queries — the query being true if expected is equal to the stored value. In other words, behaving like radio buttons.

For Containers::EnumSet types it's by default behaving like an enum set, allowing to pick a set of values, with value<expected>() queries being true if expected is a bitwise subset of the stored value. In other words, behaving like checkboxes.

This function allows to switch the default, such as when a bitmask is represented by a plain integer instead of a Containers::EnumSet.

template<class T>
StorageQuery<T> Magnum::Ui::EnumStorage<T>::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.

template<class T>
StorageQuery<T> Magnum::Ui::EnumStorage<T>::operator->() const

Single-item storage value.

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

template<class T>
StorageQuery<T> Magnum::Ui::EnumStorage<T>::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 and Reset.

template<class T> template<ValueType expected>
StorageQuery<bool> Magnum::Ui::EnumStorage<T>::value() const

Single-item storage value presence.

Expects that size() is 1. If it's not, use value(std::size_t) const.

See documentation of value(std::size_t) const for details about what is all supported by the returned query.

template<class T> template<ValueType expected>
StorageQuery<bool> Magnum::Ui::EnumStorage<T>::value(std::size_t index) const

1D storage value presence at given index

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

For enum storages, the query is true if expected is equal to the stored value. If the storage is mutable, StorageOperation::Set to true sets the stored value to expected and StorageOperation::Toggle sets the stored value to expected if it's not already, both returning StorageUpdateState::Success. StorageOperation::Set to false, StorageOperation::Reset and StorageOperation::Toggle if the storage value is already expected result in StorageUpdateState::Failed, as there's no generally unambiguous semantics for those operations.

For enum set storages, the query is true if expected is a bitwise subset of expected. If the storage is mutable, StorageOperation::Set sets or resets bits of expected in the stored value, StorageOperation::Reset sets bits of expected to their value in defaultValue(), StorageOperation::Toggle sets bits of expected if the stored value doesn't have them all set, and resets them if the stored value has them all set.

template<class T>
Containers::StridedArrayView1D<const T> Magnum::Ui::EnumStorage<T>::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 tightly packed 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.

template<class T>
Containers::StridedArrayView1D<T> Magnum::Ui::EnumStorage<T>::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.