From fde1a524ea13173f2a3a853353ed9118ab87c9e6 Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Thu, 22 Dec 2022 13:10:57 +0100 Subject: [PATCH] sparse_set: ::get -> ::value (to avoid hiding from derived classes) --- docs/md/entity.md | 6 +++--- src/entt/entity/sparse_set.hpp | 20 ++++++++++---------- test/entt/entity/sparse_set.cpp | 2 +- test/entt/entity/storage.cpp | 4 ++-- test/example/entity_copy.cpp | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/md/entity.md b/docs/md/entity.md index 522ce6e3b..d43d054e3 100644 --- a/docs/md/entity.md +++ b/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.
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)); } } ``` diff --git a/src/entt/entity/sparse_set.hpp b/src/entt/entity/sparse_set.hpp index f88755a49..dafb70e8e 100644 --- a/src/entt/entity/sparse_set.hpp +++ b/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(std::as_const(*this).get(entt)); + /*! @copydoc value */ + [[nodiscard]] void *value(const entity_type entt) noexcept { + return const_cast(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); } /** diff --git a/test/entt/entity/sparse_set.cpp b/test/entt/entity/sparse_set.cpp index a7bd21386..eb320c399 100644 --- a/test/entt/entity/sparse_set.cpp +++ b/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::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}); diff --git a/test/entt/entity/storage.cpp b/test/entt/entity/storage.cpp index cc2981b65..80f7dfa9d 100644 --- a/test/entt/entity/storage.cpp +++ b/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]); diff --git a/test/example/entity_copy.cpp b/test/example/entity_copy.cpp index 3071d11a9..b1c19088b 100644 --- a/test/example/entity_copy.cpp +++ b/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)); } }