From a0c3a82c76ab2e85a6bcb3f358c84d26399cb4e7 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 10 Oct 2019 23:28:13 +0200 Subject: [PATCH] meta: cleanup and renaming --- TODO | 4 +- src/entt/meta/factory.hpp | 52 ++++------------------- test/entt/meta/meta.cpp | 82 ++++++++++++++++++++++--------------- test/lib/a_module.cpp | 4 +- test/lib/another_module.cpp | 4 +- test/lib/lib.cpp | 4 +- 6 files changed, 64 insertions(+), 86 deletions(-) diff --git a/TODO b/TODO index c3f69d7a8..e9b2c8382 100644 --- a/TODO +++ b/TODO @@ -31,9 +31,11 @@ * range based registry::remove and some others? * add examples (and credits) from @alanjfs :) * explore the possibility to wrap other backend with a XHandler component +* use [[nodiscard]] consistently for safety purposes * make meta work across boundaries + - type(id, props...) -> type(id).properties(props...) with internal meta_prop_node ** as a sink + - entt::reflect().type("foo"_hs, entt::as_property); or similar - name-less reflect with properties - forbid reflecting two times the same type - - entt::reflect -> entt::meta - tests, doc diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index c1df59525..0c82f8df1 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -700,15 +700,14 @@ public: } /** - * @brief Unregisters a meta type and all its parts. + * @brief Resets a meta type and all its parts. * - * This function unregisters a meta type and all its data members, member + * This function resets a meta type and all its data members, member * functions and properties, as well as its constructors, destructors and * conversion functions if any.
- * Base classes aren't unregistered but the link between the two types is - * removed. + * Base classes aren't reset but the link between the two types is removed. */ - void unregister() ENTT_NOEXCEPT { + void reset() ENTT_NOEXCEPT { internal::meta_info::reset(); } }; @@ -719,55 +718,18 @@ public: * * This is the point from which everything starts.
* By invoking this function with a type that is not yet reflected, a meta type - * is created to which it will be possible to attach data and functions through - * a dedicated factory. - * - * @tparam Type Type to reflect. - * @tparam Property Types of properties to assign to the reflected type. - * @param identifier Unique identifier. - * @param property Properties to assign to the reflected type. - * @return A meta factory for the given type. - */ -template -inline meta_factory reflect(const ENTT_ID_TYPE identifier, Property &&... property) ENTT_NOEXCEPT { - return meta_factory{}.type(identifier, std::forward(property)...); -} - - -/** - * @brief Utility function to use for reflection. - * - * This is the point from which everything starts.
- * By invoking this function with a type that is not yet reflected, a meta type - * is created to which it will be possible to attach data and functions through - * a dedicated factory. + * is created to which it will be possible to attach meta objects through a + * dedicated factory. * * @tparam Type Type to reflect. * @return A meta factory for the given type. */ template -inline meta_factory reflect() ENTT_NOEXCEPT { +inline meta_factory meta() ENTT_NOEXCEPT { return meta_factory{}; } -/** - * @brief Utility function to unregister a type. - * - * This function unregisters a type and all its data members, member functions - * and properties, as well as its constructors, destructors and conversion - * functions if any.
- * Base classes aren't unregistered but the link between the two types is - * removed. - * - * @tparam Type Type to unregister. - */ -template -inline void unregister() ENTT_NOEXCEPT { - meta_factory{}.unregister(); -} - - /** * @brief Returns the meta type associated with a given type. * @tparam Type Type to use to search for a meta type. diff --git a/test/entt/meta/meta.cpp b/test/entt/meta/meta.cpp index acf8fd8ff..5f5bb5485 100644 --- a/test/entt/meta/meta.cpp +++ b/test/entt/meta/meta.cpp @@ -143,35 +143,41 @@ struct concrete_type: an_abstract_type, another_abstract_type { struct Meta: ::testing::Test { static void SetUpTestCase() { - entt::reflect().conv(); + entt::meta().conv(); - entt::reflect("char"_hs, std::make_pair(properties::prop_int, 42)) + entt::meta() + .type("char"_hs, std::make_pair(properties::prop_int, 42)) .data<&set, &get>("value"_hs); - entt::reflect() + entt::meta() .data("prop_bool"_hs) .data("prop_int"_hs) .data<&set, &get>("value"_hs); - entt::reflect().data<0u>("min"_hs).data<100u>("max"_hs); + entt::meta().data<0u>("min"_hs).data<100u>("max"_hs); - entt::reflect("base"_hs); + entt::meta() + .type("base"_hs); - entt::reflect("derived"_hs, std::make_pair(properties::prop_int, 99)) + entt::meta() + .type("derived"_hs, std::make_pair(properties::prop_int, 99)) .base() .ctor(std::make_pair(properties::prop_bool, false)) .ctor<&derived_factory>(std::make_pair(properties::prop_int, 42)) .conv<&derived_type::f>() .conv<&derived_type::g>(); - entt::reflect("empty"_hs) + entt::meta() + .type("empty"_hs) .dtor<&empty_type::destroy>(); - entt::reflect("fat"_hs) + entt::meta() + .type("fat"_hs) .base() .dtor<&fat_type::destroy>(); - entt::reflect("data"_hs) + entt::meta() + .type("data"_hs) .data<&data_type::i, entt::as_alias_t>("i"_hs, std::make_pair(properties::prop_int, 0)) .data<&data_type::j>("j"_hs, std::make_pair(properties::prop_int, 1)) .data<&data_type::h>("h"_hs, std::make_pair(properties::prop_int, 2)) @@ -179,11 +185,13 @@ struct Meta: ::testing::Test { .data<&data_type::empty>("empty"_hs) .data<&data_type::v, entt::as_void_t>("v"_hs); - entt::reflect("array"_hs) + entt::meta() + .type("array"_hs) .data<&array_type::global>("global"_hs) .data<&array_type::local>("local"_hs); - entt::reflect("func"_hs) + entt::meta() + .type("func"_hs) .func(&func_type::f)>("f3"_hs) .func(&func_type::f)>("f2"_hs, std::make_pair(properties::prop_bool, false)) .func(&func_type::f)>("f1"_hs, std::make_pair(properties::prop_bool, false)) @@ -193,34 +201,40 @@ struct Meta: ::testing::Test { .func<&func_type::v, entt::as_void_t>("v"_hs) .func<&func_type::a, entt::as_alias_t>("a"_hs); - entt::reflect("setter_getter"_hs) + entt::meta() + .type("setter_getter"_hs) .data<&setter_getter_type::static_setter, &setter_getter_type::static_getter>("x"_hs) .data<&setter_getter_type::setter, &setter_getter_type::getter>("y"_hs) .data<&setter_getter_type::static_setter, &setter_getter_type::getter>("z"_hs) .data<&setter_getter_type::setter_with_ref, &setter_getter_type::getter_with_ref>("w"_hs); - entt::reflect("an_abstract_type"_hs, std::make_pair(properties::prop_bool, false)) + entt::meta() + .type("an_abstract_type"_hs, std::make_pair(properties::prop_bool, false)) .data<&an_abstract_type::i>("i"_hs) .func<&an_abstract_type::f>("f"_hs) .func<&an_abstract_type::g>("g"_hs); - entt::reflect("another_abstract_type"_hs, std::make_pair(properties::prop_int, 42)) + entt::meta() + .type("another_abstract_type"_hs, std::make_pair(properties::prop_int, 42)) .data<&another_abstract_type::j>("j"_hs) .func<&another_abstract_type::h>("h"_hs); - entt::reflect("concrete"_hs) + entt::meta() + .type("concrete"_hs) .base() .base() .func<&concrete_type::f>("f"_hs); } static void SetUpAfterUnregistration() { - entt::reflect().conv(); + entt::meta().conv(); - entt::reflect("my_type"_hs, std::make_pair(properties::prop_bool, false)) + entt::meta() + .type("my_type"_hs, std::make_pair(properties::prop_bool, false)) .ctor<>(); - entt::reflect("your_type"_hs) + entt::meta() + .type("your_type"_hs) .data<&another_abstract_type::j>("a_data_member"_hs) .func<&another_abstract_type::h>("a_member_function"_hs); } @@ -1968,25 +1982,25 @@ TEST_F(Meta, Variables) { ASSERT_EQ(c, 'x'); } -TEST_F(Meta, Unregister) { +TEST_F(Meta, Reset) { ASSERT_NE(*entt::internal::meta_info<>::ctx, nullptr); ASSERT_NE(entt::internal::meta_info<>::local, nullptr); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); - entt::unregister(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); + entt::meta().reset(); ASSERT_EQ(*entt::internal::meta_info<>::ctx, nullptr); ASSERT_EQ(entt::internal::meta_info<>::local, nullptr); diff --git a/test/lib/a_module.cpp b/test/lib/a_module.cpp index 1d7cffa54..f5e2e6d65 100644 --- a/test/lib/a_module.cpp +++ b/test/lib/a_module.cpp @@ -52,9 +52,9 @@ LIB_EXPORT void a_module_meta_ctx(entt::meta_ctx context) { } LIB_EXPORT void a_module_meta_init() { - entt::reflect("char"_hs).data<'c'>("c"_hs); + entt::meta().type("char"_hs).data<'c'>("c"_hs); } LIB_EXPORT void a_module_meta_deinit() { - entt::unregister(); + entt::meta().reset(); } diff --git a/test/lib/another_module.cpp b/test/lib/another_module.cpp index 2473f669f..4b781fcdb 100644 --- a/test/lib/another_module.cpp +++ b/test/lib/another_module.cpp @@ -57,9 +57,9 @@ LIB_EXPORT void another_module_meta_ctx(entt::meta_ctx context) { } LIB_EXPORT void another_module_meta_init() { - entt::reflect("int"_hs).data<0>("0"_hs); + entt::meta().type("int"_hs).data<0>("0"_hs); } LIB_EXPORT void another_module_meta_deinit() { - entt::unregister(); + entt::meta().reset(); } diff --git a/test/lib/lib.cpp b/test/lib/lib.cpp index 9fffcd4c7..359d0e899 100644 --- a/test/lib/lib.cpp +++ b/test/lib/lib.cpp @@ -118,7 +118,7 @@ TEST(Lib, Meta) { a_module_meta_ctx(entt::meta_ctx{}); another_module_meta_ctx(entt::meta_ctx{}); - entt::reflect("double"_hs).conv(); + entt::meta().type("double"_hs).conv(); another_module_meta_init(); a_module_meta_init(); @@ -130,7 +130,7 @@ TEST(Lib, Meta) { a_module_meta_deinit(); another_module_meta_deinit(); - entt::unregister(); + entt::meta().reset(); ASSERT_FALSE(entt::resolve("double"_hs)); ASSERT_FALSE(entt::resolve("char"_hs));