#include <Magnum/Ui/EnumStorage.h>
template<class T>
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::bool type, use a BitStorage in that case instead.
Base classes
- class AbstractStorage new in Git master
- Base for DataLayer storage implementations.
Public types
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::EnumStorage(Owner& owner, StorageFlags flags = {}) explicit
enable_if<std:: is_convertible<Owner&, DataLayer&>::value||std:: is_convertible<Owner&, AbstractUserInterface&>::value, int>::type = 0> - 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::
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 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:: |
| size | Storage size |
| flags | Storage flags |
Delegates to EnumStorage(Owner&, NoInitT, std::
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 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:: |
| 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::
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 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:: |
| size | Storage size |
| value | Value to initialize the storage with |
| flags | Storage flags |
Delegates to EnumStorage(Owner&, NoInitT, std::value. The value is subsequently also used as the default value instead of T{}. See the documentation of EnumStorage(Owner&, NoInitT, std::
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::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:: |
| 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::
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.
template<class T>
template<class Owner>
Magnum:: Ui:: EnumStorage<T>:: EnumStorage(Owner& owner,
std:: size_t size,
StorageFlags flags = {}) explicit
Construct a value-initialized 1D storage.
Alias to EnumStorage(Owner&, ValueInitT, std::
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::
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::T{} or the value that was passed to the EnumStorage(Owner&, DirectInitT, std::
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::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::
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::
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::
See documentation of value(std::
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::
For enum storages, the query is true if expected is equal to the stored value. If the storage is mutable, StorageOperation::true sets the stored value to expected and StorageOperation::expected if it's not already, both returning StorageUpdateState::false, StorageOperation::expected result in StorageUpdateState::
For enum set storages, the query is true if expected is a bitwise subset of expected. If the storage is mutable, StorageOperation::expected in the stored value, StorageOperation::expected to their value in defaultValue(), StorageOperation::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.