Просмотр исходного кода

meta: meta_factory::type supports named types (the identifier isn't required in this case)

Michele Caini 6 лет назад
Родитель
Сommit
0e3bdc02ea
4 измененных файлов с 30 добавлено и 10 удалено
  1. 1 1
      TODO
  2. 27 7
      src/entt/meta/factory.hpp
  3. 1 1
      test/lib/a_module.cpp
  4. 1 1
      test/lib/another_module.cpp

+ 1 - 1
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<Type>: meta_descriptor<name, func..., props..., etc...>
 
 * make meta work across boundaries
   - extend and make factory::prop more flexible
   - entt::reflect<T>().type("foo"_hs, entt::as_property); or similar
-  - name-less reflect/type (for named types)
   - a better context
   - tests, doc

+ 27 - 7
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<Type>::resolve();
 
         ENTT_ASSERT(!duplicate(identifier, *internal::meta_info<>::ctx));
@@ -280,6 +274,32 @@ public:
         return extended_meta_factory<Type>{&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<Type>);
+        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<Type>);
+        return record(named_type_traits_t<Type>::value);
+    }
+
     /**
      * @brief Assigns a meta base to a meta type.
      *

+ 1 - 1
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<char>().type("char"_hs).data<'c'>("c"_hs);
+    entt::meta<char>().type().data<'c'>("c"_hs);
 }
 
 LIB_EXPORT void a_module_meta_deinit() {

+ 1 - 1
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<int>().type("int"_hs).data<0>("0"_hs);
+    entt::meta<int>().type().data<0>("0"_hs);
 }
 
 LIB_EXPORT void another_module_meta_deinit() {