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

core: rename type_seq to type_index

Michele Caini 4 лет назад
Родитель
Сommit
92d43ce620

+ 14 - 14
docs/md/core.md

@@ -382,10 +382,10 @@ information to that provided by its counterpart.
 
 Basically, the whole system relies on a handful of classes. In particular:
 
-* An unique, sequential identifier associated with a given type:
+* The unique, sequential identifier associated with a given type:
 
   ```cpp
-  auto index = entt::type_seq<a_type>::value();
+  auto index = entt::type_index<a_type>::value();
   ```
 
   The returned value isn't guaranteed to be stable across different runs.
@@ -399,13 +399,13 @@ Basically, the whole system relies on a handful of classes. In particular:
   and therefore the generation of custom runtime sequences of indices for their
   own purposes, if necessary.
   
-  An external generator can also be used if needed. In fact, `type_seq` can be
+  An external generator can also be used if needed. In fact, `type_index` can be
   specialized by type and is also _sfinae-friendly_ in order to allow more
   refined specializations such as:
   
   ```cpp
   template<typename Type>
-  struct entt::type_seq<Type, std::void_d<decltype(Type::index())>> {
+  struct entt::type_index<Type, std::void_d<decltype(Type::index())>> {
       static entt::id_type value() ENTT_NOEXCEPT {
           return Type::index();
       }
@@ -416,7 +416,7 @@ Basically, the whole system relies on a handful of classes. In particular:
   The tool is widely used within `EnTT`. Generating indices not sequentially
   would break an assumption and would likely lead to undesired behaviors.
 
-* A hash value associated with a given type:
+* The hash value associated with a given type:
 
   ```cpp
   auto hash = entt::type_hash<a_type>::value();
@@ -434,11 +434,11 @@ Basically, the whole system relies on a handful of classes. In particular:
   that identifiers remain stable across executions. Moreover, they are generated
   at runtime and are no longer a compile-time thing.
 
-  As for `type_seq`, also `type_hash` is a _sfinae-friendly_ class that can be
+  As for `type_index`, also `type_hash` is a _sfinae-friendly_ class that can be
   specialized in order to customize its behavior globally or on a per-type or
   per-traits basis.
 
-* A name associated with a given type:
+* The name associated with a given type:
 
   ```cpp
   auto name = entt::type_name<a_type>::value();
@@ -467,7 +467,7 @@ Basically, the whole system relies on a handful of classes. In particular:
   means of the `ENTT_STANDARD_CPP` definition. In this case, the name will be
   empty by default.
 
-  As for `type_seq`, also `type_name` is a _sfinae-friendly_ class that can be
+  As for `type_index`, also `type_name` is a _sfinae-friendly_ class that can be
   specialized in order to customize its behavior globally or on a per-type or
   per-traits basis.
 
@@ -491,28 +491,28 @@ auto info = entt::type_id<a_type>();
 
 These are the information made available by this object:
 
-* An unique, sequential identifier associated with a given type:
+* The hash value associated with a given type:
 
   ```cpp
-  auto index = entt::type_id<a_type>().seq();
+  auto hash = entt::type_id<a_type>().hash_code();
   ```
 
   This is also an alias for the following:
 
   ```cpp
-  auto index = entt::type_seq<a_type>::value();
+  auto hash = entt::type_hash<a_type>::value();
   ```
 
-* A hash value associated with a given type:
+* The name associated with a given type:
 
   ```cpp
-  auto hash = entt::type_id<a_type>().hash_code();
+  auto name = entt::type_id<my_type>().name();
   ```
 
   This is also an alias for the following:
 
   ```cpp
