From ce7f7d0bebc7b40ac4b98869d275e65305b4bcfd Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Fri, 2 Jul 2021 07:21:58 +0700 Subject: [PATCH] less work in registry classes --- headers/meta.hpp/meta_class.hpp | 6 +--- headers/meta.hpp/meta_class_info.hpp | 5 +-- headers/meta.hpp/meta_data.hpp | 6 +--- headers/meta.hpp/meta_field.hpp | 9 +----- headers/meta.hpp/meta_field_info.hpp | 9 ++++-- headers/meta.hpp/meta_function.hpp | 8 +---- headers/meta.hpp/meta_function_info.hpp | 8 +++-- headers/meta.hpp/meta_fwd.hpp | 41 ++++++++++--------------- headers/meta.hpp/meta_method.hpp | 9 +----- headers/meta.hpp/meta_method_info.hpp | 10 ++++-- headers/meta.hpp/meta_namespace.hpp | 6 +--- headers/meta.hpp/meta_type.hpp | 2 +- headers/meta.hpp/meta_variable.hpp | 9 +----- headers/meta.hpp/meta_variable_info.hpp | 10 ++++-- 14 files changed, 53 insertions(+), 85 deletions(-) diff --git a/headers/meta.hpp/meta_class.hpp b/headers/meta.hpp/meta_class.hpp index 0e2c4f6..31a510a 100644 --- a/headers/meta.hpp/meta_class.hpp +++ b/headers/meta.hpp/meta_class.hpp @@ -22,11 +22,7 @@ namespace meta_hpp class class_ { public: explicit class_(std::string id) - : info_{get_family_id(), std::move(id)} {} - - const class_info& info() const noexcept { - return info_; - } + : info_{detail::typename_arg, std::move(id)} {} operator const class_info&() const noexcept { return info_; diff --git a/headers/meta.hpp/meta_class_info.hpp b/headers/meta.hpp/meta_class_info.hpp index 20ddc2b..706fcce 100644 --- a/headers/meta.hpp/meta_class_info.hpp +++ b/headers/meta.hpp/meta_class_info.hpp @@ -116,8 +116,9 @@ namespace meta_hpp template < typename Class > friend class class_; - class_info(family_id fid, std::string id) - : fid_{std::move(fid)} + template < typename Class > + class_info(detail::typename_arg_t, std::string id) + : fid_{get_family_id()} , id_{std::move(id)} {} private: family_id fid_; diff --git a/headers/meta.hpp/meta_data.hpp b/headers/meta.hpp/meta_data.hpp index 5dbebec..f68a9b3 100644 --- a/headers/meta.hpp/meta_data.hpp +++ b/headers/meta.hpp/meta_data.hpp @@ -15,11 +15,7 @@ namespace meta_hpp class data_ { public: explicit data_(std::string id, value value) - : info_(std::move(id), std::move(value)) {} - - const data_info& info() const noexcept { - return info_; - } + : info_{std::move(id), std::move(value)} {} operator const data_info&() const noexcept { return info_; diff --git a/headers/meta.hpp/meta_field.hpp b/headers/meta.hpp/meta_field.hpp index 61aab5d..de7f1bc 100644 --- a/headers/meta.hpp/meta_field.hpp +++ b/headers/meta.hpp/meta_field.hpp @@ -20,14 +20,7 @@ namespace meta_hpp static_assert(std::is_member_object_pointer_v); explicit field_(std::string id) - : info_{get_family_id(), std::move(id)} { - info_.getter_ = &field_detail::getter; - info_.setter_ = &field_detail::setter; - } - - const field_info& info() const noexcept { - return info_; - } + : info_{detail::auto_arg, std::move(id)} {} operator const field_info&() const noexcept { return info_; diff --git a/headers/meta.hpp/meta_field_info.hpp b/headers/meta.hpp/meta_field_info.hpp index ad3e386..2690461 100644 --- a/headers/meta.hpp/meta_field_info.hpp +++ b/headers/meta.hpp/meta_field_info.hpp @@ -105,9 +105,12 @@ namespace meta_hpp template < auto Field > friend class field_; - field_info(family_id fid, std::string id) - : fid_{std::move(fid)} - , id_{std::move(id)} {} + template < typename FieldType, FieldType Field > + field_info(detail::auto_arg_t, std::string id) + : fid_{get_family_id()} + , id_{std::move(id)} + , getter_{&field_detail::getter} + , setter_{&field_detail::setter} {} private: family_id fid_; std::string id_; diff --git a/headers/meta.hpp/meta_function.hpp b/headers/meta.hpp/meta_function.hpp index be7ccea..5dc110a 100644 --- a/headers/meta.hpp/meta_function.hpp +++ b/headers/meta.hpp/meta_function.hpp @@ -20,13 +20,7 @@ namespace meta_hpp static_assert(std::is_function_v>); explicit function_(std::string id) - : info_{get_family_id(), std::move(id)} { - info_.invoke_ = &function_detail::invoke; - } - - const function_info& info() const noexcept { - return info_; - } + : info_{detail::auto_arg, std::move(id)} {} operator const function_info&() const noexcept { return info_; diff --git a/headers/meta.hpp/meta_function_info.hpp b/headers/meta.hpp/meta_function_info.hpp index 22ec424..6d8d355 100644 --- a/headers/meta.hpp/meta_function_info.hpp +++ b/headers/meta.hpp/meta_function_info.hpp @@ -110,9 +110,11 @@ namespace meta_hpp template < auto Function > friend class function_; - function_info(family_id fid, std::string id) - : fid_{std::move(fid)} - , id_{std::move(id)} {} + template < typename FunctionType, FunctionType Function > + function_info(detail::auto_arg_t, std::string id) + : fid_{get_family_id()} + , id_{std::move(id)} + , invoke_{&function_detail::invoke} {} private: family_id fid_; std::string id_; diff --git a/headers/meta.hpp/meta_fwd.hpp b/headers/meta.hpp/meta_fwd.hpp index f736c5a..f5b4bbd 100644 --- a/headers/meta.hpp/meta_fwd.hpp +++ b/headers/meta.hpp/meta_fwd.hpp @@ -22,30 +22,6 @@ #include #include -namespace meta_hpp -{ - class value; - - class registry; - class type; - - class class_info; - class data_info; - class field_info; - class function_info; - class method_info; - class namespace_info; - class variable_info; - - template < typename Class > class class_; - class data_; - template < auto Field > class field_; - template < auto Function > class function_; - template < auto Method > class method_; - class namespace_; - template < auto Variable > class variable_; -} - namespace meta_hpp { struct family_id { @@ -119,6 +95,23 @@ namespace meta_hpp } } +namespace meta_hpp::detail +{ + template < auto Arg > + struct auto_arg_t { + }; + + template < typename Arg > + struct typename_arg_t { + }; + + template < auto Arg > + inline auto_arg_t auto_arg; + + template < typename Arg > + inline typename_arg_t typename_arg; +} + namespace meta_hpp::detail { template < typename K, typename V, typename C, typename K2 > diff --git a/headers/meta.hpp/meta_method.hpp b/headers/meta.hpp/meta_method.hpp index a509ab9..a179cdf 100644 --- a/headers/meta.hpp/meta_method.hpp +++ b/headers/meta.hpp/meta_method.hpp @@ -20,14 +20,7 @@ namespace meta_hpp static_assert(std::is_member_function_pointer_v); explicit method_(std::string id) - : info_{get_family_id(), std::move(id)} { - info_.invoke_ = &method_detail::invoke; - info_.cinvoke_ = &method_detail::cinvoke; - } - - const method_info& info() const noexcept { - return info_; - } + : info_{detail::auto_arg, std::move(id)} {} operator const method_info&() const { return info_; diff --git a/headers/meta.hpp/meta_method_info.hpp b/headers/meta.hpp/meta_method_info.hpp index 3198225..4fcd699 100644 --- a/headers/meta.hpp/meta_method_info.hpp +++ b/headers/meta.hpp/meta_method_info.hpp @@ -139,6 +139,7 @@ namespace meta_hpp const std::string& id() const noexcept { return id_; } + template < typename... Args > value invoke(void* instance, Args&&... args) const { std::array vargs{{std::forward(args)...}}; @@ -172,9 +173,12 @@ namespace meta_hpp template < auto Method > friend class method_; - method_info(family_id fid, std::string id) - : fid_{std::move(fid)} - , id_{std::move(id)} {} + template < typename MethodType, MethodType Method > + method_info(detail::auto_arg_t, std::string id) + : fid_{get_family_id()} + , id_{std::move(id)} + , invoke_{&method_detail::invoke} + , cinvoke_{&method_detail::cinvoke} {} private: family_id fid_; std::string id_; diff --git a/headers/meta.hpp/meta_namespace.hpp b/headers/meta.hpp/meta_namespace.hpp index 5ea6740..9a05806 100644 --- a/headers/meta.hpp/meta_namespace.hpp +++ b/headers/meta.hpp/meta_namespace.hpp @@ -20,11 +20,7 @@ namespace meta_hpp class namespace_ { public: explicit namespace_(std::string id) - : info_(std::move(id)) {} - - const namespace_info& info() const noexcept { - return info_; - } + : info_{std::move(id)} {} operator const namespace_info&() const noexcept { return info_; diff --git a/headers/meta.hpp/meta_type.hpp b/headers/meta.hpp/meta_type.hpp index 8f86765..c2a5ab1 100644 --- a/headers/meta.hpp/meta_type.hpp +++ b/headers/meta.hpp/meta_type.hpp @@ -29,7 +29,7 @@ namespace meta_hpp template < typename Info > type(Info&& info) - : info_(std::forward(info)) {} + : info_{std::forward(info)} {} bool is_class() const noexcept { return std::holds_alternative(info_); } bool is_field() const noexcept { return std::holds_alternative(info_); } diff --git a/headers/meta.hpp/meta_variable.hpp b/headers/meta.hpp/meta_variable.hpp index ce133ea..eabd19f 100644 --- a/headers/meta.hpp/meta_variable.hpp +++ b/headers/meta.hpp/meta_variable.hpp @@ -18,14 +18,7 @@ namespace meta_hpp class variable_ { public: explicit variable_(std::string id) - : info_{get_family_id(), std::move(id)} { - info_.getter_ = &variable_detail::getter; - info_.setter_ = &variable_detail::setter; - } - - const variable_info& info() const noexcept { - return info_; - } + : info_{detail::auto_arg, std::move(id)} {} operator const variable_info&() const noexcept { return info_; diff --git a/headers/meta.hpp/meta_variable_info.hpp b/headers/meta.hpp/meta_variable_info.hpp index 0438779..c407b3f 100644 --- a/headers/meta.hpp/meta_variable_info.hpp +++ b/headers/meta.hpp/meta_variable_info.hpp @@ -70,6 +70,7 @@ namespace meta_hpp const std::string& id() const noexcept { return id_; } + value get() const { return getter_(); } @@ -100,9 +101,12 @@ namespace meta_hpp template < auto Variable > friend class variable_; - variable_info(family_id fid, std::string id) - : fid_{std::move(fid)} - , id_{std::move(id)} {} + template < typename VariableType, VariableType Variable > + variable_info(detail::auto_arg_t, std::string id) + : fid_{get_family_id()} + , id_{std::move(id)} + , getter_{&variable_detail::getter} + , setter_{&variable_detail::setter} {} private: family_id fid_; std::string id_;