meta: make instances meta handles all around the codebase
This commit is contained in:
@@ -76,14 +76,14 @@ template<typename Type, typename... Args, std::size_t... Indexes>
|
||||
|
||||
|
||||
template<typename Type, auto Data>
|
||||
[[nodiscard]] bool setter([[maybe_unused]] meta_any instance, [[maybe_unused]] meta_any value) {
|
||||
[[nodiscard]] bool setter([[maybe_unused]] meta_handle instance, [[maybe_unused]] meta_any value) {
|
||||
bool accepted = false;
|
||||
|
||||
if constexpr(std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>> || std::is_member_function_pointer_v<decltype(Data)>) {
|
||||
using helper_type = meta_function_helper_t<decltype(Data)>;
|
||||
using data_type = std::tuple_element_t<!std::is_member_function_pointer_v<decltype(Data)>, typename helper_type::args_type>;
|
||||
|
||||
if(auto * const clazz = instance.try_cast<Type>(); clazz) {
|
||||
if(auto * const clazz = (*instance).try_cast<Type>(); clazz) {
|
||||
if(auto * const direct = value.try_cast<data_type>(); direct || value.convert<data_type>()) {
|
||||
std::invoke(Data, *clazz, direct ? *direct : value.cast<data_type>());
|
||||
accepted = true;
|
||||
@@ -93,7 +93,7 @@ template<typename Type, auto Data>
|
||||
using data_type = std::remove_cv_t<std::remove_reference_t<decltype(std::declval<Type>().*Data)>>;
|
||||
|
||||
if constexpr(!std::is_array_v<data_type>) {
|
||||
if(auto * const clazz = instance.try_cast<Type>(); clazz) {
|
||||
if(auto * const clazz = (*instance).try_cast<Type>(); clazz) {
|
||||
if(auto * const direct = value.try_cast<data_type>(); direct || value.convert<data_type>()) {
|
||||
std::invoke(Data, clazz) = (direct ? *direct : value.cast<data_type>());
|
||||
accepted = true;
|
||||
@@ -116,7 +116,7 @@ template<typename Type, auto Data>
|
||||
|
||||
|
||||
template<typename Type, auto Data, typename Policy>
|
||||
[[nodiscard]] meta_any getter([[maybe_unused]] meta_any instance) {
|
||||
[[nodiscard]] meta_any getter([[maybe_unused]] meta_handle instance) {
|
||||
auto dispatch = [](auto &&value) {
|
||||
if constexpr(std::is_same_v<Policy, as_void_t>) {
|
||||
return meta_any{std::in_place_type<void>, std::forward<decltype(value)>(value)};
|
||||
@@ -129,13 +129,13 @@ template<typename Type, auto Data, typename Policy>
|
||||
};
|
||||
|
||||
if constexpr(std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Data)>>> || std::is_member_function_pointer_v<decltype(Data)>) {
|
||||
auto * const clazz = instance.try_cast<Type>();
|
||||
auto * const clazz = (*instance).try_cast<Type>();
|
||||
return clazz ? dispatch(std::invoke(Data, *clazz)) : meta_any{};
|
||||
} else if constexpr(std::is_member_object_pointer_v<decltype(Data)>) {
|
||||
if constexpr(std::is_array_v<std::remove_cv_t<std::remove_reference_t<decltype(std::declval<Type>().*Data)>>>) {
|
||||
return meta_any{};
|
||||
} else {
|
||||
auto * const clazz = instance.try_cast<Type>();
|
||||
auto * const clazz = (*instance).try_cast<Type>();
|
||||
return clazz ? dispatch(std::invoke(Data, clazz)) : meta_any{};
|
||||
}
|
||||
} else if constexpr(std::is_pointer_v<std::decay_t<decltype(Data)>>) {
|
||||
@@ -151,7 +151,7 @@ template<typename Type, auto Data, typename Policy>
|
||||
|
||||
|
||||
template<typename Type, auto Candidate, typename Policy, std::size_t... Indexes>
|
||||
[[nodiscard]] meta_any invoke([[maybe_unused]] meta_any instance, meta_any *args, std::index_sequence<Indexes...>) {
|
||||
[[nodiscard]] meta_any invoke([[maybe_unused]] meta_handle instance, meta_any *args, std::index_sequence<Indexes...>) {
|
||||
using helper_type = meta_function_helper_t<decltype(Candidate)>;
|
||||
|
||||
auto dispatch = [](auto *... params) {
|
||||
@@ -179,7 +179,7 @@ template<typename Type, auto Candidate, typename Policy, std::size_t... Indexes>
|
||||
if constexpr(std::is_function_v<std::remove_reference_t<std::remove_pointer_t<decltype(Candidate)>>>) {
|
||||
return (std::get<Indexes>(direct) && ...) ? dispatch(std::get<Indexes>(direct)...) : meta_any{};
|
||||
} else {
|
||||
auto * const clazz = instance.try_cast<Type>();
|
||||
auto * const clazz = (*instance).try_cast<Type>();
|
||||
return (clazz && (std::get<Indexes>(direct) && ...)) ? dispatch(clazz, std::get<Indexes>(direct)...) : meta_any{};
|
||||
}
|
||||
}
|
||||
@@ -682,7 +682,7 @@ public:
|
||||
!std::is_member_function_pointer_v<decltype(Candidate)>,
|
||||
&internal::meta_info<std::conditional_t<std::is_same_v<Policy, as_void_t>, void, typename helper_type::return_type>>::resolve,
|
||||
&helper_type::arg,
|
||||
[](meta_any instance, meta_any *args) {
|
||||
[](meta_handle instance, meta_any *args) {
|
||||
return internal::invoke<Type, Candidate, Policy>(std::move(instance), args, std::make_index_sequence<std::tuple_size_v<typename helper_type::args_type>>{});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace entt {
|
||||
|
||||
|
||||
class meta_any;
|
||||
struct meta_handle;
|
||||
|
||||
|
||||
/**
|
||||
@@ -78,8 +79,8 @@ struct meta_data_node {
|
||||
meta_prop_node * prop;
|
||||
const bool is_static;
|
||||
meta_type_node *(* const type)() ENTT_NOEXCEPT;
|
||||
bool(* const set)(meta_any, meta_any);
|
||||
meta_any(* const get)(meta_any);
|
||||
bool(* const set)(meta_handle, meta_any);
|
||||
meta_any(* const get)(meta_handle);
|
||||
};
|
||||
|
||||
|
||||
@@ -94,7 +95,7 @@ struct meta_func_node {
|
||||
const bool is_static;
|
||||
meta_type_node *(* const ret)() ENTT_NOEXCEPT;
|
||||
meta_type_node *(* const arg)(size_type) ENTT_NOEXCEPT;
|
||||
meta_any(* const invoke)(meta_any, meta_any *);
|
||||
meta_any(* const invoke)(meta_handle, meta_any *);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -333,7 +333,7 @@ public:
|
||||
* @brief Indirection operator for aliasing construction.
|
||||
* @return A meta any that shares a reference to an unmanaged object.
|
||||
*/
|
||||
[[nodiscard]] meta_any operator *() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] meta_any operator*() const ENTT_NOEXCEPT {
|
||||
return ref();
|
||||
}
|
||||
|
||||
@@ -432,8 +432,8 @@ struct meta_handle {
|
||||
}
|
||||
|
||||
/*! @copydoc meta_any::operator* */
|
||||
[[nodiscard]] meta_any operator *() const {
|
||||
return *any;
|
||||
[[nodiscard]] meta_any operator*() const {
|
||||
return any;
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -711,7 +711,7 @@ struct meta_data {
|
||||
*/
|
||||
template<typename Type>
|
||||
bool set(meta_handle instance, Type &&value) const {
|
||||
return node->set && node->set(*instance, std::forward<Type>(value));
|
||||
return node->set && node->set(std::move(instance), std::forward<Type>(value));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -724,7 +724,7 @@ struct meta_data {
|
||||
* @return A meta any containing the value of the underlying variable.
|
||||
*/
|
||||
[[nodiscard]] meta_any get(meta_handle instance) const {
|
||||
return node->get(*instance);
|
||||
return node->get(std::move(instance));
|
||||
}
|
||||
|
||||
/*! @copydoc meta_ctor::prop */
|
||||
@@ -843,8 +843,18 @@ struct meta_func {
|
||||
*/
|
||||
template<typename... Args>
|
||||
meta_any invoke(meta_handle instance, Args &&... args) const {
|
||||
meta_any arguments[]{*instance, std::forward<Args>(args)...};
|
||||
return sizeof...(Args) == size() ? node->invoke(arguments[0], &arguments[sizeof...(Args) != 0]) : meta_any{};
|
||||
meta_any any{};
|
||||
|
||||
if(sizeof...(Args) == size()) {
|
||||
if constexpr(sizeof...(Args) == 0) {
|
||||
any = node->invoke(std::move(instance), nullptr);
|
||||
} else {
|
||||
meta_any arguments[]{std::forward<Args>(args)...};
|
||||
any = node->invoke(std::move(instance), arguments);
|
||||
}
|
||||
}
|
||||
|
||||
return any;
|
||||
}
|
||||
|
||||
/*! @copydoc meta_ctor::prop */
|
||||
|
||||
Reference in New Issue
Block a user