Struct meta_ctor
Synopsis
#include <src/entt/meta/meta.hpp>
struct meta_ctor
Description
Opaque wrapper for meta constructors.
Mentioned in
- Runtime Reflection System / Enjoy the runtime
Methods
meta_ctor | Constructs an instance from a given node. | |
arg | Returns the meta type of the i-th argument of a meta constructor. | |
invoke overload | Creates an instance of the underlying type, if possible. | |
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. | |
size | Returns the number of arguments accepted by a meta constructor. |
Source
Lines 745-832 in src/entt/meta/meta.hpp.
struct meta_ctor {
/*! @brief Node type. */
using node_type = internal::meta_ctor_node;
/*! @brief Unsigned integer type. */
using size_type = typename node_type::size_type;
/*! @copydoc meta_prop::meta_prop */
meta_ctor(const node_type *curr = nullptr) ENTT_NOEXCEPT
: node{curr}
{}
/*! @copydoc meta_base::parent */
[[nodiscard]] inline meta_type parent() const ENTT_NOEXCEPT;
/**
* @brief Returns the number of arguments accepted by a meta constructor.
* @return The number of arguments accepted by the meta constructor.
*/
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
return node->size;
}
/**
* @brief Returns the meta type of the i-th argument of a meta constructor.
* @param index The index of the argument of which to return the meta type.
* @return The meta type of the i-th argument of a meta constructor, if any.
*/
[[nodiscard]] meta_type arg(size_type index) const ENTT_NOEXCEPT;
/**
* @brief Creates an instance of the underlying type, if possible.
*
* To create a valid instance, the parameters must be such that a cast or
* conversion to the required types is possible. Otherwise, an empty and
* thus invalid wrapper is returned.
*
* @param args Parameters to use to construct the instance.
* @param sz Number of parameters to use to construct the instance.
* @return A meta any containing the new instance, if any.
*/
[[nodiscard]] meta_any invoke(meta_any * const args, const size_type sz) const {
return sz == size() ? node->invoke(args) : meta_any{};
}
/**
* @copybrief invoke
*
* @sa invoke
*
* @tparam Args Types of arguments to use to construct the instance.
* @param args Parameters to use to construct the instance.
* @return A meta any containing the new instance, if any.
*/
template<typename... Args>
[[nodiscard]] meta_any invoke([[maybe_unused]] Args &&... args) const {
std::array<meta_any, sizeof...(Args)> arguments{std::forward<Args>(args)...};
return invoke(arguments.data(), sizeof...(Args));
}
/**
* @brief Returns a range to use to visit all meta properties.
* @return An iterable range to use to visit all meta properties.
*/
[[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;
};