mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-13 19:18:01 +07:00
remove resolve_poly_type, use resolve_type(T&&) instead
This commit is contained in:
@@ -22,11 +22,19 @@ namespace meta_hpp::detail
|
||||
concept check_base_info_enabled //
|
||||
= requires { typename T::meta_base_info; };
|
||||
|
||||
template < check_base_info_enabled T >
|
||||
using get_meta_base_info = typename T::meta_base_info;
|
||||
|
||||
template < typename T >
|
||||
concept check_poly_info_enabled //
|
||||
concept poly_info_enabled //
|
||||
= requires(type_registry& r, const T& v) {
|
||||
{ v.get_most_derived_meta_poly_info(r) } -> std::convertible_to<poly_info>;
|
||||
{ v.meta_poly_info(r) } -> std::convertible_to<poly_info>;
|
||||
};
|
||||
|
||||
template < poly_info_enabled T >
|
||||
poly_info get_meta_poly_info(type_registry& r, const T& v) {
|
||||
return v.meta_poly_info(r);
|
||||
}
|
||||
}
|
||||
|
||||
#define META_HPP_ENABLE_BASE_INFO(...) \
|
||||
@@ -39,7 +47,7 @@ private:
|
||||
META_HPP_ENABLE_BASE_INFO(__VA_ARGS__) \
|
||||
public: \
|
||||
META_HPP_DETAIL_IGNORE_OVERRIDE_WARNINGS_PUSH() \
|
||||
virtual ::meta_hpp::detail::poly_info get_most_derived_meta_poly_info(::meta_hpp::detail::type_registry& registry) const { \
|
||||
virtual ::meta_hpp::detail::poly_info meta_poly_info(::meta_hpp::detail::type_registry& registry) const { \
|
||||
using self_type = std::remove_cvref_t<decltype(*this)>; \
|
||||
return ::meta_hpp::detail::poly_info{.ptr = this, .type = registry.resolve_class_type<self_type>()}; \
|
||||
} \
|
||||
|
||||
@@ -37,10 +37,23 @@ namespace meta_hpp
|
||||
|
||||
template < typename T >
|
||||
// NOLINTNEXTLINE(*-missing-std-forward)
|
||||
[[nodiscard]] auto resolve_type(T&&) {
|
||||
[[nodiscard]] auto resolve_type(T&& from) {
|
||||
using namespace detail;
|
||||
|
||||
using raw_type = std::remove_cvref_t<T>;
|
||||
type_registry& registry = type_registry::instance();
|
||||
return registry.resolve_type<std::remove_cvref_t<T>>();
|
||||
|
||||
if constexpr ( std::is_class_v<raw_type> && std::is_polymorphic_v<raw_type> ) {
|
||||
static_assert(
|
||||
detail::poly_info_enabled<T>,
|
||||
"The class doesn't support polymorphic type resolving. "
|
||||
"Use the META_HPP_ENABLE_POLY_INFO macro to fix it."
|
||||
);
|
||||
return detail::get_meta_poly_info(registry, from).type;
|
||||
} else {
|
||||
(void)from;
|
||||
return registry.resolve_type<raw_type>();
|
||||
}
|
||||
}
|
||||
|
||||
template < typename... Ts >
|
||||
@@ -58,29 +71,6 @@ namespace meta_hpp
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < typename T >
|
||||
// NOLINTNEXTLINE(*-missing-std-forward)
|
||||
[[nodiscard]] auto resolve_poly_type(T&& from) {
|
||||
using namespace detail;
|
||||
|
||||
using raw_type = std::remove_cvref_t<T>;
|
||||
type_registry& registry = type_registry::instance();
|
||||
|
||||
if constexpr ( std::is_class_v<raw_type> ) {
|
||||
static_assert(
|
||||
detail::check_poly_info_enabled<raw_type>,
|
||||
"The class doesn't support polymorphic type resolving. Use the META_HPP_ENABLE_POLY_INFO macro to fix it."
|
||||
);
|
||||
return from.get_most_derived_meta_poly_info(registry).type;
|
||||
} else {
|
||||
(void)from;
|
||||
return registry.resolve_type<raw_type>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
{
|
||||
template < detail::class_kind Class, typename... Args >
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace meta_hpp::detail::class_type_data_impl
|
||||
});
|
||||
|
||||
if constexpr ( check_base_info_enabled<Target> ) {
|
||||
using target_base_info = typename Target::meta_base_info;
|
||||
using target_base_info = get_meta_base_info<Target>;
|
||||
target_base_info::for_each([&info]<class_kind TargetBase>() { //
|
||||
add_upcast_info<Class, TargetBase>(info);
|
||||
});
|
||||
@@ -53,7 +53,7 @@ namespace meta_hpp::detail::class_type_data_impl
|
||||
template < class_kind Class >
|
||||
void fill_upcast_info(new_base_info_t& info) {
|
||||
if constexpr ( check_base_info_enabled<Class> ) {
|
||||
using class_base_info = typename Class::meta_base_info;
|
||||
using class_base_info = get_meta_base_info<Class>;
|
||||
class_base_info::for_each([&info]<class_kind ClassBase>() {
|
||||
info.base_classes.push_back(resolve_type<ClassBase>());
|
||||
add_upcast_info<Class, ClassBase>(info);
|
||||
|
||||
@@ -22,8 +22,9 @@ namespace meta_hpp
|
||||
using to_data_type = std::remove_pointer_t<To>;
|
||||
|
||||
static_assert(
|
||||
detail::check_poly_info_enabled<from_data_type>,
|
||||
"The type doesn't support ucasts. Use the META_HPP_ENABLE_POLY_INFO macro to fix it."
|
||||
detail::poly_info_enabled<from_data_type>,
|
||||
"The type doesn't support ucasts. "
|
||||
"Use the META_HPP_ENABLE_POLY_INFO macro to fix it."
|
||||
);
|
||||
|
||||
if ( from == nullptr ) {
|
||||
@@ -34,7 +35,7 @@ namespace meta_hpp
|
||||
return from;
|
||||
} else {
|
||||
detail::type_registry& registry{detail::type_registry::instance()};
|
||||
const detail::poly_info& meta_info{from->get_most_derived_meta_poly_info(registry)};
|
||||
const detail::poly_info& meta_info{detail::get_meta_poly_info(registry, *from)};
|
||||
|
||||
// NOLINTNEXTLINE(*-const-cast)
|
||||
void* most_derived_object_ptr = const_cast<void*>(meta_info.ptr);
|
||||
@@ -56,8 +57,9 @@ namespace meta_hpp
|
||||
using to_data_type = std::remove_reference_t<To>;
|
||||
|
||||
static_assert(
|
||||
detail::check_poly_info_enabled<from_data_type>,
|
||||
"The type doesn't support ucasts. Use the META_HPP_ENABLE_POLY_INFO macro to fix it."
|
||||
detail::poly_info_enabled<from_data_type>,
|
||||
"The type doesn't support ucasts. "
|
||||
"Use the META_HPP_ENABLE_POLY_INFO macro to fix it."
|
||||
);
|
||||
|
||||
if ( to_data_type* ptr = ucast<to_data_type*>(std::addressof(from)) ) {
|
||||
|
||||
Reference in New Issue
Block a user