Browse Source

*: minor explicit names for traits types

Michele Caini 4 years ago
parent
commit
a8b224a364

+ 5 - 5
src/entt/core/hashed_string.hpp

@@ -62,7 +62,7 @@ struct fnv1a_traits<std::uint64_t> {
  */
 template<typename Char>
 class basic_hashed_string {
-    using traits_type = internal::fnv1a_traits<id_type>;
+    using hs_traits = internal::fnv1a_traits<id_type>;
 
     struct const_wrapper {
         // non-explicit constructor on purpose
@@ -72,10 +72,10 @@ class basic_hashed_string {
 
     // Fowler–Noll–Vo hash function v. 1a - the good
     [[nodiscard]] static constexpr id_type helper(const Char *curr) ENTT_NOEXCEPT {
-        auto value = traits_type::offset;
+        auto value = hs_traits::offset;
 
         while(*curr != 0) {
-            value = (value ^ static_cast<traits_type::type>(*(curr++))) * traits_type::prime;
+            value = (value ^ static_cast<hs_traits::type>(*(curr++))) * hs_traits::prime;
         }
 
         return value;
@@ -94,8 +94,8 @@ public:
      * @return The numeric representation of the string.
      */
     [[nodiscard]] static constexpr hash_type value(const value_type *str, std::size_t size) ENTT_NOEXCEPT {
-        id_type partial{traits_type::offset};
-        while(size--) { partial = (partial^(str++)[0])*traits_type::prime; }
+        id_type partial{hs_traits::offset};
+        while(size--) { partial = (partial ^ (str++)[0]) * hs_traits::prime; }
         return partial;
     }
 

+ 9 - 9
src/entt/entity/entity.hpp

@@ -75,17 +75,17 @@ struct entt_traits<std::uint64_t> {
  */
 template<typename Type>
 class entt_traits: private internal::entt_traits<Type> {
-    using traits_type = internal::entt_traits<Type>;
+    using entity_traits = internal::entt_traits<Type>;
 
 public:
     /*! @brief Value type. */
     using value_type = Type;
     /*! @brief Underlying entity type. */
-    using entity_type = typename traits_type::entity_type;
+    using entity_type = typename entity_traits::entity_type;
     /*! @brief Underlying version type. */
-    using version_type = typename traits_type::version_type;
+    using version_type = typename entity_traits::version_type;
     /*! @brief Difference type. */
-    using difference_type = typename traits_type::difference_type;
+    using difference_type = typename entity_traits::difference_type;
 
     /**
      * @brief Converts an entity to its underlying type.
@@ -102,7 +102,7 @@ public:
      * @return The integral representation of the entity part.
      */
     [[nodiscard]] static constexpr entity_type to_entity(const value_type value) ENTT_NOEXCEPT {
-        return (to_integral(value) & traits_type::entity_mask);
+        return (to_integral(value) & entity_traits::entity_mask);
     }
 
     /**
@@ -111,8 +111,8 @@ public:
      * @return The integral representation of the version part.
      */
     [[nodiscard]] static constexpr version_type to_version(const value_type value) ENTT_NOEXCEPT {
-        constexpr auto mask = (traits_type::version_mask << traits_type::entity_shift);
-        return ((to_integral(value) & mask) >> traits_type::entity_shift);
+        constexpr auto mask = (entity_traits::version_mask << entity_traits::entity_shift);
+        return ((to_integral(value) & mask) >> entity_traits::entity_shift);
     }
 
     /**
@@ -125,8 +125,8 @@ public:
      * @param version The version part of the identifier.
      * @return A properly constructed identifier.
      */
-    [[nodiscard]] static constexpr value_type construct(const entity_type entity = traits_type::entity_mask, const version_type version = traits_type::version_mask) ENTT_NOEXCEPT {
-        return value_type{(entity & traits_type::entity_mask) | (static_cast<entity_type>(version) << traits_type::entity_shift)};
+    [[nodiscard]] static constexpr value_type construct(const entity_type entity = entity_traits::entity_mask, const version_type version = entity_traits::version_mask) ENTT_NOEXCEPT {
+        return value_type{(entity & entity_traits::entity_mask) | (static_cast<entity_type>(version) << entity_traits::entity_shift)};
     }
 };
 

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

@@ -43,7 +43,7 @@ namespace entt {
  */
 template<typename Entity>
 class basic_registry {
-    using traits_type = entt_traits<Entity>;
+    using entity_traits = entt_traits<Entity>;
     using poly_storage_type = typename poly_storage_traits<Entity>::storage_type;
     using basic_common_type = basic_sparse_set<Entity>;
 
@@ -129,20 +129,20 @@ class basic_registry {
     }
 
     auto generate_identifier(const std::size_t pos) ENTT_NOEXCEPT {
-        ENTT_ASSERT(pos < traits_type::to_integral(null), "No entities available");
-        return traits_type::construct(static_cast<typename traits_type::entity_type>(pos), {});
+        ENTT_ASSERT(pos < entity_traits::to_integral(null), "No entities available");
+        return entity_traits::construct(static_cast<typename entity_traits::entity_type>(pos), {});
     }
 
     auto recycle_identifier() ENTT_NOEXCEPT {
         ENTT_ASSERT(free_list != null, "No entities available");
-        const auto curr = traits_type::to_entity(free_list);
+        const auto curr = entity_traits::to_entity(free_list);
         free_list = (tombstone | entities[curr]);
-        return (entities[curr] = traits_type::construct(curr, traits_type::to_version(entities[curr])));
+        return (entities[curr] = entity_traits::construct(curr, entity_traits::to_version(entities[curr])));
     }
 
-    auto release_entity(const Entity entity, const typename traits_type::version_type version) {
-        const typename traits_type::version_type vers = version + (version == traits_type::to_version(tombstone));
-        entities[traits_type::to_entity(entity)] = traits_type::construct(traits_type::to_entity(free_list), vers);
+    auto release_entity(const Entity entity, const typename entity_traits::version_type version) {
+        const typename entity_traits::version_type vers = version + (version == entity_traits::to_version(tombstone));
+        entities[entity_traits::to_entity(entity)] = entity_traits::construct(entity_traits::to_entity(free_list), vers);
         free_list = (tombstone | entity);
         return vers;
     }
@@ -151,7 +151,7 @@ public:
     /*! @brief Underlying entity identifier. */
     using entity_type = Entity;
     /*! @brief Underlying version type. */
-    using version_type = typename traits_type::version_type;
+    using version_type = typename entity_traits::version_type;
     /*! @brief Unsigned integer type. */
     using size_type = std::size_t;
     /*! @brief Poly storage type. */
@@ -163,7 +163,7 @@ public:
      * @return The entity identifier without the version.
      */
     [[nodiscard]] static entity_type entity(const entity_type entity) ENTT_NOEXCEPT {
-        return traits_type::construct(traits_type::to_entity(entity), {});
+        return entity_traits::construct(entity_traits::to_entity(entity), {});
     }
 
     /**
@@ -172,7 +172,7 @@ public:
      * @return The version stored along with the given entity identifier.
      */
     [[nodiscard]] static version_type version(const entity_type entity) ENTT_NOEXCEPT {
-        return traits_type::to_version(entity);
+        return entity_traits::to_version(entity);
     }
 
     /*! @brief Default constructor. */
@@ -238,7 +238,7 @@ public:
         auto sz = entities.size();
 
         for(auto curr = free_list; curr != null; --sz) {
-            curr = entities[traits_type::to_entity(curr)];
+            curr = entities[entity_traits::to_entity(curr)];
         }
 
         return sz;
@@ -350,7 +350,7 @@ public:
      * @return True if the identifier is valid, false otherwise.
      */
     [[nodiscard]] bool valid(const entity_type entity) const {
-        const auto pos = size_type(traits_type::to_entity(entity));
+        const auto pos = size_type(entity_traits::to_entity(entity));
         return (pos < entities.size() && entities[pos] == entity);
     }
 
@@ -366,7 +366,7 @@ public:
      * @return Actual version for the given entity identifier.
      */
     [[nodiscard]] version_type current(const entity_type entity) const {
-        const auto pos = size_type(traits_type::to_entity(entity));
+        const auto pos = size_type(entity_traits::to_entity(entity));
         ENTT_ASSERT(pos < entities.size(), "Entity does not exist");
         return version(entities[pos]);
     }
@@ -401,7 +401,7 @@ public:
 
         if(hint == null || hint == tombstone) {
             return create();
-        } else if(const auto req = traits_type::to_entity(hint); !(req < length)) {
+        } else if(const auto req = entity_traits::to_entity(hint); !(req < length)) {
             entities.resize(size_type(req) + 1u, null);
 
             for(auto pos = length; pos < req; ++pos) {
@@ -409,12 +409,12 @@ public:
             }
 
             return (entities[req] = hint);
-        } else if(const auto curr = traits_type::to_entity(entities[req]); req == curr) {
+        } else if(const auto curr = entity_traits::to_entity(entities[req]); req == curr) {
             return create();
         } else {
             auto *it = &free_list;
-            for(; traits_type::to_entity(*it) != req; it = &entities[traits_type::to_entity(*it)]);
-            *it = traits_type::construct(curr, traits_type::to_version(*it));
+            for(; entity_traits::to_entity(*it) != req; it = &entities[entity_traits::to_entity(*it)]);
+            *it = entity_traits::construct(curr, entity_traits::to_version(*it));
             return (entities[req] = hint);
         }
     }
@@ -995,7 +995,7 @@ public:
             }
         } else {
             for(auto pos = entities.size(); pos; --pos) {
-                if(const auto entity = entities[pos - 1]; traits_type::to_entity(entity) == (pos - 1)) {
+                if(const auto entity = entities[pos - 1]; entity_traits::to_entity(entity) == (pos - 1)) {
                     func(entity);
                 }
             }

+ 10 - 10
src/entt/entity/snapshot.hpp

@@ -32,12 +32,12 @@ namespace entt {
  */
 template<typename Entity>
 class basic_snapshot {
-    using traits_type = entt_traits<Entity>;
+    using entity_traits = entt_traits<Entity>;
 
     template<typename Component, typename Archive, typename It>
     void get(Archive &archive, std::size_t sz, It first, It last) const {
         const auto view = reg->template view<std::add_const_t<Component>>();
-        archive(typename traits_type::entity_type(sz));
+        archive(typename entity_traits::entity_type(sz));
 
         while(first != last) {
             const auto entt = *(first++);
@@ -93,7 +93,7 @@ public:
     const basic_snapshot & entities(Archive &archive) const {
         const auto sz = reg->size();
 
-        archive(typename traits_type::entity_type(sz));
+        archive(typename entity_traits::entity_type(sz));
 
         for(auto first = reg->data(), last = first + sz; first != last; ++first) {
             archive(*first);
@@ -164,11 +164,11 @@ private:
  */
 template<typename Entity>
 class basic_snapshot_loader {
-    using traits_type = entt_traits<Entity>;
+    using entity_traits = entt_traits<Entity>;
 
     template<typename Type, typename Archive>
     void assign(Archive &archive) const {
-        typename traits_type::entity_type length{};
+        typename entity_traits::entity_type length{};
         archive(length);
 
         entity_type entt{};
@@ -225,7 +225,7 @@ public:
      */
     template<typename Archive>
     const basic_snapshot_loader & entities(Archive &archive) const {
-        typename traits_type::entity_type length{};
+        typename entity_traits::entity_type length{};
 
         archive(length);
         std::vector<entity_type> all(length);
@@ -302,7 +302,7 @@ private:
  */
 template<typename Entity>
 class basic_continuous_loader {
-    using traits_type = entt_traits<Entity>;
+    using entity_traits = entt_traits<Entity>;
 
     void destroy(Entity entt) {
         if(const auto it = remloc.find(entt); it == remloc.cend()) {
@@ -387,7 +387,7 @@ class basic_continuous_loader {
 
     template<typename Other, typename Archive, typename... Type, typename... Member>
     void assign(Archive &archive, [[maybe_unused]] Member Type:: *... member) {
-        typename traits_type::entity_type length{};
+        typename entity_traits::entity_type length{};
         archive(length);
 
         entity_type entt{};
@@ -440,7 +440,7 @@ public:
      */
     template<typename Archive>
     basic_continuous_loader & entities(Archive &archive) {
-        typename traits_type::entity_type length{};
+        typename entity_traits::entity_type length{};
         entity_type entt{};
 
         archive(length);
@@ -448,7 +448,7 @@ public:
         for(decltype(length) pos{}; pos < length; ++pos) {
             archive(entt);
 
-            if(const auto entity = traits_type::to_entity(entt); entity == pos) {
+            if(const auto entity = entity_traits::to_entity(entt); entity == pos) {
                 restore(entt);
             } else {
                 destroy(entt);

+ 21 - 21
src/entt/entity/sparse_set.hpp

@@ -54,7 +54,7 @@ class basic_sparse_set {
     static constexpr auto growth_factor = 1.5;
     static constexpr auto sparse_page = ENTT_SPARSE_PAGE;
 
-    using traits_type = entt_traits<Entity>;
+    using entity_traits = entt_traits<Entity>;
 
     using alloc_traits = typename std::allocator_traits<Allocator>::template rebind_traits<Entity>;
     using alloc_pointer = typename alloc_traits::pointer;
@@ -67,7 +67,7 @@ class basic_sparse_set {
     static_assert(bucket_alloc_traits::propagate_on_container_move_assignment::value);
 
     struct sparse_set_iterator final {
-        using difference_type = typename traits_type::difference_type;
+        using difference_type = typename entity_traits::difference_type;
         using value_type = Entity;
         using pointer = const value_type *;
         using reference = const value_type &;
@@ -164,11 +164,11 @@ class basic_sparse_set {
     };
 
     [[nodiscard]] static auto page(const Entity entt) ENTT_NOEXCEPT {
-        return static_cast<size_type>(traits_type::to_entity(entt) / sparse_page);
+        return static_cast<size_type>(entity_traits::to_entity(entt) / sparse_page);
     }
 
     [[nodiscard]] static auto offset(const Entity entt) ENTT_NOEXCEPT {
-        return static_cast<size_type>(traits_type::to_entity(entt) & (sparse_page - 1));
+        return static_cast<size_type>(entity_traits::to_entity(entt) & (sparse_page - 1));
     }
 
     [[nodiscard]] auto assure_page(const std::size_t idx) {
@@ -246,7 +246,7 @@ protected:
      */
     virtual void swap_and_pop(const Entity entt, [[maybe_unused]] void *ud) {
         auto &ref = sparse[page(entt)][offset(entt)];
-        const auto pos = static_cast<size_type>(traits_type::to_entity(ref));
+        const auto pos = static_cast<size_type>(entity_traits::to_entity(ref));
         ENTT_ASSERT(packed[pos] == entt, "Invalid entity identifier");
         auto &last = packed[--count];
 
@@ -265,10 +265,10 @@ protected:
      */
     virtual void in_place_pop(const Entity entt, [[maybe_unused]] void *ud) {
         auto &ref = sparse[page(entt)][offset(entt)];
-        const auto pos = static_cast<size_type>(traits_type::to_entity(ref));
+        const auto pos = static_cast<size_type>(entity_traits::to_entity(ref));
         ENTT_ASSERT(packed[pos] == entt, "Invalid entity identifier");
 
-        packed[pos] = std::exchange(free_list, traits_type::construct(static_cast<typename traits_type::entity_type>(pos)));
+        packed[pos] = std::exchange(free_list, entity_traits::construct(static_cast<typename entity_traits::entity_type>(pos)));
         // lazy self-assignment guard
         ref = null;
     }
@@ -367,7 +367,7 @@ public:
      * @return The next slot available for insertion.
      */
     [[nodiscard]] size_type slot() const ENTT_NOEXCEPT {
-        return free_list == null ? count : static_cast<size_type>(traits_type::to_entity(free_list));
+        return free_list == null ? count : static_cast<size_type>(entity_traits::to_entity(free_list));
     }
 
     /**
@@ -454,7 +454,7 @@ public:
      * @return An iterator to the first entity of the internal packed array.
      */
     [[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
-        return iterator{std::addressof(packed), static_cast<typename traits_type::difference_type>(count)};
+        return iterator{std::addressof(packed), static_cast<typename entity_traits::difference_type>(count)};
     }
 
     /**
@@ -533,7 +533,7 @@ public:
      */
     [[nodiscard]] size_type index(const entity_type entt) const ENTT_NOEXCEPT {
         ENTT_ASSERT(contains(entt), "Set does not contain entity");
-        return static_cast<size_type>(traits_type::to_entity(sparse[page(entt)][offset(entt)]));
+        return static_cast<size_type>(entity_traits::to_entity(sparse[page(entt)][offset(entt)]));
     }
 
     /**
@@ -573,7 +573,7 @@ public:
             resize_packed(sz + !(sz > reserved));
         }
 
-        assure_page(page(entt))[offset(entt)] = traits_type::construct(static_cast<typename traits_type::entity_type>(count));
+        assure_page(page(entt))[offset(entt)] = entity_traits::construct(static_cast<typename entity_traits::entity_type>(count));
         packed[count] = entt;
         return count++;
     }
@@ -593,8 +593,8 @@ public:
             return emplace_back(entt);
         } else {
             ENTT_ASSERT(!contains(entt), "Set already contains entity");
-            const auto pos = static_cast<size_type>(traits_type::to_entity(free_list));
-            assure_page(page(entt))[offset(entt)] = traits_type::construct(static_cast<typename traits_type::entity_type>(pos));
+            const auto pos = static_cast<size_type>(entity_traits::to_entity(free_list));
+            assure_page(page(entt))[offset(entt)] = entity_traits::construct(static_cast<typename entity_traits::entity_type>(pos));
             free_list = std::exchange(packed[pos], entt);
             return pos;
         }
@@ -618,7 +618,7 @@ public:
         for(; first != last; ++first) {
             const auto entt = *first;
             ENTT_ASSERT(!contains(entt), "Set already contains entity");
-            assure_page(page(entt))[offset(entt)] = traits_type::construct(static_cast<typename traits_type::entity_type>(count));
+            assure_page(page(entt))[offset(entt)] = entity_traits::construct(static_cast<typename entity_traits::entity_type>(count));
             packed[count++] = entt;
         }
     }
@@ -689,13 +689,13 @@ public:
         size_type next = count;
         for(; next && packed[next - 1u] == tombstone; --next);
 
-        for(auto *it = &free_list; *it != null && next; it = std::addressof(packed[traits_type::to_entity(*it)])) {
-            if(const size_type pos = traits_type::to_entity(*it); pos < next) {
+        for(auto *it = &free_list; *it != null && next; it = std::addressof(packed[entity_traits::to_entity(*it)])) {
+            if(const size_type pos = entity_traits::to_entity(*it); pos < next) {
                 --next;
                 move_and_pop(next, pos);
                 std::swap(packed[next], packed[pos]);
-                sparse[page(packed[pos])][offset(packed[pos])] = traits_type::construct(static_cast<const typename traits_type::entity_type>(pos));
-                *it = traits_type::construct(static_cast<typename traits_type::entity_type>(next));
+                sparse[page(packed[pos])][offset(packed[pos])] = entity_traits::construct(static_cast<const typename entity_traits::entity_type>(pos));
+                *it = entity_traits::construct(static_cast<typename entity_traits::entity_type>(next));
                 for(; next && packed[next - 1u] == tombstone; --next);
             }
         }
@@ -724,8 +724,8 @@ public:
         auto &entt = sparse[page(lhs)][offset(lhs)];
         auto &other = sparse[page(rhs)][offset(rhs)];
 
-        const auto from = static_cast<size_type>(traits_type::to_entity(entt));
-        const auto to = static_cast<size_type>(traits_type::to_entity(other));
+        const auto from = static_cast<size_type>(entity_traits::to_entity(entt));
+        const auto to = static_cast<size_type>(entity_traits::to_entity(other));
 
         // basic no-leak guarantee (with invalid state) if swapping throws
         swap_at(from, to);
@@ -780,7 +780,7 @@ public:
                 const auto entt = packed[curr];
 
                 swap_at(next, idx);
-                sparse[page(entt)][offset(entt)] = traits_type::construct(static_cast<typename traits_type::entity_type>(curr));
+                sparse[page(entt)][offset(entt)] = entity_traits::construct(static_cast<typename entity_traits::entity_type>(curr));
                 curr = std::exchange(next, idx);
             }
         }