Magnum::Trade::MaterialAttributeData class new in Git master

Material attribute data.

See MaterialData for more information.

Constructors, destructors, conversion operators

MaterialAttributeData() explicit constexpr noexcept
Default constructor.
template<class T>
MaterialAttributeData(Containers::StringView name, const T& value) constexpr noexcept
Construct with a string name.
MaterialAttributeData(Containers::StringView name, Containers::StringView value) constexpr noexcept
Construct with a string name and string value.
template<class T>
MaterialAttributeData(MaterialAttribute name, const T& value) noexcept
Construct with a predefined name.
MaterialAttributeData(MaterialAttribute name, Containers::StringView value) noexcept
Construct with a predefined name and string value.
MaterialAttributeData(Containers::StringView name, MaterialAttributeType type, const void* value) noexcept
Construct from a type-erased value.
MaterialAttributeData(MaterialAttribute name, MaterialAttributeType type, const void* value) noexcept
Construct with a predefined name.
MaterialAttributeData(MaterialLayer layerName) noexcept
Construct a layer name attribute.

Public functions

auto type() const -> MaterialAttributeType
Attribute type.
auto name() const -> Containers::StringView
Attribute name.
auto value() const -> const void*
Type-erased attribute value.
template<class T>
auto value() const -> T
Attribute value.

Function documentation

Magnum::Trade::MaterialAttributeData::MaterialAttributeData() explicit constexpr noexcept

Default constructor.

Leaves contents at unspecified values. Provided as a convenience for initialization of the attribute array for MaterialData, expected to be replaced with concrete values later.

template<class T>
Magnum::Trade::MaterialAttributeData::MaterialAttributeData(Containers::StringView name, const T& value) constexpr noexcept

Construct with a string name.

Parameters
name Attribute name
value Attribute value

The name together with value is expected to fit into 62 bytes. MaterialAttributeType is inferred from the type passed.

This function is useful in constexpr contexts and for creating custom material attributes. For known attributes prefer to use MaterialAttributeData(MaterialAttribute, const T&) if you don't need constexpr, as it additionally checks that given attribute has the expected type.

Magnum::Trade::MaterialAttributeData::MaterialAttributeData(Containers::StringView name, Containers::StringView value) constexpr noexcept

Construct with a string name and string value.

Parameters
name Attribute name
value Attribute value

The combined length of name and value is expected to fit into 61 bytes. Type is set to MaterialAttributeType::String.

This function is useful in constexpr contexts and for creating custom material attributes. For known attributes prefer to use MaterialAttributeData(MaterialAttribute, const T&) if you don't need constexpr, as it additionally checks that given attribute has the expected type.

template<class T>
Magnum::Trade::MaterialAttributeData::MaterialAttributeData(MaterialAttribute name, const T& value) noexcept

Construct with a predefined name.

Parameters
name Attribute name
value Attribute value

Compared to MaterialAttributeData(Containers::StringView, const T&) checks that the attribute is in expected type. The MaterialAttribute gets converted to a corresponding string name. Apart from the type check, the following two instances are equivalent:

Trade::MaterialAttributeData a{
    Trade::MaterialAttribute::DiffuseColor, 0x3bd267ff_srgbaf};
Trade::MaterialAttributeData b{"DiffuseColor", 0x3bd267ff_srgbaf};

Magnum::Trade::MaterialAttributeData::MaterialAttributeData(MaterialAttribute name, Containers::StringView value) noexcept

Construct with a predefined name and string value.

Parameters
name Attribute name
value Attribute value

Compared to MaterialAttributeData(Containers::StringView, Containers::StringView) checks that the attribute is in expected type. The MaterialAttribute gets converted to a corresponding string name. Apart from the type check, the following two instances are equivalent:

Trade::MaterialAttributeData a{
    Trade::MaterialAttribute::DiffuseColor, 0x3bd267ff_srgbaf};
Trade::MaterialAttributeData b{"DiffuseColor", 0x3bd267ff_srgbaf};

Magnum::Trade::MaterialAttributeData::MaterialAttributeData(Containers::StringView name, MaterialAttributeType type, const void* value) noexcept

Construct from a type-erased value.

Parameters
name Attribute name
type Attribute type
value Type-erased value

In case type is not MaterialAttributeType::String, copies a number of bytes according to materialAttributeTypeSize() from value. The name together with value is expected to fit into 62 bytes.

In case type is MaterialAttributeType::String, value is expected to point to a Containers::StringView. The combined length of name and value strings is expected to fit into 61 bytes.

Magnum::Trade::MaterialAttributeData::MaterialAttributeData(MaterialAttribute name, MaterialAttributeType type, const void* value) noexcept

Construct with a predefined name.

Parameters
name Attribute name
type Attribute type
value Attribute value

Compared to MaterialAttributeData(Containers::StringView, MaterialAttributeType, const void*) checks that the attribute is in expected type. The MaterialAttribute gets converted to a corresponding string name.

Magnum::Trade::MaterialAttributeData::MaterialAttributeData(MaterialLayer layerName) noexcept

Construct a layer name attribute.

Parameters
layerName Material layer name

Equivalent to calling MaterialAttributeData(MaterialAttribute, Containers::StringView) with MaterialAttribute::LayerName and a string corresponding to layerName.

Containers::StringView Magnum::Trade::MaterialAttributeData::name() const

Attribute name.

The returned view always has Corrade::Containers::StringViewFlag::NullTerminated set.

const void* Magnum::Trade::MaterialAttributeData::value() const

Type-erased attribute value.

Cast the pointer to a concrete type based on type(). Note that in case of a MaterialAttributeType::Pointer or a MaterialAttributeType::MutablePointer, returns a pointer to a pointer, not the pointer value itself.

In case of a MaterialAttributeType::String, returns a null-terminated const char* (not a pointer to Containers::StringView). This doesn't preserve the actual string size in case the string data contain zero bytes, thus prefer to use typed access in that case.

template<class T>
T Magnum::Trade::MaterialAttributeData::value() const

Attribute value.

Expects that T corresponds to type().