Struct meta_data
Synopsis
#include <src/entt/meta/meta.hpp>
struct meta_data
Description
Opaque wrapper for meta data.
Mentioned in
- Runtime Reflection System / Enjoy the runtime
Methods
meta_data | Constructs an instance from a given node. | |
get | Gets the value of a given variable. | |
id | Returns the identifier assigned to a meta object. | |
is_const | Indicates whether a meta data is constant or not. | |
is_static | Indicates whether a meta data is static or not. | |
operator bool | Returns true if a meta object is valid, false otherwise. | |
parent | Returns the meta type to which a meta object belongs. | |
prop overload | Returns a range to use to visit all meta properties. | |
prop overload | Returns the property associated with a given key. | |
set | Sets the value of a given variable. | |
type | Returns the meta type of the underlying object. |
Source
Lines 836-929 in src/entt/meta/meta.hpp.
struct meta_data {
/*! @brief Node type. */
using node_type = internal::meta_data_node;
/*! @copydoc meta_prop::meta_prop */
meta_data(const node_type *curr = nullptr) ENTT_NOEXCEPT
: node{curr}
{}
/*! @copydoc meta_type::id */
[[nodiscard]] id_type id() const ENTT_NOEXCEPT {
return node->id;
}
/*! @copydoc meta_base::parent */
[[nodiscard]] inline meta_type parent() const ENTT_NOEXCEPT;
/**
* @brief Indicates whether a meta data is constant or not.
* @return True if the meta data is constant, false otherwise.
*/
[[nodiscard]] bool is_const() const ENTT_NOEXCEPT {
return (node->set == nullptr);
}
/**
* @brief Indicates whether a meta data is static or not.
* @return True if the meta data is static, false otherwise.
*/
[[nodiscard]] bool is_static() const ENTT_NOEXCEPT {
return node->is_static;
}
/*! @copydoc meta_any::type */
[[nodiscard]] inline meta_type type() const ENTT_NOEXCEPT;
/**
* @brief Sets the value of a given variable.
*
* It must be possible to cast the instance to the parent type of the meta
* data. Otherwise, invoking the setter results in an undefined
* behavior.<br/>
* The type of the value must be such that a cast or conversion to the type
* of the variable is possible. Otherwise, invoking the setter does nothing.
*
* @tparam Type Type of value to assign.
* @param instance An opaque instance of the underlying type.
* @param value Parameter to use to set the underlying variable.
* @return True in case of success, false otherwise.
*/
template<typename Type>
bool set(meta_handle instance, Type &&value) const {
return node->set && node->set(std::move(instance), std::forward<Type>(value));
}
/**
* @brief Gets the value of a given variable.
*
* It must be possible to cast the instance to the parent type of the meta
* data. Otherwise, invoking the getter results in an undefined behavior.
*
* @param instance An opaque instance of the underlying type.
* @return A meta any containing the value of the underlying variable.
*/
[[nodiscard]] meta_any get(meta_handle instance) const {
return node->get(std::move(instance));
}
/*! @copydoc meta_ctor::prop */
[[nodiscard]] meta_range<meta_prop> prop() const ENTT_NOEXCEPT {
return node->prop;
}
/**
* @brief Returns the property associated with a given key.
* @param key The key to use to search for a property.
* @return The property associated with the given key, if any.
*/
[[nodiscard]] meta_prop prop(meta_any key) const {
internal::meta_range range{node->prop};
return std::find_if(range.begin(), range.end(), [&key](const auto &curr) { return curr.key() == key; }).operator->();
}
/**
* @brief Returns true if a meta object is valid, false otherwise.
* @return True if the meta object is valid, false otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return !(node == nullptr);
}
private:
const node_type *node;
};