-  auto hash = entt::type_hash<a_type>::value();
+  auto name = entt::type_name<a_type>::value();
   ```
 
 Where all accessed features are available at compile-time, the `type_info` class

+ 5 - 5
docs/md/lib.md

@@ -29,7 +29,7 @@ This isn't a problem in itself (in fact, it's the basis of an API so convenient
 to use). However, a way is needed to recognize the objects whose type has been
 erased on the other side of a boundary.<br/>
 The `type_hash` class template is how identifiers are generated and thus made
-available to the rest of the library. The `type_seq` class template makes all
+available to the rest of the library. The `type_index` class template makes all
 types _indexable_ instead, so as to speed up the lookup.
 
 In general, these classes don't arouse much interest. The only exceptions are:
@@ -47,16 +47,16 @@ In general, these classes don't arouse much interest. The only exceptions are:
   `EnTT`, so as to make everything work nicely across boundaries.
 
 * When working with plugins or shared libraries that don't export any symbol. In
-  this case, `type_seq` confuses the other classes by giving potentially wrong
+  this case, `type_index` confuses the other classes by giving potentially wrong
   information to them.<br/>
   To avoid problems, it's required to provide a custom generator. Briefly, it's
-  necessary to specialize the `type_seq` class and make it point to a context
+  necessary to specialize the `type_index` class and make it point to a context
   that is also shared between the main application and the dynamically loaded
   libraries or plugins.<br/>
   This will make the type system available to the whole application, not just to
   a particular tool such as the registry or the dispatcher. It means that a call
-  to `type_seq::value()` will return the same identifier for the same type from
-  both sides of a boundary and can be used reliably for any purpose.
+  to `type_index::value()` will return the same identifier for the same type
+  from both sides of a boundary and can be used reliably for any purpose.
 
 For anyone who needs more details, the test suite contains multiple examples
 covering the most common cases (see the `lib` directory for all details).<br/>

+ 4 - 4
src/entt/core/type_info.hpp

@@ -23,7 +23,7 @@ namespace entt {
 namespace internal {
 
 
-struct ENTT_API type_seq final {
+struct ENTT_API type_index final {
     [[nodiscard]] static id_type next() ENTT_NOEXCEPT {
         static ENTT_MAYBE_ATOMIC(id_type) value{};
         return value++;
@@ -89,13 +89,13 @@ template<typename Type>
  * @tparam Type Type for which to generate a sequential identifier.
  */
 template<typename Type, typename = void>
-struct ENTT_API type_seq final {
+struct ENTT_API type_index final {
     /**
      * @brief Returns the sequential identifier of a given type.
      * @return The sequential identifier of a given type.
      */
     [[nodiscard]] static id_type value() ENTT_NOEXCEPT {
-        static const id_type value = internal::type_seq::next();
+        static const id_type value = internal::type_index::next();
         return value;
     }
 
@@ -119,7 +119,7 @@ struct type_hash final {
         return internal::type_hash<Type>(0);
 #else
     [[nodiscard]] static constexpr id_type value() ENTT_NOEXCEPT {
-        return type_seq<Type>::value();
+        return type_index<Type>::value();
 #endif
     }
 

+ 2 - 2
src/entt/entity/registry.hpp

@@ -107,7 +107,7 @@ class basic_registry {
     template<typename Component>
     [[nodiscard]] storage_type<Component> * assure() const {
         static_assert(std::is_same_v<Component, std::decay_t<Component>>, "Non-decayed types not allowed");
-        const auto index = type_seq<Component>::value();
+        const auto index = type_index<Component>::value();
 
         if(!(index < pools.size())) {
             pools.resize(size_type(index)+1u);
@@ -124,7 +124,7 @@ class basic_registry {
     template<typename Component>
     [[nodiscard]] const storage_type<Component> * pool_if_exists() const ENTT_NOEXCEPT {
         static_assert(std::is_same_v<Component, std::decay_t<Component>>, "Non-decayed types not allowed");
-        const auto index = type_seq<Component>::value();
+        const auto index = type_index<Component>::value();
         return (!(index < pools.size()) || !pools[index].pool) ? nullptr : static_cast<const storage_type<Component> *>(pools[index].pool.get());
     }
 

+ 1 - 1
src/entt/signal/dispatcher.hpp

@@ -87,7 +87,7 @@ class dispatcher {
 
     template<typename Event>
     [[nodiscard]] pool_handler<Event> & assure() {
-        const auto index = type_seq<Event>::value();
+        const auto index = type_index<Event>::value();
 
         if(!(index < pools.size())) {
             pools.resize(std::size_t(index)+1u);

+ 2 - 2
src/entt/signal/emitter.hpp

@@ -123,7 +123,7 @@ class emitter {
 
     template<typename Event>
     [[nodiscard]] pool_handler<Event> * assure() {
-        const auto index = type_seq<Event>::value();
+        const auto index = type_index<Event>::value();
 
         if(!(index < pools.size())) {
             pools.resize(std::size_t(index)+1u);
@@ -138,7 +138,7 @@ class emitter {
 
     template<typename Event>
     [[nodiscard]] const pool_handler<Event> * assure() const {
-        const auto index = type_seq<Event>::value();
+        const auto index = type_index<Event>::value();
         return (!(index < pools.size()) || !pools[index]) ? nullptr : static_cast<const pool_handler<Event> *>(pools[index].get());
     }
 

+ 6 - 6
test/entt/core/type_info.cpp

@@ -12,12 +12,12 @@ struct entt::type_name<float> final {
     }
 };
 
-TEST(TypeSeq, Functionalities) {
-    ASSERT_EQ(entt::type_seq<int>::value(), entt::type_seq<int>::value());
-    ASSERT_NE(entt::type_seq<int>::value(), entt::type_seq<char>::value());
-    ASSERT_NE(entt::type_seq<int>::value(), entt::type_seq<int &&>::value());
-    ASSERT_NE(entt::type_seq<int &>::value(), entt::type_seq<const int &>::value());
-    ASSERT_EQ(static_cast<entt::id_type>(entt::type_seq<int>{}), entt::type_seq<int>::value());
+TEST(TypeIndex, Functionalities) {
+    ASSERT_EQ(entt::type_index<int>::value(), entt::type_index<int>::value());
+    ASSERT_NE(entt::type_index<int>::value(), entt::type_index<char>::value());
+    ASSERT_NE(entt::type_index<int>::value(), entt::type_index<int &&>::value());
+    ASSERT_NE(entt::type_index<int &>::value(), entt::type_index<const int &>::value());
+    ASSERT_EQ(static_cast<entt::id_type>(entt::type_index<int>{}), entt::type_index<int>::value());
 }
 
 TEST(TypeHash, Functionalities) {

+ 1 - 1
test/lib/dispatcher_plugin/main.cpp

@@ -8,7 +8,7 @@
 #include "types.h"
 
 template<typename Type>
-struct entt::type_seq<Type> {
+struct entt::type_index<Type> {
     [[nodiscard]] static id_type value() ENTT_NOEXCEPT {
         static const entt::id_type value = type_context::instance()->value(entt::type_hash<Type>::value());
         return value;

+ 1 - 1
test/lib/dispatcher_plugin/plugin.cpp

@@ -9,7 +9,7 @@ struct ctx {
 };
 
 template<typename Type>
-struct entt::type_seq<Type> {
+struct entt::type_index<Type> {
     [[nodiscard]] static id_type value() ENTT_NOEXCEPT {
         static const entt::id_type value = ctx::ref->value(entt::type_hash<Type>::value());
         return value;

+ 1 - 1
test/lib/emitter_plugin/main.cpp

@@ -8,7 +8,7 @@
 #include "types.h"
 
 template<typename Type>
-struct entt::type_seq<Type> {
+struct entt::type_index<Type> {
     [[nodiscard]] static id_type value() ENTT_NOEXCEPT {
         static const entt::id_type value = type_context::instance()->value(entt::type_hash<Type>::value());
         return value;

+ 1 - 1
test/lib/emitter_plugin/plugin.cpp

@@ -9,7 +9,7 @@ struct ctx {
 };
 
 template<typename Type>
-struct entt::type_seq<Type> {
+struct entt::type_index<Type> {
     [[nodiscard]] static id_type value() ENTT_NOEXCEPT {
         static const entt::id_type value = ctx::ref->value(entt::type_hash<Type>::value());
         return value;

+ 1 - 1
test/lib/registry_plugin/main.cpp

@@ -8,7 +8,7 @@
 #include "types.h"
 
 template<typename Type>
-struct entt::type_seq<Type> {
+struct entt::type_index<Type> {
     [[nodiscard]] static id_type value() ENTT_NOEXCEPT {
         static const entt::id_type value = type_context::instance()->value(entt::type_hash<Type>::value());
         return value;

+ 1 - 1
test/lib/registry_plugin/plugin.cpp

@@ -9,7 +9,7 @@ struct ctx {
 };
 
 template<typename Type>
-struct entt::type_seq<Type> {
+struct entt::type_index<Type> {
     [[nodiscard]] static id_type value() ENTT_NOEXCEPT {
         static const entt::id_type value = ctx::ref->value(entt::type_hash<Type>::value());
         return value;