|
|
@@ -30,13 +30,14 @@ namespace internal {
|
|
|
class basic_meta_factory {
|
|
|
using invoke_type = std::remove_pointer_t<decltype(meta_func_node::invoke)>;
|
|
|
|
|
|
- auto *find_overload() {
|
|
|
- auto *curr = &details->func[bucket];
|
|
|
-
|
|
|
- while(curr->invoke != invoke) {
|
|
|
- curr = curr->next.get();
|
|
|
- }
|
|
|
+ template<typename Type>
|
|
|
+ auto *find_member(Type &from) {
|
|
|
+ return &from[bucket];
|
|
|
+ }
|
|
|
|
|
|
+ auto *find_overload() {
|
|
|
+ auto *curr = find_member(details->func);
|
|
|
+ for(; curr->invoke != invoke; curr = curr->next.get()) {}
|
|
|
return curr;
|
|
|
}
|
|
|
|
|
|
@@ -49,20 +50,17 @@ protected:
|
|
|
elem.id = id;
|
|
|
}
|
|
|
|
|
|
- void base(const id_type id, meta_base_node node) {
|
|
|
- details->base.insert_or_assign(id, node);
|
|
|
- invoke = nullptr;
|
|
|
- bucket = parent;
|
|
|
- }
|
|
|
-
|
|
|
- void conv(const id_type id, meta_conv_node node) {
|
|
|
- details->conv.insert_or_assign(id, node);
|
|
|
- invoke = nullptr;
|
|
|
- bucket = parent;
|
|
|
- }
|
|
|
+ template<typename Type>
|
|
|
+ void insert_or_assign(const id_type id, Type node) {
|
|
|
+ if constexpr(std::is_same_v<Type, meta_base_node>) {
|
|
|
+ details->base.insert_or_assign(id, node);
|
|
|
+ } else if constexpr(std::is_same_v<Type, meta_conv_node>) {
|
|
|
+ details->conv.insert_or_assign(id, node);
|
|
|
+ } else {
|
|
|
+ static_assert(std::is_same_v<Type, meta_ctor_node>, "Unexpected type");
|
|
|
+ details->ctor.insert_or_assign(id, node);
|
|
|
+ }
|
|
|
|
|
|
- void ctor(const id_type id, meta_ctor_node node) {
|
|
|
- details->ctor.insert_or_assign(id, node);
|
|
|
invoke = nullptr;
|
|
|
bucket = parent;
|
|
|
}
|
|
|
@@ -112,7 +110,7 @@ protected:
|
|
|
if(bucket == parent) {
|
|
|
details->prop[key] = std::move(value);
|
|
|
} else if(invoke == nullptr) {
|
|
|
- details->data[bucket].prop[key] = std::move(value);
|
|
|
+ find_member(details->data)->prop[key] = std::move(value);
|
|
|
} else {
|
|
|
find_overload()->prop[key] = std::move(value);
|
|
|
}
|
|
|
@@ -122,7 +120,7 @@ protected:
|
|
|
if(bucket == parent) {
|
|
|
meta_context::from(*ctx).value[bucket].traits |= value;
|
|
|
} else if(invoke == nullptr) {
|
|
|
- details->data[bucket].traits |= value;
|
|
|
+ find_member(details->data)->traits |= value;
|
|
|
} else {
|
|
|
find_overload()->traits |= value;
|
|
|
}
|
|
|
@@ -132,7 +130,7 @@ protected:
|
|
|
if(bucket == parent) {
|
|
|
meta_context::from(*ctx).value[bucket].custom = std::move(node);
|
|
|
} else if(invoke == nullptr) {
|
|
|
- details->data[bucket].custom = std::move(node);
|
|
|
+ find_member(details->data)->custom = std::move(node);
|
|
|
} else {
|
|
|
find_overload()->custom = std::move(node);
|
|
|
}
|
|
|
@@ -223,7 +221,7 @@ public:
|
|
|
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::base(type_id<Base>().hash(), internal::meta_base_node{&internal::resolve<Base>, op});
|
|
|
+ base_type::insert_or_assign(type_id<Base>().hash(), internal::meta_base_node{&internal::resolve<Base>, op});
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
@@ -243,7 +241,7 @@ public:
|
|
|
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::conv(type_id<conv_type>().hash(), internal::meta_conv_node{op});
|
|
|
+ base_type::insert_or_assign(type_id<conv_type>().hash(), internal::meta_conv_node{op});
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
@@ -260,7 +258,7 @@ public:
|
|
|
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::conv(type_id<conv_type>().hash(), internal::meta_conv_node{op});
|
|
|
+ base_type::insert_or_assign(type_id<conv_type>().hash(), internal::meta_conv_node{op});
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
@@ -282,7 +280,7 @@ public:
|
|
|
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::ctor(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(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>});
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
|
@@ -301,7 +299,7 @@ public:
|
|
|
// 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::ctor(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(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...>});
|
|
|
}
|
|
|
|
|
|
return *this;
|