Ver Fonte

basic_storage: flip entity type and value type

Michele Caini há 3 anos atrás
pai
commit
a5c9d3a809

+ 4 - 4
src/entt/entity/fwd.hpp

@@ -10,7 +10,7 @@ namespace entt {
 template<typename Entity, typename = std::allocator<Entity>>
 class basic_sparse_set;
 
-template<typename, typename Type, typename = std::allocator<Type>, typename = void>
+template<typename Type, typename, typename = std::allocator<Type>, typename = void>
 class basic_storage;
 
 template<typename Type>
@@ -96,10 +96,10 @@ using sparse_set = basic_sparse_set<entity>;
 
 /**
  * @brief Alias declaration for the most common use case.
- * @tparam Args Other template parameters.
+ * @tparam Type Type of objects assigned to the entities.
  */
-template<typename... Args>
-using storage = basic_storage<entity, Args...>;
+template<typename Type>
+using storage = basic_storage<Type, entity>;
 
 /*! @brief Alias declaration for the most common use case. */
 using registry = basic_registry<entity>;

+ 1 - 1
src/entt/entity/observer.hpp

@@ -426,7 +426,7 @@ public:
 
 private:
     delegate<void(basic_observer &)> release;
-    basic_storage<entity_type, payload_type> storage;
+    basic_storage<payload_type, entity_type> storage;
 };
 
 } // namespace entt

+ 5 - 5
src/entt/entity/storage.hpp

@@ -227,11 +227,11 @@ template<typename... CLhs, typename... CRhs>
  * Empty types aren't explicitly instantiated. Therefore, many of the functions
  * normally available for non-empty types will not be available for empty ones.
  *
- * @tparam Entity A valid entity type (see entt_traits for more details).
  * @tparam Type Type of objects assigned to the entities.
+ * @tparam Entity A valid entity type (see entt_traits for more details).
  * @tparam Allocator Type of allocator used to manage memory and elements.
  */
-template<typename Entity, typename Type, typename Allocator, typename>
+template<typename Type, typename Entity, typename Allocator, typename>
 class basic_storage: public basic_sparse_set<Entity, typename std::allocator_traits<Allocator>::template rebind_alloc<Entity>> {
     static_assert(std::is_move_constructible_v<Type> && std::is_move_assignable_v<Type>, "The type must be at least move constructible/assignable");
 
@@ -748,8 +748,8 @@ private:
 };
 
 /*! @copydoc basic_storage */
