Quellcode durchsuchen

component_traits: deprecate old version (sort of) to make the migration easier

Michele Caini vor 1 Jahr
Ursprung
Commit
de80e7b910

+ 9 - 8
docs/md/entity.md

@@ -1300,11 +1300,12 @@ packed and maximize performance, unless full pointer stability is enabled.
 
 In `EnTT`, almost everything is customizable. Pools are no exception.<br/>
 In this case, the _standardized_ way to access all component properties is the
-`component_traits` class.
+`component_traits_deprecated` class.
 
 Various parts of the library access component properties through this class. It
 makes it possible to use any type as a component, as long as its specialization
-of `component_traits` implements all the required functionalities.<br/>
+of `component_traits_deprecated` implements all the required
+functionalities.<br/>
 The non-specialized version of this class contains the following members:
 
 * `in_place_delete`: `Type::in_place_delete` if present, true for non-movable
@@ -1324,8 +1325,8 @@ struct transform {
 };
 ```
 
-The `component_traits` class template takes care of _extracting_ the properties
-from the supplied type.<br/>
+The `component_traits_deprecated` class template takes care of _extracting_ the
+properties from the supplied type.<br/>
 Plus, it's _sfinae-friendly_ and also supports feature-based specializations.
 
 ## Empty type optimization
@@ -1349,8 +1350,8 @@ More in general, none of the feature offered by the library is affected, but for
 the ones that require to return actual instances.<br/>
 This optimization is disabled by defining the `ENTT_NO_ETO` macro. In this case,
 empty types are treated like all other types. Setting a page size at component
-level via the `component_traits` class template is another way to disable this
-optimization selectively rather than globally.
+level via the `component_traits_deprecated` class template is another way to
+disable this optimization selectively rather than globally.
 
 ## Void storage
 
@@ -1457,8 +1458,8 @@ In other words, pointer stability is not automatic but is enabled on request.
 
 The library offers out of the box support for in-place deletion, thus offering
 storage with completely stable pointers. This is achieved by specializing the
-`component_traits` class or by adding the required properties to the component
-definition when needed.<br/>
+`component_traits_deprecated` class or by adding the required properties to the
+component definition when needed.<br/>
 Views and groups adapt accordingly when they detect a storage with a different
 deletion policy than the default. In particular:
 

+ 1 - 1
docs/md/faq.md

@@ -77,7 +77,7 @@ In addition, `EnTT` also offers the possibility to create stable storage types
 and therefore have pointer stability for one, all or some components. This is by
 far the most convenient solution when it comes to creating hierarchies and
 whatnot. See the documentation for the ECS part of the library and in particular
-what concerns the `component_traits` class for further details.
+what concerns the `component_traits_deprecated` class for further details.
 
 ## Custom entity identifiers: yay or nay?
 

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

@@ -39,7 +39,7 @@ struct page_size<Type, std::void_t<decltype(Type::page_size)>>
  * @tparam Type Type of component.
  */
 template<typename Type, typename = void>
-struct component_traits {
+struct component_traits_deprecated {
     static_assert(std::is_same_v<std::decay_t<Type>, Type>, "Unsupported type");
 
     /*! @brief Component type. */

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

@@ -124,7 +124,7 @@ void invoke(Registry &reg, const typename Registry::entity_type entt) {
  */
 template<typename... Args>
 typename basic_storage<Args...>::entity_type to_entity(const basic_storage<Args...> &storage, const typename basic_storage<Args...>::value_type &instance) {
-    using traits_type = component_traits<typename basic_storage<Args...>::value_type>;
+    using traits_type = component_traits_deprecated<typename basic_storage<Args...>::value_type>;
     static_assert(traits_type::page_size != 0u, "Unexpected page size");
     const typename basic_storage<Args...>::base_type &base = storage;
     const auto *addr = std::addressof(instance);

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

@@ -90,7 +90,7 @@ public:
 
     [[nodiscard]] constexpr reference operator[](const difference_type value) const noexcept {
         const auto pos = static_cast<typename Container::size_type>(index() - value);
-        constexpr auto page_size = component_traits<value_type>::page_size;
+        constexpr auto page_size = component_traits_deprecated<value_type>::page_size;
         return (*payload)[pos / page_size][fast_mod(static_cast<std::size_t>(pos), page_size)];
     }
 
@@ -233,7 +233,7 @@ class basic_storage: public basic_sparse_set<Entity, typename std::allocator_tra
     using container_type = std::vector<typename alloc_traits::pointer, typename alloc_traits::template rebind_alloc<typename alloc_traits::pointer>>;
     using underlying_type = basic_sparse_set<Entity, typename alloc_traits::template rebind_alloc<Entity>>;
     using underlying_iterator = typename underlying_type::basic_iterator;
-    using traits_type = component_traits<Type>;
+    using traits_type = component_traits_deprecated<Type>;
 
     [[nodiscard]] auto &element_at(const std::size_t pos) const {
         return payload[pos / traits_type::page_size][fast_mod(pos, traits_type::page_size)];
@@ -791,11 +791,11 @@ private:
 
 /*! @copydoc basic_storage */
 template<typename Type, typename Entity, typename Allocator>
-class basic_storage<Type, Entity, Allocator, std::enable_if_t<component_traits<Type>::page_size == 0u>>
+class basic_storage<Type, Entity, Allocator, std::enable_if_t<component_traits_deprecated<Type>::page_size == 0u>>
     : 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");
-    using traits_type = component_traits<Type>;
+    using traits_type = component_traits_deprecated<Type>;
 
 public:
     /*! @brief Allocator type. */

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

@@ -13,49 +13,49 @@ struct self_contained {
 struct traits_based {};
 
 template<>
-struct entt::component_traits<traits_based> {
+struct entt::component_traits_deprecated<traits_based> {
     using type = traits_based;
     static constexpr auto in_place_delete = false;
     static constexpr auto page_size = 8u;
 };
 
 TEST(Component, VoidType) {
-    using traits_type = entt::component_traits<void>;
+    using traits_type = entt::component_traits_deprecated<void>;
 
     ASSERT_FALSE(traits_type::in_place_delete);
     ASSERT_EQ(traits_type::page_size, 0u);
 }
 
 TEST(Component, Empty) {
-    using traits_type = entt::component_traits<test::empty>;
+    using traits_type = entt::component_traits_deprecated<test::empty>;
 
     ASSERT_FALSE(traits_type::in_place_delete);
     ASSERT_EQ(traits_type::page_size, 0u);
 }
 
 TEST(Component, NonEmpty) {
-    using traits_type = entt::component_traits<test::boxed_int>;
+    using traits_type = entt::component_traits_deprecated<test::boxed_int>;
 
     ASSERT_FALSE(traits_type::in_place_delete);
     ASSERT_EQ(traits_type::page_size, ENTT_PACKED_PAGE);
 }
 
 TEST(Component, NonMovable) {
-    using traits_type = entt::component_traits<test::non_movable>;
+    using traits_type = entt::component_traits_deprecated<test::non_movable>;
 
     ASSERT_TRUE(traits_type::in_place_delete);
     ASSERT_EQ(traits_type::page_size, ENTT_PACKED_PAGE);
 }
 
 TEST(Component, SelfContained) {
-    using traits_type = entt::component_traits<self_contained>;
+    using traits_type = entt::component_traits_deprecated<self_contained>;
 
     ASSERT_TRUE(traits_type::in_place_delete);
     ASSERT_EQ(traits_type::page_size, 4u);
 }
 
 TEST(Component, TraitsBased) {
-    using traits_type = entt::component_traits<traits_based>;
+    using traits_type = entt::component_traits_deprecated<traits_based>;
 
     ASSERT_TRUE(!traits_type::in_place_delete);
     ASSERT_EQ(traits_type::page_size, 8u);

+ 1 - 1
test/entt/entity/helper.cpp

@@ -62,7 +62,7 @@ TEST(Invoke, Functionalities) {
 
 TYPED_TEST(ToEntity, Functionalities) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::registry registry;
     const entt::entity null = entt::null;

+ 1 - 1
test/entt/entity/reactive_mixin.cpp

@@ -49,7 +49,7 @@ TYPED_TEST_SUITE(ReactiveMixinDeathTest, ReactiveMixinTypes, );
 
 TYPED_TEST(ReactiveMixin, Constructors) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::reactive_mixin<entt::storage<value_type>> pool;
 

+ 3 - 3
test/entt/entity/sigh_mixin.cpp

@@ -68,7 +68,7 @@ TYPED_TEST_SUITE(SighMixinDeathTest, SighMixinTypes, );
 
 TYPED_TEST(SighMixin, Functionalities) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::registry registry;
     auto &pool = registry.storage<value_type>();
@@ -384,7 +384,7 @@ TYPED_TEST(SighMixin, Move) {
 
 TYPED_TEST(SighMixin, Swap) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::sigh_mixin<entt::storage<value_type>> pool;
     entt::sigh_mixin<entt::storage<value_type>> other;
@@ -594,7 +594,7 @@ TYPED_TEST(SighMixin, ThrowingAllocator) {
     typename storage_type::base_type &base = pool;
     registry_type registry;
 
-    constexpr auto packed_page_size = entt::component_traits<value_type>::page_size;
+    constexpr auto packed_page_size = entt::component_traits_deprecated<value_type>::page_size;
     constexpr auto sparse_page_size = entt::entt_traits<entt::entity>::page_size;
 
     std::size_t on_construct{};

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

@@ -62,20 +62,20 @@ struct create_from_constructor {
 };
 
 template<>
-struct entt::component_traits<std::unordered_set<char>> {
+struct entt::component_traits_deprecated<std::unordered_set<char>> {
     static constexpr auto in_place_delete = true;
     static constexpr auto page_size = 4u;
 };
 
 template<>
-struct entt::component_traits<int> {
+struct entt::component_traits_deprecated<int> {
     static constexpr auto in_place_delete = false;
     static constexpr auto page_size = 128u;
 };
 
 template<typename Type>
 struct Storage: testing::Test {
-    static_assert(entt::component_traits<Type>::page_size != 0u, "Empty type not allowed");
+    static_assert(entt::component_traits_deprecated<Type>::page_size != 0u, "Empty type not allowed");
 
     using type = Type;
 };
@@ -90,7 +90,7 @@ TYPED_TEST_SUITE(StorageDeathTest, StorageTypes, );
 
 TYPED_TEST(Storage, Constructors) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
 
@@ -164,7 +164,7 @@ TYPED_TEST(Storage, Move) {
 
 TYPED_TEST(Storage, Swap) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
     entt::storage<value_type> other;
@@ -198,7 +198,7 @@ TYPED_TEST(Storage, Swap) {
 
 TYPED_TEST(Storage, Capacity) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
 
@@ -215,7 +215,7 @@ TYPED_TEST(Storage, Capacity) {
 
 TYPED_TEST(Storage, ShrinkToFit) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
 
@@ -544,11 +544,11 @@ TYPED_TEST(Storage, IteratorConversion) {
 
 TYPED_TEST(Storage, IteratorPageSizeAwareness) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
 
-    static_assert(!std::is_same_v<value_type, int> || (traits_type::page_size != entt::component_traits<value_type *>::page_size), "Different page size required");
+    static_assert(!std::is_same_v<value_type, int> || (traits_type::page_size != entt::component_traits_deprecated<value_type *>::page_size), "Different page size required");
 
     for(unsigned int next{}; next < traits_type::page_size; ++next) {
         pool.emplace(entt::entity{next});
@@ -664,7 +664,7 @@ TEST(Storage, EmplaceSelfMoveSupportInPlaceDelete) {
 
 TYPED_TEST(Storage, TryEmplace) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
     entt::sparse_set &base = pool;
@@ -833,7 +833,7 @@ ENTT_DEBUG_TYPED_TEST(StorageDeathTest, Patch) {
 
 TYPED_TEST(Storage, Insert) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
     const std::array entity{entt::entity{1}, entt::entity{3}};
@@ -878,7 +878,7 @@ TYPED_TEST(Storage, Insert) {
 
 TYPED_TEST(Storage, Erase) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
     const std::array entity{entt::entity{1}, entt::entity{3}, entt::entity{2}};
@@ -935,7 +935,7 @@ TYPED_TEST(Storage, CrossErase) {
 
 TYPED_TEST(Storage, Remove) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
     const std::array entity{entt::entity{1}, entt::entity{3}, entt::entity{2}};
@@ -995,7 +995,7 @@ TYPED_TEST(Storage, CrossRemove) {
 
 TYPED_TEST(Storage, Clear) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
     const std::array entity{entt::entity{1}, entt::entity{3}, entt::entity{2}};
@@ -1020,7 +1020,7 @@ TYPED_TEST(Storage, Clear) {
 
 TYPED_TEST(Storage, Compact) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
 
@@ -1066,7 +1066,7 @@ TYPED_TEST(Storage, Compact) {
 
 TYPED_TEST(Storage, SwapElements) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
 
@@ -1635,7 +1635,7 @@ ENTT_DEBUG_TEST(StorageDeathTest, NonMovableComponent) {
 
 TYPED_TEST(Storage, CanModifyDuringIteration) {
     using value_type = typename TestFixture::type;
-    using traits_type = entt::component_traits<value_type>;
+    using traits_type = entt::component_traits_deprecated<value_type>;
 
     entt::storage<value_type> pool;
     auto *ptr = &pool.emplace(entt::entity{0}, 2);
@@ -1783,7 +1783,7 @@ TYPED_TEST(Storage, ThrowingAllocator) {
     entt::basic_storage<value_type, entt::entity, test::throwing_allocator<value_type>> pool{};
     typename std::decay_t<decltype(pool)>::base_type &base = pool;
 
-    constexpr auto packed_page_size = entt::component_traits<value_type>::page_size;
+    constexpr auto packed_page_size = entt::component_traits_deprecated<value_type>::page_size;
     constexpr auto sparse_page_size = entt::entt_traits<entt::entity>::page_size;
 
     pool.get_allocator().template throw_counter<value_type>(0u);

+ 1 - 1
test/entt/entity/storage_no_instance.cpp

@@ -17,7 +17,7 @@
 
 template<typename Type>
 struct StorageNoInstance: testing::Test {
-    static_assert(entt::component_traits<Type>::page_size == 0u, "Non-empty type not allowed");
+    static_assert(entt::component_traits_deprecated<Type>::page_size == 0u, "Non-empty type not allowed");
 
     using type = Type;