skypjack 2 недель назад
Родитель
Сommit
314eec83e9

+ 0 - 1
TODO

@@ -41,7 +41,6 @@ TODO:
 * fast lookup on meta reset
 * fast lookup on meta reset
 * check for duplicates in basic_meta_factory constructor (with tests)
 * check for duplicates in basic_meta_factory constructor (with tests)
 * test (and fix) resolve where the type id conflicts with the type hash
 * test (and fix) resolve where the type id conflicts with the type hash
-* rename meta-type::id -> ::alias
 * assert and test type mismatch on meta factory construction and type(...) - ie id vs alias on overloaded and standard
 * assert and test type mismatch on meta factory construction and type(...) - ie id vs alias on overloaded and standard
 * use meta_any::type(value) with from_void and the like to avoid lookups in some cases
 * use meta_any::type(value) with from_void and the like to avoid lookups in some cases
 * try to fully support uint16_t for entity types
 * try to fully support uint16_t for entity types

+ 8 - 8
src/entt/meta/factory.hpp

@@ -54,9 +54,9 @@ class basic_meta_factory {
 protected:
 protected:
     void type(const id_type alias, const char *name) noexcept {
     void type(const id_type alias, const char *name) noexcept {
         state = mode::type;
         state = mode::type;
-        ENTT_ASSERT((parent->id == alias) || stl::find_if(ctx->bucket.cbegin(), ctx->bucket.cend(), [alias](const auto &value) { return value.second->id == alias; }) == ctx->bucket.cend(), "Duplicate identifier");
+        ENTT_ASSERT((parent->alias == alias) || stl::find_if(ctx->bucket.cbegin(), ctx->bucket.cend(), [alias](const auto &value) { return value.second->alias == alias; }) == ctx->bucket.cend(), "Duplicate identifier");
+        parent->alias = alias;
         parent->name = name;
         parent->name = name;
-        parent->id = alias;
     }
     }
 
 
     template<typename Type>
     template<typename Type>
@@ -561,14 +561,14 @@ public:
  *
  *
  * The type is also removed from the set of searchable types.
  * The type is also removed from the set of searchable types.
  *
  *
- * @param id Unique identifier.
+ * @param alias Unique identifier.
  * @param ctx The context from which to reset meta types.
  * @param ctx The context from which to reset meta types.
  */
  */
-inline void meta_reset(meta_ctx &ctx, const id_type id) noexcept {
+inline void meta_reset(meta_ctx &ctx, const id_type alias) noexcept {
     auto &context = internal::meta_context::from(ctx);
     auto &context = internal::meta_context::from(ctx);
 
 
     for(auto it = context.bucket.begin(); it != context.bucket.end();) {
     for(auto it = context.bucket.begin(); it != context.bucket.end();) {
-        if(it->second->id == id) {
+        if(it->second->alias == alias) {
             it = context.bucket.erase(it);
             it = context.bucket.erase(it);
         } else {
         } else {
             ++it;
             ++it;
@@ -585,10 +585,10 @@ inline void meta_reset(meta_ctx &ctx, const id_type id) noexcept {
  *
  *
  * The type is also removed from the set of searchable types.
  * The type is also removed from the set of searchable types.
  *
  *
- * @param id Unique identifier.
+ * @param alias Unique identifier.
  */
  */
-inline void meta_reset(const id_type id) noexcept {
-    meta_reset(locator<meta_ctx>::value_or(), id);
+inline void meta_reset(const id_type alias) noexcept {
+    meta_reset(locator<meta_ctx>::value_or(), alias);
 }
 }
 
 
 /**
 /**

+ 5 - 5
src/entt/meta/meta.hpp

@@ -1098,11 +1098,11 @@ public:
     }
     }
 
 
     /**
     /**
-     * @brief Returns the identifier assigned to a type.
-     * @return The identifier assigned to the type.
+     * @brief Returns the alias assigned to a type.
+     * @return The alias assigned to the type.
      */
      */
-    [[nodiscard]] id_type id() const noexcept {
-        return fetch_node().id;
+    [[nodiscard]] id_type alias() const noexcept {
+        return fetch_node().alias;
     }
     }
 
 
     /**
     /**
@@ -1466,7 +1466,7 @@ public:
 
 
     /*! @copydoc meta_data::operator== */
     /*! @copydoc meta_data::operator== */
     [[nodiscard]] bool operator==(const meta_type &other) const noexcept {
     [[nodiscard]] bool operator==(const meta_type &other) const noexcept {
-        return (ctx == other.ctx) && (fetch_node().id == other.fetch_node().id);
+        return (ctx == other.ctx) && (fetch_node().alias == other.fetch_node().alias);
     }
     }
 
 
 private:
 private:

+ 1 - 1
src/entt/meta/node.hpp

@@ -134,7 +134,7 @@ struct meta_type_node {
     using size_type = stl::size_t;
     using size_type = stl::size_t;
 
 
     const type_info *info{};
     const type_info *info{};
-    id_type id{};
+    id_type alias{};
     const char *name{};
     const char *name{};
     meta_traits traits{meta_traits::is_none};
     meta_traits traits{meta_traits::is_none};
     size_type size_of{0u};
     size_type size_of{0u};

+ 7 - 7
src/entt/meta/resolve.hpp

@@ -54,19 +54,19 @@ template<typename Type>
 /**
 /**
  * @brief Returns the meta type associated with a given identifier, if any.
  * @brief Returns the meta type associated with a given identifier, if any.
  * @param ctx The context from which to search for meta types.
  * @param ctx The context from which to search for meta types.
- * @param id Unique identifier.
+ * @param alias Unique identifier.
  * @return The meta type associated with the given identifier, if any.
  * @return The meta type associated with the given identifier, if any.
  */
  */
-[[nodiscard]] inline meta_type resolve(const meta_ctx &ctx, const id_type id) noexcept {
+[[nodiscard]] inline meta_type resolve(const meta_ctx &ctx, const id_type alias) noexcept {
     const auto &context = internal::meta_context::from(ctx);
     const auto &context = internal::meta_context::from(ctx);
 
 
     // fast lookup for unsearchable and overloaded types
     // fast lookup for unsearchable and overloaded types
-    if(const auto it = context.bucket.find(id); it != context.bucket.end()) {
+    if(const auto it = context.bucket.find(alias); it != context.bucket.end()) {
         return meta_type{ctx, *it->second};
         return meta_type{ctx, *it->second};
     }
     }
 
 
     for(auto &&curr: context.bucket) {
     for(auto &&curr: context.bucket) {
-        if(curr.second->id == id) {
+        if(curr.second->alias == alias) {
             return meta_type{ctx, *curr.second};
             return meta_type{ctx, *curr.second};
         }
         }
     }
     }
@@ -76,11 +76,11 @@ template<typename Type>
 
 
 /**
 /**
  * @brief Returns the meta type associated with a given identifier, if any.
  * @brief Returns the meta type associated with a given identifier, if any.
- * @param id Unique identifier.
+ * @param alias Unique identifier.
  * @return The meta type associated with the given identifier, if any.
  * @return The meta type associated with the given identifier, if any.
  */
  */
-[[nodiscard]] inline meta_type resolve(const id_type id) noexcept {
-    return resolve(locator<meta_ctx>::value_or(), id);
+[[nodiscard]] inline meta_type resolve(const id_type alias) noexcept {
+    return resolve(locator<meta_ctx>::value_or(), alias);
 }
 }
 
 
 /**
 /**

+ 4 - 4
test/entt/meta/meta_context.cpp

@@ -205,8 +205,8 @@ TEST_F(MetaContext, MetaType) {
     ASSERT_EQ(global, entt::resolve("foo"_hs));
     ASSERT_EQ(global, entt::resolve("foo"_hs));
     ASSERT_EQ(local, entt::resolve(ctx(), "bar"_hs));
     ASSERT_EQ(local, entt::resolve(ctx(), "bar"_hs));
 
 
-    ASSERT_EQ(global.id(), "foo"_hs);
-    ASSERT_EQ(local.id(), "bar"_hs);
+    ASSERT_EQ(global.alias(), "foo"_hs);
+    ASSERT_EQ(local.alias(), "bar"_hs);
 
 
     clazz instance{'c', 8};
     clazz instance{'c', 8};
     const argument value{2};
     const argument value{2};
@@ -234,8 +234,8 @@ TEST_F(MetaContext, MetaOverloadedType) {
 
 
     ASSERT_NE(global, local);
     ASSERT_NE(global, local);
 
 
-    ASSERT_EQ(global.id(), "global"_hs);
-    ASSERT_EQ(local.id(), "local"_hs);
+    ASSERT_EQ(global.alias(), "global"_hs);
+    ASSERT_EQ(local.alias(), "local"_hs);
 
 
     clazz instance{'c', 8};
     clazz instance{'c', 8};
     const argument value{2};
     const argument value{2};

+ 2 - 2
test/entt/meta/meta_factory.cpp

@@ -114,13 +114,13 @@ TEST_F(MetaFactory, Type) {
     factory.type("foo"_hs);
     factory.type("foo"_hs);
 
 
     ASSERT_NE(entt::resolve("foo"_hs), entt::meta_type{});
     ASSERT_NE(entt::resolve("foo"_hs), entt::meta_type{});
-    ASSERT_EQ(entt::resolve<int>().id(), "foo"_hs);
+    ASSERT_EQ(entt::resolve<int>().alias(), "foo"_hs);
 
 
     factory.type("bar"_hs);
     factory.type("bar"_hs);
 
 
     ASSERT_EQ(entt::resolve("foo"_hs), entt::meta_type{});
     ASSERT_EQ(entt::resolve("foo"_hs), entt::meta_type{});
     ASSERT_NE(entt::resolve("bar"_hs), entt::meta_type{});
     ASSERT_NE(entt::resolve("bar"_hs), entt::meta_type{});
-    ASSERT_EQ(entt::resolve<int>().id(), "bar"_hs);
+    ASSERT_EQ(entt::resolve<int>().alias(), "bar"_hs);
 }
 }
 
 
 TEST_F(MetaFactory, OverloadedType) {
 TEST_F(MetaFactory, OverloadedType) {

+ 6 - 6
test/entt/meta/meta_type.cpp

@@ -201,7 +201,7 @@ TEST_F(MetaType, Resolve) {
     ASSERT_FALSE(entt::resolve(entt::type_id<void>()));
     ASSERT_FALSE(entt::resolve(entt::type_id<void>()));
 
 
     auto range = entt::resolve();
     auto range = entt::resolve();
-    const auto it = std::find_if(range.begin(), range.end(), [](auto curr) { return curr.second.id() == "class"_hs; });
+    const auto it = std::find_if(range.begin(), range.end(), [](auto curr) { return curr.second.alias() == "class"_hs; });
 
 
     ASSERT_NE(it, range.end());
     ASSERT_NE(it, range.end());
     ASSERT_EQ(it->second, entt::resolve<clazz>());
     ASSERT_EQ(it->second, entt::resolve<clazz>());
@@ -224,7 +224,7 @@ TEST_F(MetaType, SafeWhenEmpty) {
     ASSERT_FALSE(type);
     ASSERT_FALSE(type);
     ASSERT_EQ(type, entt::meta_type{});
     ASSERT_EQ(type, entt::meta_type{});
     ASSERT_EQ(type.info(), entt::type_id<void>());
     ASSERT_EQ(type.info(), entt::type_id<void>());
-    ASSERT_EQ(type.id(), entt::type_id<void>().hash());
+    ASSERT_EQ(type.alias(), entt::type_id<void>().hash());
     ASSERT_EQ(type.size_of(), 0u);
     ASSERT_EQ(type.size_of(), 0u);
     ASSERT_FALSE(type.is_arithmetic());
     ASSERT_FALSE(type.is_arithmetic());
     ASSERT_FALSE(type.is_integral());
     ASSERT_FALSE(type.is_integral());
@@ -307,7 +307,7 @@ TEST_F(MetaType, IdAndInfo) {
 
 
     ASSERT_TRUE(type);
     ASSERT_TRUE(type);
     ASSERT_NE(type, entt::meta_type{});
     ASSERT_NE(type, entt::meta_type{});
-    ASSERT_EQ(type.id(), "class"_hs);
+    ASSERT_EQ(type.alias(), "class"_hs);
     ASSERT_EQ(type.info(), entt::type_id<clazz>());
     ASSERT_EQ(type.info(), entt::type_id<clazz>());
 }
 }
 
 
@@ -783,7 +783,7 @@ TEST_F(MetaType, Reset) {
     using namespace entt::literals;
     using namespace entt::literals;
 
 
     ASSERT_TRUE(entt::resolve("class"_hs));
     ASSERT_TRUE(entt::resolve("class"_hs));
-    ASSERT_EQ(entt::resolve<clazz>().id(), "class"_hs);
+    ASSERT_EQ(entt::resolve<clazz>().alias(), "class"_hs);
     ASSERT_TRUE(entt::resolve<clazz>().data("value"_hs));
     ASSERT_TRUE(entt::resolve<clazz>().data("value"_hs));
     ASSERT_TRUE((entt::resolve<clazz>().construct(derived{}, clazz{})));
     ASSERT_TRUE((entt::resolve<clazz>().construct(derived{}, clazz{})));
     // implicitly generated default constructor
     // implicitly generated default constructor
@@ -792,7 +792,7 @@ TEST_F(MetaType, Reset) {
     entt::meta_reset("class"_hs);
     entt::meta_reset("class"_hs);
 
 
     ASSERT_FALSE(entt::resolve("class"_hs));
     ASSERT_FALSE(entt::resolve("class"_hs));
-    ASSERT_NE(entt::resolve<clazz>().id(), "class"_hs);
+    ASSERT_NE(entt::resolve<clazz>().alias(), "class"_hs);
     ASSERT_FALSE(entt::resolve<clazz>().data("value"_hs));
     ASSERT_FALSE(entt::resolve<clazz>().data("value"_hs));
     ASSERT_FALSE((entt::resolve<clazz>().construct(derived{}, clazz{})));
     ASSERT_FALSE((entt::resolve<clazz>().construct(derived{}, clazz{})));
     // implicitly generated default constructor is not cleared
     // implicitly generated default constructor is not cleared
@@ -804,7 +804,7 @@ TEST_F(MetaType, Reset) {
 }
 }
 
 
 TEST_F(MetaType, ResetLast) {
 TEST_F(MetaType, ResetLast) {
-    auto id = (entt::resolve().cend() - 1u)->second.id();
+    auto id = (entt::resolve().cend() - 1u)->second.alias();
 
 
     ASSERT_TRUE(entt::resolve(id));
     ASSERT_TRUE(entt::resolve(id));