Skip to content

Commit

Permalink
meta: prepare meta_base/meta_conv/meta_ctor rework
Browse files Browse the repository at this point in the history
  • Loading branch information
skypjack committed Aug 26, 2024
1 parent 116bb91 commit 94735d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/entt/meta/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ class basic_meta_factory {
}

template<typename Type>
void insert_or_assign(const id_type id, Type node) {
void insert_or_assign(Type node) {
reset_bucket(parent);

if constexpr(std::is_same_v<Type, meta_base_node>) {
details->base.insert_or_assign(id, node);
details->base.insert_or_assign(node.id, node);
} else if constexpr(std::is_same_v<Type, meta_conv_node>) {
details->conv.insert_or_assign(id, node);
details->conv.insert_or_assign(node.type, node);
} else {
static_assert(std::is_same_v<Type, meta_ctor_node>, "Unexpected type");
details->ctor.insert_or_assign(id, node);
details->ctor.insert_or_assign(node.id, node);
}
}

Expand Down Expand Up @@ -221,7 +221,7 @@ class meta_factory: private internal::basic_meta_factory {
meta_factory base() noexcept {
static_assert(!std::is_same_v<Type, Base> && std::is_base_of_v<Base, Type>, "Invalid base type");
auto *const op = +[](const void *instance) noexcept { return static_cast<const void *>(static_cast<const Base *>(static_cast<const Type *>(instance))); };
base_type::insert_or_assign(type_id<Base>().hash(), internal::meta_base_node{&internal::resolve<Base>, op});
base_type::insert_or_assign(internal::meta_base_node{type_id<Base>().hash(), &internal::resolve<Base>, op});
return *this;
}

Expand All @@ -241,7 +241,7 @@ class meta_factory: private internal::basic_meta_factory {
auto conv() noexcept {
using conv_type = std::remove_cv_t<std::remove_reference_t<std::invoke_result_t<decltype(Candidate), Type &>>>;
auto *const op = +[](const meta_ctx &area, const void *instance) { return forward_as_meta(area, std::invoke(Candidate, *static_cast<const Type *>(instance))); };
base_type::insert_or_assign(type_id<conv_type>().hash(), internal::meta_conv_node{op});
base_type::insert_or_assign(internal::meta_conv_node{type_id<conv_type>().hash(), op});
return *this;
}

Expand All @@ -258,7 +258,7 @@ class meta_factory: private internal::basic_meta_factory {
meta_factory conv() noexcept {
using conv_type = std::remove_cv_t<std::remove_reference_t<To>>;
auto *const op = +[](const meta_ctx &area, const void *instance) { return forward_as_meta(area, static_cast<To>(*static_cast<const Type *>(instance))); };
base_type::insert_or_assign(type_id<conv_type>().hash(), internal::meta_conv_node{op});
base_type::insert_or_assign(internal::meta_conv_node{type_id<conv_type>().hash(), op});
return *this;
}

Expand All @@ -280,7 +280,7 @@ class meta_factory: private internal::basic_meta_factory {
using descriptor = meta_function_helper_t<Type, decltype(Candidate)>;
static_assert(Policy::template value<typename descriptor::return_type>, "Invalid return type for the given policy");
static_assert(std::is_same_v<std::remove_cv_t<std::remove_reference_t<typename descriptor::return_type>>, Type>, "The function doesn't return an object of the required type");
base_type::insert_or_assign(type_id<typename descriptor::args_type>().hash(), internal::meta_ctor_node{descriptor::args_type::size, &meta_arg<typename descriptor::args_type>, &meta_construct<Type, Candidate, Policy>});
base_type::insert_or_assign(internal::meta_ctor_node{type_id<typename descriptor::args_type>().hash(), descriptor::args_type::size, &meta_arg<typename descriptor::args_type>, &meta_construct<Type, Candidate, Policy>});
return *this;
}

Expand All @@ -299,7 +299,7 @@ class meta_factory: private internal::basic_meta_factory {
// default constructor is already implicitly generated, no need for redundancy
if constexpr(sizeof...(Args) != 0u) {
using descriptor = meta_function_helper_t<Type, Type (*)(Args...)>;
base_type::insert_or_assign(type_id<typename descriptor::args_type>().hash(), internal::meta_ctor_node{descriptor::args_type::size, &meta_arg<typename descriptor::args_type>, &meta_construct<Type, Args...>});
base_type::insert_or_assign(internal::meta_ctor_node{type_id<typename descriptor::args_type>().hash(), descriptor::args_type::size, &meta_arg<typename descriptor::args_type>, &meta_construct<Type, Args...>});
}

return *this;
Expand Down
3 changes: 3 additions & 0 deletions src/entt/meta/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,20 @@ struct meta_prop_node {
};

struct meta_base_node {
id_type id{};
meta_type_node (*type)(const meta_context &) noexcept {};
const void *(*cast)(const void *) noexcept {};
};

struct meta_conv_node {
id_type type{};
meta_any (*conv)(const meta_ctx &, const void *){};
};

struct meta_ctor_node {
using size_type = std::size_t;

id_type id{};
size_type arity{0u};
meta_type (*arg)(const meta_ctx &, const size_type) noexcept {};
meta_any (*invoke)(const meta_ctx &, meta_any *const){};
Expand Down

0 comments on commit 94735d0

Please sign in to comment.