Struct meta_func
Synopsis
#include <src/entt/meta/meta.hpp>
struct meta_func
Description
Opaque wrapper for member functions.
Mentioned in
- Runtime Reflection System / Enjoy the runtime
Methods
meta_func | Constructs an instance from a given node. | |
arg | Returns the type of the i-th argument of a member function. | |
arity | Returns the number of arguments accepted by a member function. | |
id | Returns the identifier assigned to a type. | |
invoke overload | Invokes the underlying function, if possible. | |
is_const | Indicates whether a member function is constant or not. | |
is_static | Indicates whether a member function is static or not. | |
operator bool | Returns true if an object is valid, false otherwise. | |
prop overload | Returns a range to visit registered meta properties. | |
prop overload | Lookup function for registered meta properties. | |
ret | Returns the return type of a member function. |
Source
Lines 830-946 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;
}
/**
* @brief Returns the number of arguments accepted by a member function.
* @return The number of arguments accepted by the member function.
*/
[[nodiscard]] size_type arity() const ENTT_NOEXCEPT {
return node->arity;
}
/**
* @brief Indicates whether a member function is constant or not.
* @return True if the member function is constant, false otherwise.
*/
[[nodiscard]] bool is_const() const ENTT_NOEXCEPT {
return !!(node->traits & internal::meta_traits::is_const);
}
/**
* @brief Indicates whether a member function is static or not.
* @return True if the member function is static, false otherwise.
*/
[[nodiscard]] bool is_static() const ENTT_NOEXCEPT {
return !!(node->traits & internal::meta_traits::is_static);
}
/**
* @brief Returns the return type of a member function.
* @return The return type of the member function.
*/
[[nodiscard]] inline meta_type ret() const ENTT_NOEXCEPT;
/**
* @brief Returns the type of the i-th argument of a member function.
* @param index Index of the argument of which to return the type.
* @return The type of the i-th argument of a member function.
*/
[[nodiscard]] inline meta_type arg(const size_type index) const ENTT_NOEXCEPT;
/**
* @brief Invokes the underlying function, if possible.
*
* To invoke a member 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 member
* function.
*
* @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 wrapper containing the returned value, if any.
*/
meta_any invoke(meta_handle instance, meta_any *const args, const size_type sz) const {
return sz == arity() ? 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 wrapper containing the new instance, if any.
*/
template<typename... Args>
meta_any invoke(meta_handle instance, Args &&...args) const {
meta_any arguments[sizeof...(Args) + 1u]{std::forward<Args>(args)...};
return invoke(std::move(instance), arguments, sizeof...(Args));
}
/*! @copydoc meta_data::prop */
[[nodiscard]] meta_range<meta_prop> prop() const ENTT_NOEXCEPT {
return node->prop;
}
/**
* @brief Lookup function for registered meta properties.
* @param key The key to use to search for a property.
* @return The registered meta property for the given key, if any.
*/
[[nodiscard]] meta_prop prop(meta_any key) const {
for(auto curr: prop()) {
if(curr.key() == key) {
return curr;
}
}
return nullptr;
}
/**
* @brief Returns true if an object is valid, false otherwise.
* @return True if the object is valid, false otherwise.
*/
[[nodiscard]] explicit operator bool() const ENTT_NOEXCEPT {
return !(node == nullptr);
}
private:
const node_type *node;
};