-template<typename Entity, typename Type, typename Allocator>
-class basic_storage<Entity, Type, Allocator, std::enable_if_t<ignore_as_empty_v<Type>>>
+template<typename Type, typename Entity, typename Allocator>
+class basic_storage<Type, Entity, Allocator, std::enable_if_t<ignore_as_empty_v<Type>>>
     : public basic_sparse_set<Entity, typename std::allocator_traits<Allocator>::template rebind_alloc<Entity>> {
     using alloc_traits = std::allocator_traits<Allocator>;
     static_assert(std::is_same_v<typename alloc_traits::value_type, Type>, "Invalid value type");
@@ -906,7 +906,7 @@ public:
 template<typename Entity, typename Type, typename = void>
 struct storage_type {
     /*! @brief Resulting type after component-to-storage conversion. */
-    using type = sigh_storage_mixin<basic_storage<Entity, Type>>;
+    using type = sigh_storage_mixin<basic_storage<Type, Entity>>;
 };
 
 /**

+ 5 - 5
test/entt/entity/sigh_storage_mixin.cpp

@@ -464,9 +464,9 @@ TEST(SighStorageMixin, CustomAllocator) {
 
     test::throwing_allocator<entt::entity> allocator{};
 
-    test(entt::sigh_storage_mixin<entt::storage<int, test::throwing_allocator<int>>>{allocator}, allocator);
-    test(entt::sigh_storage_mixin<entt::storage<std::true_type, test::throwing_allocator<std::true_type>>>{allocator}, allocator);
-    test(entt::sigh_storage_mixin<entt::storage<stable_type, test::throwing_allocator<stable_type>>>{allocator}, allocator);
+    test(entt::sigh_storage_mixin<entt::basic_storage<int, entt::entity, test::throwing_allocator<int>>>{allocator}, allocator);
+    test(entt::sigh_storage_mixin<entt::basic_storage<std::true_type, entt::entity, test::throwing_allocator<std::true_type>>>{allocator}, allocator);
+    test(entt::sigh_storage_mixin<entt::basic_storage<stable_type, entt::entity, test::throwing_allocator<stable_type>>>{allocator}, allocator);
 }
 
 TEST(SighStorageMixin, ThrowingAllocator) {
@@ -540,8 +540,8 @@ TEST(SighStorageMixin, ThrowingAllocator) {
         ASSERT_EQ(on_destroy.value, 1);
     };
 
-    test(entt::sigh_storage_mixin<entt::basic_storage<entt::entity, int, test::throwing_allocator<int>>>{});
-    test(entt::sigh_storage_mixin<entt::basic_storage<entt::entity, stable_type, test::throwing_allocator<stable_type>>>{});
+    test(entt::sigh_storage_mixin<entt::basic_storage<int, entt::entity, test::throwing_allocator<int>>>{});
+    test(entt::sigh_storage_mixin<entt::basic_storage<stable_type, entt::entity, test::throwing_allocator<stable_type>>>{});
 }
 
 TEST(SighStorageMixin, ThrowingComponent) {

+ 7 - 7
test/entt/entity/storage.cpp

@@ -1659,9 +1659,9 @@ TEST(Storage, CustomAllocator) {
 
     test::throwing_allocator<entt::entity> allocator{};
 
-    test(entt::basic_storage<entt::entity, int, test::throwing_allocator<int>>{allocator}, allocator);
-    test(entt::basic_storage<entt::entity, std::true_type, test::throwing_allocator<std::true_type>>{allocator}, allocator);
-    test(entt::basic_storage<entt::entity, stable_type, test::throwing_allocator<stable_type>>{allocator}, allocator);
+    test(entt::basic_storage<int, entt::entity, test::throwing_allocator<int>>{allocator}, allocator);
+    test(entt::basic_storage<std::true_type, entt::entity, test::throwing_allocator<std::true_type>>{allocator}, allocator);
+    test(entt::basic_storage<stable_type, entt::entity, test::throwing_allocator<stable_type>>{allocator}, allocator);
 }
 
 TEST(Storage, ThrowingAllocator) {
@@ -1724,8 +1724,8 @@ TEST(Storage, ThrowingAllocator) {
         ASSERT_FALSE(pool.contains(entt::entity{sparse_page_size}));
     };
 
-    test(entt::basic_storage<entt::entity, int, test::throwing_allocator<int>>{});
-    test(entt::basic_storage<entt::entity, stable_type, test::throwing_allocator<stable_type>>{});
+    test(entt::basic_storage<int, entt::entity, test::throwing_allocator<int>>{});
+    test(entt::basic_storage<stable_type, entt::entity, test::throwing_allocator<stable_type>>{});
 }
 
 TEST(Storage, ThrowingComponent) {
@@ -1784,7 +1784,7 @@ TEST(Storage, ThrowingComponent) {
 
 TEST(Storage, NoUsesAllocatorConstruction) {
     test::tracked_memory_resource memory_resource{};
-    entt::basic_storage<entt::entity, int, std::pmr::polymorphic_allocator<int>> pool{&memory_resource};
+    entt::basic_storage<int, entt::entity, std::pmr::polymorphic_allocator<int>> pool{&memory_resource};
     const entt::entity entity{};
 
     pool.emplace(entity);
@@ -1801,7 +1801,7 @@ TEST(Storage, UsesAllocatorConstruction) {
     using string_type = typename test::tracked_memory_resource::string_type;
 
     test::tracked_memory_resource memory_resource{};
-    entt::basic_storage<entt::entity, string_type, std::pmr::polymorphic_allocator<string_type>> pool{&memory_resource};
+    entt::basic_storage<string_type, entt::entity, std::pmr::polymorphic_allocator<string_type>> pool{&memory_resource};
     const entt::entity entity{};
 
     pool.emplace(entity);

+ 2 - 2
test/example/signal_less.cpp

@@ -7,13 +7,13 @@
 template<typename Entity, typename Type>
 struct entt::storage_type<Entity, Type> {
     // no signal regardless of component type ...
-    using type = basic_storage<Entity, Type>;
+    using type = basic_storage<Type, Entity>;
 };
 
 template<typename Entity>
 struct entt::storage_type<Entity, char> {
     // ... unless it's char, because yes.
-    using type = sigh_storage_mixin<basic_storage<Entity, char>>;
+    using type = sigh_storage_mixin<basic_storage<char, Entity>>;
 };
 
 template<typename, typename, typename = void>