diff --git a/include/ignition/gazebo/Types.hh b/include/ignition/gazebo/Types.hh index ee0a75e106..d30ae00d06 100644 --- a/include/ignition/gazebo/Types.hh +++ b/include/ignition/gazebo/Types.hh @@ -22,6 +22,8 @@ #include #include +#include "ignition/gazebo/Entity.hh" + namespace ignition { namespace gazebo @@ -89,10 +91,10 @@ namespace ignition /// \brief A key that uniquely identifies, at the global scope, a component /// instance - /// \note On version 6, the 2nd element equals the entity ID. + /// \note On version 6, the 2nd element was changed to the entity ID. /// \deprecated Deprecated on version 6, removed on version 7. Use /// ComponentTypeId + Entity instead. - using ComponentKey = std::pair; + using ComponentKey = std::pair; /// \brief typedef for query callbacks using EntityQueryCallback = std::function #include "ignition/gazebo/components/Component.hh" #include "ignition/gazebo/components/Factory.hh" -#include "ignition/gazebo/detail/EntityStorage.hh" +#include "ignition/gazebo/detail/EntityComponentStorage.hh" #include "ignition/gazebo/EntityComponentManager.hh" using namespace ignition; @@ -78,7 +78,7 @@ class ignition::gazebo::EntityComponentManagerPrivate /// \brief A class that stores all components and maps entities to their /// component types - public: detail::EntityStorage entityStorage; + public: detail::EntityComponentStorage entityStorage; /// \brief All component types that have ever been created. public: std::unordered_set createdCompTypes; diff --git a/src/EntityStorage.cc b/src/EntityComponentStorage.cc similarity index 87% rename from src/EntityStorage.cc rename to src/EntityComponentStorage.cc index 51c694eff2..495441342e 100644 --- a/src/EntityStorage.cc +++ b/src/EntityComponentStorage.cc @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "ignition/gazebo/detail/EntityStorage.hh" +#include "ignition/gazebo/detail/EntityComponentStorage.hh" #include #include @@ -30,14 +30,14 @@ using namespace gazebo; using namespace detail; ////////////////////////////////////////////////// -void EntityStorage::Reset() +void EntityComponentStorage::Reset() { this->entityComponents.clear(); this->componentTypeIndex.clear(); } ////////////////////////////////////////////////// -bool EntityStorage::AddEntity(const Entity _entity) +bool EntityComponentStorage::AddEntity(const Entity _entity) { const auto [it, success] = this->entityComponents.insert({_entity, std::vector>()}); @@ -51,7 +51,7 @@ bool EntityStorage::AddEntity(const Entity _entity) } ////////////////////////////////////////////////// -bool EntityStorage::RemoveEntity(const Entity _entity) +bool EntityComponentStorage::RemoveEntity(const Entity _entity) { const auto removedComponents = this->entityComponents.erase(_entity); const auto removedTypeIdxMap = this->componentTypeIndex.erase(_entity); @@ -59,7 +59,7 @@ bool EntityStorage::RemoveEntity(const Entity _entity) } ////////////////////////////////////////////////// -ComponentAdditionResult EntityStorage::AddComponent( +ComponentAdditionResult EntityComponentStorage::AddComponent( const Entity _entity, std::unique_ptr _component) { @@ -101,7 +101,7 @@ ComponentAdditionResult EntityStorage::AddComponent( } ////////////////////////////////////////////////// -bool EntityStorage::RemoveComponent(const Entity _entity, +bool EntityComponentStorage::RemoveComponent(const Entity _entity, const ComponentTypeId _typeId) { auto compPtr = this->Component(_entity, _typeId); @@ -116,7 +116,7 @@ bool EntityStorage::RemoveComponent(const Entity _entity, } ////////////////////////////////////////////////// -const components::BaseComponent *EntityStorage::Component( +const components::BaseComponent *EntityComponentStorage::Component( const Entity _entity, const ComponentTypeId _typeId) const { @@ -144,15 +144,16 @@ const components::BaseComponent *EntityStorage::Component( } ////////////////////////////////////////////////// -components::BaseComponent *EntityStorage::Component(const Entity _entity, - const ComponentTypeId _typeId) +components::BaseComponent *EntityComponentStorage::Component( + const Entity _entity, const ComponentTypeId _typeId) { return const_cast( - static_cast(*this).Component(_entity, _typeId)); + static_cast(*this).Component(_entity, + _typeId)); } ////////////////////////////////////////////////// -const components::BaseComponent *EntityStorage::ValidComponent( +const components::BaseComponent *EntityComponentStorage::ValidComponent( const Entity _entity, const ComponentTypeId _typeId) const { auto compPtr = this->Component(_entity, _typeId); @@ -162,7 +163,7 @@ const components::BaseComponent *EntityStorage::ValidComponent( } ////////////////////////////////////////////////// -components::BaseComponent *EntityStorage::ValidComponent( +components::BaseComponent *EntityComponentStorage::ValidComponent( const Entity _entity, const ComponentTypeId _typeId) { auto compPtr = this->Component(_entity, _typeId); diff --git a/src/EntityStorage_TEST.cc b/src/EntityComponentStorage_TEST.cc similarity index 93% rename from src/EntityStorage_TEST.cc rename to src/EntityComponentStorage_TEST.cc index 0f4d8c12e8..28a69f7c00 100644 --- a/src/EntityStorage_TEST.cc +++ b/src/EntityComponentStorage_TEST.cc @@ -26,7 +26,7 @@ #include "ignition/gazebo/components/Factory.hh" #include "ignition/gazebo/components/LinearVelocity.hh" #include "ignition/gazebo/components/Pose.hh" -#include "ignition/gazebo/detail/EntityStorage.hh" +#include "ignition/gazebo/detail/EntityComponentStorage.hh" using namespace ignition; using namespace gazebo; @@ -42,7 +42,7 @@ const Entity entity3 = 3; const Entity entity4 = 4; ///////////////////////////////////////////////// -class EntityStorageTest : public ::testing::Test +class EntityComponentStorageTest : public ::testing::Test { // Documentation inherited protected: void SetUp() override @@ -65,7 +65,7 @@ class EntityStorageTest : public ::testing::Test return this->storage.AddComponent(_entity, std::move(compPtr)); } - /// \brief Helper function that uses EntityStorage::ValidComponent to get + /// \brief Helper function that uses EntityComponentStorage::ValidComponent to get /// a component of a particular type that belongs to an entity. /// \param[in] _entity The entity /// \return A pointer to the component of the templated type. If no such @@ -87,7 +87,7 @@ class EntityStorageTest : public ::testing::Test return static_cast(baseComp); } - public: detail::EntityStorage storage; + public: detail::EntityComponentStorage storage; public: const Entity e1{1}; @@ -95,7 +95,7 @@ class EntityStorageTest : public ::testing::Test }; ///////////////////////////////////////////////// -TEST_F(EntityStorageTest, AddEntity) +TEST_F(EntityComponentStorageTest, AddEntity) { // Entities were already added to the storage in the test fixture's SetUp // method. So, try to add entities that are already in the storage. @@ -109,7 +109,7 @@ TEST_F(EntityStorageTest, AddEntity) } ///////////////////////////////////////////////// -TEST_F(EntityStorageTest, RemoveEntity) +TEST_F(EntityComponentStorageTest, RemoveEntity) { // Try to remove entities that aren't in the storage EXPECT_FALSE(this->storage.RemoveEntity(3)); @@ -125,7 +125,7 @@ TEST_F(EntityStorageTest, RemoveEntity) } ///////////////////////////////////////////////// -TEST_F(EntityStorageTest, AddComponent) +TEST_F(EntityComponentStorageTest, AddComponent) { // Add components to entities in the storage EXPECT_EQ(detail::ComponentAdditionResult::NEW_ADDITION, @@ -166,8 +166,8 @@ TEST_F(EntityStorageTest, AddComponent) &linVelComp2)); // We can't check if the modification actually took place since this requires - // functionality beyond the EntityStorage API (see the comments in the - // EntityStorage::AddComponent method definition for more details), but we + // functionality beyond the EntityComponentStorage API (see the comments in the + // EntityComponentStorage::AddComponent method definition for more details), but we // can at least check that the components still exist after modification ASSERT_NE(nullptr, this->Component(this->e1)); ASSERT_NE(nullptr, this->Component(this->e2)); @@ -195,7 +195,7 @@ TEST_F(EntityStorageTest, AddComponent) } ///////////////////////////////////////////////// -TEST_F(EntityStorageTest, RemoveComponent) +TEST_F(EntityComponentStorageTest, RemoveComponent) { // Add components to entities EXPECT_EQ(detail::ComponentAdditionResult::NEW_ADDITION, @@ -231,7 +231,7 @@ TEST_F(EntityStorageTest, RemoveComponent) } ///////////////////////////////////////////////// -TEST_F(EntityStorageTest, ValidComponent) +TEST_F(EntityComponentStorageTest, ValidComponent) { // Attach a component to an entity EXPECT_EQ(detail::ComponentAdditionResult::NEW_ADDITION, @@ -260,9 +260,9 @@ TEST_F(EntityStorageTest, ValidComponent) ///////////////////////////////////////////////// // Similar to the ValidComponent test, but this test covers the const version of -// the EntityStorage::ValidComponent method (the ValidComponent test covered -// the non-const version of the EntityStorage::ValidComponent) -TEST_F(EntityStorageTest, ValidComponentConst) +// the EntityComponentStorage::ValidComponent method (the ValidComponent test covered +// the non-const version of the EntityComponentStorage::ValidComponent) +TEST_F(EntityComponentStorageTest, ValidComponentConst) { // Attach a component to an entity EXPECT_EQ(detail::ComponentAdditionResult::NEW_ADDITION, @@ -285,7 +285,7 @@ TEST_F(EntityStorageTest, ValidComponentConst) } ///////////////////////////////////////////////// -TEST_F(EntityStorageTest, Reset) +TEST_F(EntityComponentStorageTest, Reset) { // Add components to entities in the storage EXPECT_EQ(detail::ComponentAdditionResult::NEW_ADDITION, diff --git a/test/integration/view.cc b/test/integration/view.cc index d9661d939c..f01cf9e3d0 100644 --- a/test/integration/view.cc +++ b/test/integration/view.cc @@ -28,7 +28,7 @@ #include "ignition/gazebo/Entity.hh" #include "ignition/gazebo/Types.hh" #include "ignition/gazebo/detail/View.hh" -#include "ignition/gazebo/detail/EntityStorage.hh" +#include "ignition/gazebo/detail/EntityComponentStorage.hh" #include "ignition/gazebo/components/Component.hh" #include "ignition/gazebo/components/Factory.hh" #include "ignition/gazebo/components/Model.hh" @@ -62,7 +62,7 @@ class ViewTest : public::testing::Test } }; -/// \brief Helper class that wraps EntityStorage to provide a simplified +/// \brief Helper class that wraps EntityComponentStorage to provide a simplified /// API for working with entities and their components. This class also stores /// a set of user-defined views and handles updating views as needed whenever /// an entity's components are modified. @@ -187,7 +187,7 @@ class StorageViewWrapper EXPECT_EQ(entityComp->Data(), _component.Data()); } - /// \brief Helper function that uses EntityStorage::ValidComponent to get + /// \brief Helper function that uses EntityComponentStorage::ValidComponent to get /// a component of a particular type that belongs to an entity. /// \param[in] _entity The entity /// \return A pointer to the component of the templated type. If no such @@ -230,8 +230,8 @@ class StorageViewWrapper return this->storage.AddComponent(_entity, std::move(compPtr)); } - /// \brief The actual detail::EntityStorage instance - private: detail::EntityStorage storage; + /// \brief The actual detail::EntityComponentStorage instance + private: detail::EntityComponentStorage storage; /// \brief All of the views that will be updated as needed based on the /// changes being made to this->storage