From 0e3bdc02ea4fa5edd4431e27074a41c277cbc1da Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Mon, 14 Oct 2019 14:26:01 +0200 Subject: [PATCH] meta: meta_factory::type supports named types (the identifier isn't required in this case) --- TODO | 2 +- src/entt/meta/factory.hpp | 34 +++++++++++++++++++++++++++------- test/lib/a_module.cpp | 2 +- test/lib/another_module.cpp | 2 +- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 92ea15e60..48ca05d55 100644 --- a/TODO +++ b/TODO @@ -32,10 +32,10 @@ * add examples (and credits) from @alanjfs :) * explore the possibility to wrap other backend with a XHandler component * use [[nodiscard]] consistently for safety purposes +* static reflection, hint: template<> meta_type_t: meta_descriptor * make meta work across boundaries - extend and make factory::prop more flexible - entt::reflect().type("foo"_hs, entt::as_property); or similar - - name-less reflect/type (for named types) - a better context - tests, doc diff --git a/src/entt/meta/factory.hpp b/src/entt/meta/factory.hpp index 199a3d297..6b46a88b6 100644 --- a/src/entt/meta/factory.hpp +++ b/src/entt/meta/factory.hpp @@ -262,13 +262,7 @@ class meta_factory { return node && (node->identifier == identifier || duplicate(identifier, node->next)); } -public: - /** - * @brief Extends a meta type by assigning it an identifier. - * @param identifier Unique identifier. - * @return An extended meta factory for the parent type. - */ - auto type(const ENTT_ID_TYPE identifier) ENTT_NOEXCEPT { + auto record(const ENTT_ID_TYPE identifier) ENTT_NOEXCEPT { auto * const node = internal::meta_info::resolve(); ENTT_ASSERT(!duplicate(identifier, *internal::meta_info<>::ctx)); @@ -280,6 +274,32 @@ public: return extended_meta_factory{&node->prop}; } +public: + /** + * @brief Extends a meta type by assigning it an identifier. + * + * This function is intended only for unnamed types. + * + * @param identifier Unique identifier. + * @return An extended meta factory for the parent type. + */ + auto type(const ENTT_ID_TYPE identifier) ENTT_NOEXCEPT { + static_assert(!is_named_type_v); + return record(identifier); + } + + /** + * @brief Extends a meta type by assigning it an identifier. + * + * This function is intended only for named types + * + * @return An extended meta factory for the parent type. + */ + auto type() ENTT_NOEXCEPT { + static_assert(is_named_type_v); + return record(named_type_traits_t::value); + } + /** * @brief Assigns a meta base to a meta type. * diff --git a/test/lib/a_module.cpp b/test/lib/a_module.cpp index f5e2e6d65..9b80573b7 100644 --- a/test/lib/a_module.cpp +++ b/test/lib/a_module.cpp @@ -52,7 +52,7 @@ LIB_EXPORT void a_module_meta_ctx(entt::meta_ctx context) { } LIB_EXPORT void a_module_meta_init() { - entt::meta().type("char"_hs).data<'c'>("c"_hs); + entt::meta().type().data<'c'>("c"_hs); } LIB_EXPORT void a_module_meta_deinit() { diff --git a/test/lib/another_module.cpp b/test/lib/another_module.cpp index 4b781fcdb..71fd25136 100644 --- a/test/lib/another_module.cpp +++ b/test/lib/another_module.cpp @@ -57,7 +57,7 @@ LIB_EXPORT void another_module_meta_ctx(entt::meta_ctx context) { } LIB_EXPORT void another_module_meta_init() { - entt::meta().type("int"_hs).data<0>("0"_hs); + entt::meta().type().data<0>("0"_hs); } LIB_EXPORT void another_module_meta_deinit() {