Browse Source

storage_traits: small review

Michele Caini 5 years ago
parent
commit
3338d5e105
4 changed files with 20 additions and 26 deletions
  1. 2 2
      src/entt/entity/group.hpp
  2. 14 11
      src/entt/entity/registry.hpp
  3. 2 11
      src/entt/entity/storage.hpp
  4. 2 2
      src/entt/entity/view.hpp

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

@@ -69,7 +69,7 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>> final {
     friend class basic_registry<Entity>;
 
     template<typename Component>
-    using storage_type = storage_t<Entity, Component>;
+    using storage_type = typename storage_traits<Entity, Component>::storage_type;
 
     class iterable_group final {
         friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>>;
@@ -574,7 +574,7 @@ class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...> final
     friend class basic_registry<Entity>;
 
     template<typename Component>
-    using storage_type = storage_t<Entity, Component>;
+    using storage_type = typename storage_traits<Entity, Component>::storage_type;
 
     class iterable_group final {
         friend class basic_group<Entity, exclude_t<Exclude...>, get_t<Get...>, Owned...>;

+ 14 - 11
src/entt/entity/registry.hpp

@@ -41,6 +41,9 @@ template<typename Entity>
 class basic_registry {
     using traits_type = entt_traits<Entity>;
 
+    template<typename Component>
+    using storage_type = typename storage_traits<Entity, Component>::storage_type;
+
     struct pool_data {
         type_info info{};
         std::unique_ptr<basic_sparse_set<Entity>> pool{};
@@ -59,7 +62,7 @@ class basic_registry {
         void maybe_valid_if(basic_registry &owner, const Entity entt) {
             [[maybe_unused]] const auto cpools = std::forward_as_tuple(owner.assure<Owned>()...);
 
-            const auto is_valid = ((std::is_same_v<Component, Owned> || std::get<storage_t<Entity, Owned> &>(cpools).contains(entt)) && ...)
+            const auto is_valid = ((std::is_same_v<Component, Owned> || std::get<storage_type<Owned> &>(cpools).contains(entt)) && ...)
                     && ((std::is_same_v<Component, Get> || owner.assure<Get>().contains(entt)) && ...)
                     && ((std::is_same_v<Component, Exclude> || !owner.assure<Exclude>().contains(entt)) && ...);
 
@@ -70,7 +73,7 @@ class basic_registry {
             } else {
                 if(is_valid && !(std::get<0>(cpools).index(entt) < current)) {
                     const auto pos = current++;
-                    (std::get<storage_t<Entity, Owned> &>(cpools).swap(std::get<storage_t<Entity, Owned> &>(cpools).data()[pos], entt), ...);
+                    (std::get<storage_type<Owned> &>(cpools).swap(std::get<storage_type<Owned> &>(cpools).data()[pos], entt), ...);
                 }
             }
         }
@@ -83,7 +86,7 @@ class basic_registry {
             } else {
                 if(const auto cpools = std::forward_as_tuple(owner.assure<Owned>()...); std::get<0>(cpools).contains(entt) && (std::get<0>(cpools).index(entt) < current)) {
                     const auto pos = --current;
-                    (std::get<storage_t<Entity, Owned> &>(cpools).swap(std::get<storage_t<Entity, Owned> &>(cpools).data()[pos], entt), ...);
+                    (std::get<storage_type<Owned> &>(cpools).swap(std::get<storage_type<Owned> &>(cpools).data()[pos], entt), ...);
                 }
             }
         }
@@ -103,7 +106,7 @@ class basic_registry {
     };
 
     template<typename Component>
-    [[nodiscard]] const storage_t<Entity, Component> & assure() const {
+    [[nodiscard]] const storage_type<Component> & assure() const {
         const auto index = type_seq<Component>::value();
 
         if(!(index < pools.size())) {
@@ -112,18 +115,18 @@ class basic_registry {
 
         if(auto &&pdata = pools[index]; !pdata.pool) {
             pdata.info = type_id<Component>();
-            pdata.pool.reset(new storage_t<Entity, Component>());
+            pdata.pool.reset(new storage_type<Component>());
             pdata.remove = +[](basic_sparse_set<Entity> &cpool, basic_registry &owner, const Entity *first, const Entity *last) {
-                static_cast<storage_t<Entity, Component> &>(cpool).remove(owner, first, last);
+                static_cast<storage_type<Component> &>(cpool).remove(owner, first, last);
             };
         }
 
-        return static_cast<const storage_t<Entity, Component> &>(*pools[index].pool);
+        return static_cast<const storage_type<Component> &>(*pools[index].pool);
     }
 
     template<typename Component>
-    [[nodiscard]] storage_t<Entity, Component> & assure() {
-        return const_cast<storage_t<Entity, Component> &>(std::as_const(*this).template assure<Component>());
+    [[nodiscard]] storage_type<Component> & assure() {
+        return const_cast<storage_type<Component> &>(std::as_const(*this).template assure<Component>());
     }
 
     Entity generate_identifier() {
@@ -1256,9 +1259,9 @@ public:
         }
 
         if constexpr(sizeof...(Owned) == 0) {
-            return { handler->current, std::get<storage_t<Entity, std::decay_t<Get>> &>(cpools)... };
+            return { handler->current, std::get<storage_type<std::decay_t<Get>> &>(cpools)... };
         } else {
-            return { handler->current, std::get<storage_t<Entity, std::decay_t<Owned>> &>(cpools)... , std::get<storage_t<Entity, std::decay_t<Get>> &>(cpools)... };
+            return { handler->current, std::get<storage_type<std::decay_t<Owned>> &>(cpools)... , std::get<storage_type<std::decay_t<Get>> &>(cpools)... };
         }
     }
 

+ 2 - 11
src/entt/entity/storage.hpp

@@ -829,7 +829,7 @@ private:
 template<typename Entity, typename Type, typename = void>
 struct storage_traits {
     /*! @brief Resulting type after component-to-storage conversion. */
-    using value_type = sigh_storage_mixin<storage_adapter_mixin<basic_storage<Entity, Type>>>;
+    using storage_type = sigh_storage_mixin<storage_adapter_mixin<basic_storage<Entity, Type>>>;
 };
 
 
@@ -837,19 +837,10 @@ struct storage_traits {
 template<typename Entity, typename Type>
 struct storage_traits<Entity, const Type> {
     /*! @brief Resulting type after component-to-storage conversion. */
-    using value_type = std::add_const_t<typename storage_traits<Entity, std::remove_const_t<Type>>::value_type>;
+    using storage_type = std::add_const_t<typename storage_traits<Entity, std::remove_const_t<Type>>::storage_type>;
 };
 
 
-/**
- * @brief Alias declaration to use to make component-to-storage conversions.
- * @tparam Entity A valid entity type (see entt_traits for more details).
- * @tparam Type Type of objects assigned to the entities.
- */
-template<typename Entity, typename Type>
-using storage_t = typename storage_traits<Entity, Type>::value_type;
-
-
 }
 
 

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

@@ -69,7 +69,7 @@ class basic_view<Entity, exclude_t<Exclude...>, Component...> final {
     friend class basic_registry<Entity>;
 
     template<typename Comp>
-    using storage_type = storage_t<Entity, Comp>;
+    using storage_type = typename storage_traits<Entity, Comp>::storage_type;
 
     using unchecked_type = std::array<const basic_sparse_set<Entity> *, (sizeof...(Component) - 1)>;
 
@@ -559,7 +559,7 @@ class basic_view<Entity, exclude_t<>, Component> final {
     /*! @brief A registry is allowed to create views. */
     friend class basic_registry<Entity>;
 
-    using storage_type = storage_t<Entity, Component>;
+    using storage_type = typename storage_traits<Entity, Component>::storage_type;
 
     class iterable_view {
         friend class basic_view<Entity, exclude_t<>, Component>;