Struct meta_func
Synopsis
#include <src/entt/meta/meta.hpp>
struct meta_func
Description
Opaque wrapper for meta functions.
Mentioned in
- Runtime Reflection System / Enjoy the runtime
Methods
meta_func | Constructs an instance from a given node. | |
arg | Returns the meta type of the i-th argument of a meta function. | |
id | Returns the identifier assigned to a meta object. | |
invoke overload | Invokes the underlying function, if possible. | |
is_const | Indicates whether a meta function is constant or not. | |
is_static | Indicates whether a meta function 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. | |
ret | Returns the meta type of the return type of a meta function. | |
size | Returns the number of arguments accepted by a meta function. |
Source
Lines 933-1049 in src/entt/meta/meta.hpp.
struct meta_func {
/*! @brief Node type. */
using node_type = internal::meta_func_node;
/*! @brief Unsigned integer type. */
using size_type = typename node_type::size_type;
/*! @copydoc meta_prop::meta_prop */
meta_func(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 Returns the number of arguments accepted by a meta function.
* @return The number of arguments accepted by the meta function.
*/
[[nodiscard]] size_type size() const ENTT_NOEXCEPT {
return node->size;
}
/**
* @brief Indicates whether a meta function is constant or not.
* @return True if the meta function is constant, false otherwise.
*/
[[nodiscard]] bool is_const() const ENTT_NOEXCEPT {
return node->is_const;
}
/**
* @brief Indicates whether a meta function is static or not.
* @return True if the meta function is static, false otherwise.
*/
[[nodiscard]] bool is_static() const ENTT_NOEXCEPT {
return node->is_static;
}
/**
* @brief Returns the meta type of the return type of a meta function.
* @return The meta type of the return type of the meta function.
*/
[[nodiscard]] inline meta_type ret() const ENTT_NOEXCEPT;
/**
* @brief Returns the meta type of the i-th argument of a meta function.
* @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 function, if any.
*/
[[nodiscard]] inline meta_type arg(size_type index) const ENTT_NOEXCEPT;
/**
* @brief Invokes the underlying function, if possible.
*
* To invoke a meta function, 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.<br/>
* It must be possible to cast the instance to the parent type of the meta
* function. Otherwise, invoking the underlying function results in an
* undefined behavior.
*
* @param instance An opaque instance of the underlying type.
* @param args Parameters to use to invoke the function.
* @param sz Number of parameters to use to invoke the function.
* @return A meta any containing the returned value, if any.
*/
meta_any invoke(meta_handle instance, meta_any * const args, const size_type sz) const {
return sz == size() ? node->invoke(std::move(instance), args) : meta_any{};
}
/**
* @copybrief invoke
*
* @sa invoke
*
* @tparam Args Types of arguments to use to invoke the function.
* @param instance An opaque instance of the underlying type.
* @param args Parameters to use to invoke the function.
* @return A meta any containing the new instance, if any.
*/
template<typename... Args>
meta_any invoke(meta_handle instance, Args &&... args) const {
std::array<meta_any, sizeof...(Args)> arguments{std::forward<Args>(args)...};
return invoke(std::move(instance), arguments.data(), sizeof...(Args));
}
/*! @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;
};