mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-15 03:45:30 +07:00
instance type for field and method infos
This commit is contained in:
@@ -81,6 +81,13 @@ namespace meta_hpp::field_detail
|
||||
using value_type = typename ft::value_type;
|
||||
return get_family_id<value_type>();
|
||||
}
|
||||
|
||||
template < typename FieldType >
|
||||
family_id make_instance_type() noexcept {
|
||||
using ft = detail::field_traits<FieldType>;
|
||||
using instance_type = typename ft::instance_type;
|
||||
return get_family_id<instance_type>();
|
||||
}
|
||||
}
|
||||
|
||||
namespace meta_hpp
|
||||
@@ -103,6 +110,10 @@ namespace meta_hpp
|
||||
return value_type_;
|
||||
}
|
||||
|
||||
family_id instance_type() const noexcept {
|
||||
return instance_type_;
|
||||
}
|
||||
|
||||
value get(cinstance instance) const {
|
||||
return getter_(instance);
|
||||
}
|
||||
@@ -142,11 +153,13 @@ namespace meta_hpp
|
||||
field_info(std::string id, FieldType field_ptr)
|
||||
: id_{std::move(id)}
|
||||
, value_type_{field_detail::make_value_type<FieldType>()}
|
||||
, instance_type_{field_detail::make_instance_type<FieldType>()}
|
||||
, getter_{field_detail::make_getter(field_ptr)}
|
||||
, setter_{field_detail::make_setter(field_ptr)} {}
|
||||
private:
|
||||
std::string id_;
|
||||
family_id value_type_;
|
||||
family_id instance_type_;
|
||||
field_detail::field_getter getter_;
|
||||
field_detail::field_setter setter_;
|
||||
std::map<std::string, data_info, std::less<>> datas_;
|
||||
|
||||
@@ -132,10 +132,17 @@ namespace meta_hpp::method_detail
|
||||
return std::bind(&raw_cinvoke<MethodType>, method, _1, _2, _3);
|
||||
}
|
||||
|
||||
template < typename MethodType >
|
||||
family_id make_instance_type() noexcept {
|
||||
using mt = detail::method_traits<MethodType>;
|
||||
using instance_type = typename mt::instance_type;
|
||||
return get_family_id<instance_type>();
|
||||
}
|
||||
|
||||
template < typename MethodType >
|
||||
std::optional<family_id> make_return_type() {
|
||||
using ft = detail::method_traits<MethodType>;
|
||||
using return_type = typename ft::return_type;
|
||||
using mt = detail::method_traits<MethodType>;
|
||||
using return_type = typename mt::return_type;
|
||||
|
||||
if constexpr ( !std::is_void_v<return_type> ) {
|
||||
return get_family_id<return_type>();
|
||||
@@ -146,15 +153,15 @@ namespace meta_hpp::method_detail
|
||||
|
||||
template < typename MethodType, std::size_t... Is >
|
||||
std::vector<family_id> make_argument_types_impl(std::index_sequence<Is...>) {
|
||||
using ft = detail::method_traits<MethodType>;
|
||||
using argument_types = typename ft::argument_types;
|
||||
using mt = detail::method_traits<MethodType>;
|
||||
using argument_types = typename mt::argument_types;
|
||||
return { get_family_id<std::tuple_element_t<Is, argument_types>>()... };
|
||||
}
|
||||
|
||||
template < typename MethodType >
|
||||
std::vector<family_id> make_argument_types() {
|
||||
using ft = detail::method_traits<MethodType>;
|
||||
return make_argument_types_impl<MethodType>(std::make_index_sequence<ft::arity>());
|
||||
using mt = detail::method_traits<MethodType>;
|
||||
return make_argument_types_impl<MethodType>(std::make_index_sequence<mt::arity>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,6 +185,10 @@ namespace meta_hpp
|
||||
return argument_types_.size();
|
||||
}
|
||||
|
||||
family_id instance_type() const noexcept {
|
||||
return instance_type_;
|
||||
}
|
||||
|
||||
std::optional<family_id> return_type() const noexcept {
|
||||
return return_type_;
|
||||
}
|
||||
@@ -238,12 +249,14 @@ namespace meta_hpp
|
||||
template < typename MethodType >
|
||||
method_info(std::string id, MethodType method_ptr)
|
||||
: id_{std::move(id)}
|
||||
, instance_type_{method_detail::make_instance_type<MethodType>()}
|
||||
, return_type_{method_detail::make_return_type<MethodType>()}
|
||||
, argument_types_{method_detail::make_argument_types<MethodType>()}
|
||||
, invoke_{method_detail::make_invoke(method_ptr)}
|
||||
, cinvoke_{method_detail::make_cinvoke(method_ptr)} {}
|
||||
private:
|
||||
std::string id_;
|
||||
family_id instance_type_;
|
||||
std::optional<family_id> return_type_;
|
||||
std::vector<family_id> argument_types_;
|
||||
method_detail::method_invoke invoke_;
|
||||
|
||||
Reference in New Issue
Block a user