From d08fe88b85218cfb1b4245e99ac1e6de3b7c91bc Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Wed, 7 Jul 2021 00:19:30 +0700 Subject: [PATCH] remove all value family id --- headers/meta.hpp/meta_field_info.hpp | 11 +- headers/meta.hpp/meta_function_info.hpp | 10 +- headers/meta.hpp/meta_fwd.hpp | 15 -- headers/meta.hpp/meta_method_info.hpp | 10 +- headers/meta.hpp/meta_registry.hpp | 10 -- headers/meta.hpp/meta_variable_info.hpp | 10 +- untests/meta_family_tests.cpp | 47 ------- untests/meta_registry_tests.cpp | 174 +++--------------------- 8 files changed, 29 insertions(+), 258 deletions(-) diff --git a/headers/meta.hpp/meta_field_info.hpp b/headers/meta.hpp/meta_field_info.hpp index ce1c488..093f01c 100644 --- a/headers/meta.hpp/meta_field_info.hpp +++ b/headers/meta.hpp/meta_field_info.hpp @@ -66,13 +66,10 @@ namespace meta_hpp field_info& operator=(field_info&&) = default; field_info& operator=(const field_info&) = default; public: - const family_id& fid() const noexcept { - return fid_; - } - const std::string& id() const noexcept { return id_; } + value get(cinstance instance) const { return getter_(instance); } @@ -99,7 +96,7 @@ namespace meta_hpp } void merge(const field_info& other) { - if ( fid() != other.fid() ) { + if ( id() != other.id() ) { throw std::logic_error("field_info::merge failed"); } detail::merge_with(datas_, other.datas_, &data_info::merge); @@ -110,12 +107,10 @@ namespace meta_hpp template < typename FieldType, FieldType Field > field_info(detail::auto_arg_t, std::string id) - : fid_{get_value_family_id()} - , id_{std::move(id)} + : id_{std::move(id)} , getter_{&field_detail::getter} , setter_{&field_detail::setter} {} private: - family_id fid_; std::string id_; value(*getter_)(cinstance); void(*setter_)(instance, value); diff --git a/headers/meta.hpp/meta_function_info.hpp b/headers/meta.hpp/meta_function_info.hpp index b169858..4ad5c96 100644 --- a/headers/meta.hpp/meta_function_info.hpp +++ b/headers/meta.hpp/meta_function_info.hpp @@ -60,10 +60,6 @@ namespace meta_hpp function_info& operator=(function_info&&) = default; function_info& operator=(const function_info&) = default; public: - const family_id& fid() const noexcept { - return fid_; - } - const std::string& id() const noexcept { return id_; } @@ -95,7 +91,7 @@ namespace meta_hpp } void merge(const function_info& other) { - if ( fid() != other.fid() ) { + if ( id() != other.id() ) { throw std::logic_error("function_info::merge failed"); } detail::merge_with(datas_, other.datas_, &data_info::merge); @@ -106,11 +102,9 @@ namespace meta_hpp template < typename FunctionType, FunctionType Function > function_info(detail::auto_arg_t, std::string id) - : fid_{get_value_family_id()} - , id_{std::move(id)} + : id_{std::move(id)} , invoke_{&function_detail::invoke} {} private: - family_id fid_; std::string id_; std::optional(*invoke_)(value*, std::size_t); std::map> datas_; diff --git a/headers/meta.hpp/meta_fwd.hpp b/headers/meta.hpp/meta_fwd.hpp index 68513c1..607eefd 100644 --- a/headers/meta.hpp/meta_fwd.hpp +++ b/headers/meta.hpp/meta_fwd.hpp @@ -78,27 +78,12 @@ namespace meta_hpp return self_id; } }; - - template < typename T, T V > - class value_family final : public family_base<> { - public: - static family_id id() noexcept { - static family_id self_id{++last_id_}; - assert(self_id.id > 0u && "family_id overflow"); - return self_id; - } - }; } template < typename T > family_id get_type_family_id() noexcept { return family_id_detail::type_family::id(); } - - template < typename T, T V > - family_id get_value_family_id() noexcept { - return family_id_detail::value_family::id(); - } } namespace meta_hpp diff --git a/headers/meta.hpp/meta_method_info.hpp b/headers/meta.hpp/meta_method_info.hpp index f65ca29..efcf13f 100644 --- a/headers/meta.hpp/meta_method_info.hpp +++ b/headers/meta.hpp/meta_method_info.hpp @@ -110,10 +110,6 @@ namespace meta_hpp method_info& operator=(method_info&&) = default; method_info& operator=(const method_info&) = default; public: - const family_id& fid() const noexcept { - return fid_; - } - const std::string& id() const noexcept { return id_; } @@ -155,7 +151,7 @@ namespace meta_hpp } void merge(const method_info& other) { - if ( fid() != other.fid() ) { + if ( id() != other.id() ) { throw std::logic_error("method_info::merge failed"); } detail::merge_with(datas_, other.datas_, &data_info::merge); @@ -166,12 +162,10 @@ namespace meta_hpp template < typename MethodType, MethodType Method > method_info(detail::auto_arg_t, std::string id) - : fid_{get_value_family_id()} - , id_{std::move(id)} + : id_{std::move(id)} , invoke_{&method_detail::invoke} , cinvoke_{&method_detail::cinvoke} {} private: - family_id fid_; std::string id_; std::optional(*invoke_)(instance, value*, std::size_t); std::optional(*cinvoke_)(cinstance, value*, std::size_t); diff --git a/headers/meta.hpp/meta_registry.hpp b/headers/meta.hpp/meta_registry.hpp index 0c396c1..1975088 100644 --- a/headers/meta.hpp/meta_registry.hpp +++ b/headers/meta.hpp/meta_registry.hpp @@ -27,12 +27,6 @@ namespace meta_hpp return detail::find_opt(types_, fid); } - template < typename T, T V > - std::optional resolve() const { - const family_id fid = get_value_family_id(); - return detail::find_opt(types_, fid); - } - template < typename T > std::optional resolve(T&&) const { const family_id fid = get_type_family_id>(); @@ -149,7 +143,6 @@ namespace meta_hpp ? info.id() : prefix + "::" + info.id(); - detail::merge_with(types_, info.fid(), info, &type::merge); detail::merge_with(fields_, name, info, &field_info::merge); info.visit(overloaded { @@ -165,7 +158,6 @@ namespace meta_hpp ? info.id() : prefix + "::" + info.id(); - detail::merge_with(types_, info.fid(), info, &type::merge); detail::merge_with(functions_, name, info, &function_info::merge); info.visit(overloaded { @@ -181,7 +173,6 @@ namespace meta_hpp ? info.id() : prefix + "::" + info.id(); - detail::merge_with(types_, info.fid(), info, &type::merge); detail::merge_with(methods_, name, info, &method_info::merge); info.visit(overloaded { @@ -212,7 +203,6 @@ namespace meta_hpp ? info.id() : prefix + "::" + info.id(); - detail::merge_with(types_, info.fid(), info, &type::merge); detail::merge_with(variables_, name, info, &variable_info::merge); info.visit(overloaded { diff --git a/headers/meta.hpp/meta_variable_info.hpp b/headers/meta.hpp/meta_variable_info.hpp index a60a83b..9391b07 100644 --- a/headers/meta.hpp/meta_variable_info.hpp +++ b/headers/meta.hpp/meta_variable_info.hpp @@ -53,10 +53,6 @@ namespace meta_hpp variable_info& operator=(variable_info&&) = default; variable_info& operator=(const variable_info&) = default; public: - const family_id& fid() const noexcept { - return fid_; - } - const std::string& id() const noexcept { return id_; } @@ -87,7 +83,7 @@ namespace meta_hpp } void merge(const variable_info& other) { - if ( fid() != other.fid() ) { + if ( id() != other.id() ) { throw std::logic_error("variable_info::merge failed"); } detail::merge_with(datas_, other.datas_, &data_info::merge); @@ -98,12 +94,10 @@ namespace meta_hpp template < typename VariableType, VariableType Variable > variable_info(detail::auto_arg_t, std::string id) - : fid_{get_value_family_id()} - , id_{std::move(id)} + : id_{std::move(id)} , getter_{&variable_detail::getter} , setter_{&variable_detail::setter} {} private: - family_id fid_; std::string id_; value(*getter_)(); void(*setter_)(value); diff --git a/untests/meta_family_tests.cpp b/untests/meta_family_tests.cpp index ef38c47..48222d9 100644 --- a/untests/meta_family_tests.cpp +++ b/untests/meta_family_tests.cpp @@ -17,36 +17,13 @@ namespace struct ivec2 { int x{}; int y{}; - - static ivec2 zero; - - int dot(ivec2 other) const { - return x * other.x + y * other.y; - } }; struct ivec3 { int x{}; int y{}; int z{}; - - static ivec3 zero; - - int dot(ivec3 other) const { - return x * other.x + y * other.y + z * other.z; - } }; - - ivec2 ivec2::zero{}; - ivec3 ivec3::zero{}; - - ivec2 iadd2(ivec2 l, ivec2 r) { - return {l.x + r.x, l.y + r.y}; - } - - ivec3 iadd3(ivec3 l, ivec3 r) { - return {l.x + r.x, l.y + r.y, l.z + r.z}; - } } TEST_CASE("meta/family") { @@ -58,28 +35,4 @@ TEST_CASE("meta/family") { meta::class_info ivec3_info = meta::class_("ivec3"); CHECK_FALSE(ivec2_info.fid() == ivec3_info.fid()); } - - SUBCASE("field") { - meta::field_info x_info = meta::field_<&ivec2::x>("x"); - meta::field_info y_info = meta::field_<&ivec2::y>("y"); - CHECK_FALSE(x_info.fid() == y_info.fid()); - } - - SUBCASE("function") { - meta::function_info iadd2_info = meta::function_<&iadd2>("iadd2"); - meta::function_info iadd3_info = meta::function_<&iadd3>("iadd3"); - CHECK_FALSE(iadd2_info.fid() == iadd3_info.fid()); - } - - SUBCASE("method") { - meta::method_info dot2_info = meta::method_<&ivec2::dot>("dot"); - meta::method_info dot3_info = meta::method_<&ivec3::dot>("dot"); - CHECK_FALSE(dot2_info.fid() == dot3_info.fid()); - } - - SUBCASE("variable") { - meta::variable_info zero2_info = meta::variable_<&ivec2::zero>("zero"); - meta::variable_info zero3_info = meta::variable_<&ivec3::zero>("zero"); - CHECK_FALSE(zero2_info.fid() == zero3_info.fid()); - } } diff --git a/untests/meta_registry_tests.cpp b/untests/meta_registry_tests.cpp index 3694e82..548b1d1 100644 --- a/untests/meta_registry_tests.cpp +++ b/untests/meta_registry_tests.cpp @@ -89,69 +89,6 @@ TEST_CASE("meta/registry") { CHECK(ivec3_info.id() == "ivec3"); } - SUBCASE("field_template") { - REQUIRE(registry.resolve()); - REQUIRE(registry.resolve()); - - const meta::type ivec2_x_type = registry.resolve().value(); - const meta::type ivec2_y_type = registry.resolve().value(); - - REQUIRE(ivec2_x_type.is_field()); - REQUIRE(ivec2_y_type.is_field()); - - const meta::field_info ivec2_x_info = ivec2_x_type.get_field().value(); - const meta::field_info ivec2_y_info = ivec2_y_type.get_field().value(); - - CHECK(ivec2_x_info.id() == "x"); - CHECK(ivec2_y_info.id() == "y"); - } - - SUBCASE("field_instance") { - CHECK_FALSE(registry.resolve(&ivec2::x)); - } - - SUBCASE("function_template") { - REQUIRE(registry.resolve()); - - const meta::type iadd2_type = registry.resolve().value(); - REQUIRE(iadd2_type.is_function()); - - const meta::function_info iadd2_info = iadd2_type.get_function().value(); - CHECK(iadd2_info.id() == "iadd2"); - } - - SUBCASE("function_instance") { - CHECK_FALSE(registry.resolve(&iadd3)); - } - - SUBCASE("method_template") { - REQUIRE(registry.resolve()); - - const meta::type ivec2_dot_type = registry.resolve().value(); - REQUIRE(ivec2_dot_type.is_method()); - - const meta::method_info ivec2_dot_info = ivec2_dot_type.get_method().value(); - CHECK(ivec2_dot_info.id() == "dot"); - } - - SUBCASE("method_instance") { - CHECK_FALSE(registry.resolve(&ivec3::dot)); - } - - SUBCASE("variable_template") { - REQUIRE(registry.resolve()); - - const meta::type ivec2_zero_type = registry.resolve().value(); - REQUIRE(ivec2_zero_type.is_variable()); - - const meta::variable_info ivec2_x_info = ivec2_zero_type.get_variable().value(); - CHECK(ivec2_x_info.id() == "zero"); - } - - SUBCASE("variable_instance") { - CHECK_FALSE(registry.resolve(&ivec3::zero)); - } - SUBCASE("resolve/class") { ivec2 v2; ivec3 v3; @@ -190,110 +127,39 @@ TEST_CASE("meta/registry") { } SUBCASE("resolve/field") { - REQUIRE(registry.resolve()); - REQUIRE(registry.resolve()); - CHECK_FALSE(registry.resolve(&ivec2::x)); - CHECK_FALSE(registry.resolve(&ivec2::y)); + REQUIRE(registry.get_field_by_name("vmath::ivec2::x")); + REQUIRE(registry.get_field_by_name("vmath::ivec2::y")); + REQUIRE(registry.get_field_by_name("vmath::ivec3::x")); + REQUIRE(registry.get_field_by_name("vmath::ivec3::y")); - REQUIRE(registry.resolve()); - REQUIRE(registry.resolve()); - CHECK_FALSE(registry.resolve(&ivec3::x)); - CHECK_FALSE(registry.resolve(&ivec3::y)); - - const meta::field_info v2_x_info = meta::field_<&ivec2::x>("x"); - const meta::field_info v2_y_info = meta::field_<&ivec2::y>("y"); - CHECK(v2_x_info.fid() != v2_y_info.fid()); - - const meta::field_info v3_x_info = meta::field_<&ivec3::x>("x"); - const meta::field_info v3_y_info = meta::field_<&ivec3::y>("y"); - CHECK(v3_x_info.fid() != v3_y_info.fid()); - - CHECK(v2_x_info.fid() != v3_x_info.fid()); - CHECK(v2_y_info.fid() != v3_y_info.fid()); - - CHECK(v2_x_info.fid() == registry.resolve()->get_field()->fid()); - CHECK(v2_y_info.fid() == registry.resolve()->get_field()->fid()); - - CHECK(v3_x_info.fid() == registry.resolve()->get_field()->fid()); - CHECK(v3_y_info.fid() == registry.resolve()->get_field()->fid()); - - { - REQUIRE(registry.get_field_by_name("vmath::ivec2::x")); - REQUIRE(registry.get_field_by_name("vmath::ivec2::y")); - REQUIRE(registry.get_field_by_name("vmath::ivec3::x")); - REQUIRE(registry.get_field_by_name("vmath::ivec3::y")); - - CHECK(v2_x_info.fid() == registry.get_field_by_name("vmath::ivec2::x")->fid()); - CHECK(v2_y_info.fid() == registry.get_field_by_name("vmath::ivec2::y")->fid()); - CHECK(v3_x_info.fid() == registry.get_field_by_name("vmath::ivec3::x")->fid()); - CHECK(v3_y_info.fid() == registry.get_field_by_name("vmath::ivec3::y")->fid()); - } + CHECK("x" == registry.get_field_by_name("vmath::ivec2::x")->id()); + CHECK("y" == registry.get_field_by_name("vmath::ivec2::y")->id()); + CHECK("x" == registry.get_field_by_name("vmath::ivec3::x")->id()); + CHECK("y" == registry.get_field_by_name("vmath::ivec3::y")->id()); } SUBCASE("resolve/function") { - REQUIRE(registry.resolve()); - REQUIRE(registry.resolve()); - CHECK_FALSE(registry.resolve(&iadd2)); - CHECK_FALSE(registry.resolve(&iadd3)); + REQUIRE(registry.get_function_by_name("vmath::iadd2")); + REQUIRE(registry.get_function_by_name("vmath::iadd3")); - const meta::function_info iadd2_info = meta::function_<&iadd2>("iadd2"); - const meta::function_info iadd3_info = meta::function_<&iadd3>("iadd3"); - CHECK(iadd2_info.fid() != iadd3_info.fid()); - - CHECK(iadd2_info.fid() == registry.resolve()->get_function()->fid()); - CHECK(iadd3_info.fid() == registry.resolve()->get_function()->fid()); - - { - REQUIRE(registry.get_function_by_name("vmath::iadd2")); - REQUIRE(registry.get_function_by_name("vmath::iadd3")); - - CHECK(iadd2_info.fid() == registry.get_function_by_name("vmath::iadd2")->fid()); - CHECK(iadd3_info.fid() == registry.get_function_by_name("vmath::iadd3")->fid()); - } + CHECK("iadd2" == registry.get_function_by_name("vmath::iadd2")->id()); + CHECK("iadd3" == registry.get_function_by_name("vmath::iadd3")->id()); } SUBCASE("resolve/method") { - REQUIRE(registry.resolve()); - REQUIRE(registry.resolve()); - CHECK_FALSE(registry.resolve(&ivec2::dot)); - CHECK_FALSE(registry.resolve(&ivec3::dot)); + REQUIRE(registry.get_method_by_name("vmath::ivec2::dot")); + REQUIRE(registry.get_method_by_name("vmath::ivec3::dot")); - const meta::method_info v2_dot_info = meta::method_<&ivec2::dot>("dot"); - const meta::method_info v3_dot_info = meta::method_<&ivec3::dot>("dot"); - CHECK(v2_dot_info.fid() != v3_dot_info.fid()); - - CHECK(v2_dot_info.fid() == registry.resolve()->get_method()->fid()); - CHECK(v3_dot_info.fid() == registry.resolve()->get_method()->fid()); - - { - REQUIRE(registry.get_method_by_name("vmath::ivec2::dot")); - REQUIRE(registry.get_method_by_name("vmath::ivec3::dot")); - - CHECK(v2_dot_info.fid() == registry.get_method_by_name("vmath::ivec2::dot")->fid()); - CHECK(v3_dot_info.fid() == registry.get_method_by_name("vmath::ivec3::dot")->fid()); - } + CHECK("dot" == registry.get_method_by_name("vmath::ivec2::dot")->id()); + CHECK("dot" == registry.get_method_by_name("vmath::ivec3::dot")->id()); } SUBCASE("resolve/variable") { - REQUIRE(registry.resolve()); - REQUIRE(registry.resolve()); - CHECK_FALSE(registry.resolve(&ivec2::zero)); - CHECK_FALSE(registry.resolve(&ivec3::zero)); + REQUIRE(registry.get_variable_by_name("vmath::ivec2::zero")); + REQUIRE(registry.get_variable_by_name("vmath::ivec3::zero")); - const meta::variable_info v2_zero_info = meta::variable_<&ivec2::zero>("zero"); - const meta::variable_info v3_zero_info = meta::variable_<&ivec3::zero>("zero"); - CHECK(v2_zero_info.fid() != v3_zero_info.fid()); - - CHECK(v2_zero_info.fid() == registry.resolve()->get_variable()->fid()); - CHECK(v3_zero_info.fid() == registry.resolve()->get_variable()->fid()); - - { - REQUIRE(registry.get_variable_by_name("vmath::ivec2::zero")); - REQUIRE(registry.get_variable_by_name("vmath::ivec3::zero")); - - CHECK(v2_zero_info.fid() == registry.get_variable_by_name("vmath::ivec2::zero")->fid()); - CHECK(v3_zero_info.fid() == registry.get_variable_by_name("vmath::ivec3::zero")->fid()); - } + CHECK("zero" == registry.get_variable_by_name("vmath::ivec2::zero")->id()); + CHECK("zero" == registry.get_variable_by_name("vmath::ivec3::zero")->id()); } }