Преглед изворни кода

sparse_set: ::get -> ::value (to avoid hiding from derived classes)

Michele Caini пре 3 година
родитељ
комит
fde1a524ea

+ 3 - 3
docs/md/entity.md

@@ -1110,10 +1110,10 @@ passed to it every time.
 Alongside these more specific things, there are also a couple of functions
 designed to address some common requirements such as copying an entity.<br/>
 In particular, the base class behind a storage offers the possibility to _take_
-the object associated with an entity through an opaque pointer:
+the value associated with an entity through an opaque pointer:
 
 ```cpp
-const void *instance = base.get(entity);
+const void *instance = base.value(entity);
 ```
 
 Similarly, the non-specialized `push` function accepts an optional opaque
@@ -1133,7 +1133,7 @@ them by copy if needed:
 // create a copy of an entity component by component
 for(auto &&curr: registry.storage()) {
     if(auto &storage = curr.second; storage.contains(src)) {
-        storage.push(dst, storage.get(src));
+        storage.push(dst, storage.value(src));
     }
 }
 ```

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

@@ -357,14 +357,14 @@ public:
     /**
      * @brief Constructs an empty container with the given value type, policy
      * and allocator.
-     * @param value Returned value type, if any.
+     * @param elem Returned value type, if any.
      * @param pol Type of deletion policy.
      * @param allocator The allocator to use (possibly default-constructed).
      */
-    explicit basic_sparse_set(const type_info &value, deletion_policy pol = deletion_policy::swap_and_pop, const allocator_type &allocator = {})
+    explicit basic_sparse_set(const type_info &elem, deletion_policy pol = deletion_policy::swap_and_pop, const allocator_type &allocator = {})
         : sparse{allocator},
           packed{allocator},
-          info{&value},
+          info{&elem},
           free_list{tombstone},
           mode{pol} {}
 
@@ -668,13 +668,13 @@ public:
      * @param entt A valid identifier.
      * @return An opaque pointer to the element assigned to the entity, if any.
      */
-    [[nodiscard]] const void *get(const entity_type entt) const noexcept {
+    [[nodiscard]] const void *value(const entity_type entt) const noexcept {
         return get_at(index(entt));
     }
 
-    /*! @copydoc get */
-    [[nodiscard]] void *get(const entity_type entt) noexcept {
-        return const_cast<void *>(std::as_const(*this).get(entt));
+    /*! @copydoc value */
+    [[nodiscard]] void *value(const entity_type entt) noexcept {
+        return const_cast<void *>(std::as_const(*this).value(entt));
     }
 
     /**
@@ -685,12 +685,12 @@ public:
      * results in undefined behavior.
      *
      * @param entt A valid identifier.
-     * @param value Optional opaque value to forward to mixins, if any.
+     * @param elem Optional opaque element to forward to mixins, if any.
      * @return Iterator pointing to the emplaced element in case of success, the
      * `end()` iterator otherwise.
      */
-    iterator push(const entity_type entt, const void *value = nullptr) {
-        return try_emplace(entt, false, value);
+    iterator push(const entity_type entt, const void *elem = nullptr) {
+        return try_emplace(entt, false, elem);
     }
 
     /**

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

@@ -48,7 +48,7 @@ TEST(SparseSet, Functionalities) {
     ASSERT_EQ(set.at(0u), entt::entity{42});
     ASSERT_EQ(set.at(1u), static_cast<entt::entity>(entt::null));
     ASSERT_EQ(set[0u], entt::entity{42});
-    ASSERT_EQ(set.get(entt::entity{42}), nullptr);
+    ASSERT_EQ(set.value(entt::entity{42}), nullptr);
 
     set.erase(entt::entity{42});
 

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

@@ -671,7 +671,7 @@ TEST(Storage, TypeFromBase) {
 
     ASSERT_TRUE(pool.contains(entities[0u]));
     ASSERT_FALSE(pool.contains(entities[1u]));
-    ASSERT_EQ(base.get(entities[0u]), &pool.get(entities[0u]));
+    ASSERT_EQ(base.value(entities[0u]), &pool.get(entities[0u]));
     ASSERT_EQ(pool.get(entities[0u]), 42);
 
     base.erase(entities[0u]);
@@ -706,7 +706,7 @@ TEST(Storage, EmptyTypeFromBase) {
     ASSERT_EQ(pool.size(), 1u);
     ASSERT_TRUE(pool.contains(entities[0u]));
     ASSERT_FALSE(pool.contains(entities[1u]));
-    ASSERT_EQ(base.get(entities[0u]), nullptr);
+    ASSERT_EQ(base.value(entities[0u]), nullptr);
     ASSERT_EQ(base.index(entities[0u]), 0u);
 
     base.erase(entities[0u]);

+ 2 - 2
test/example/entity_copy.cpp

@@ -28,7 +28,7 @@ TEST(Example, EntityCopy) {
     for(auto [id, storage]: registry.storage()) {
         // discard the custom storage because why not, this is just an example after all
         if(id != "custom"_hs && storage.contains(src)) {
-            storage.push(dst, storage.get(src));
+            storage.push(dst, storage.value(src));
         }
     }
 
@@ -67,7 +67,7 @@ TEST(Example, DifferentRegistryTypes) {
 
     for(auto [id, storage]: src.storage()) {
         if(auto *other = dst.storage(id); other && storage.contains(entity)) {
-            other->push(copy, storage.get(entity));
+            other->push(copy, storage.value(entity));
         }
     }