diff --git a/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h b/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h index aa3a1c903433d233747287cf9218e5a8b70d2e35..f4d0b530f43afcfa7f7aeba95389bdb8a5371918 100644 --- a/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h +++ b/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h @@ -284,7 +284,8 @@ namespace armarx::armem::base /// Move and insert a provider segment. ProviderSegmentT& addProviderSegment(ProviderSegmentT&& providerSegment) { - return this->_derived().addProviderSegment(providerSegment.name(), std::move(providerSegment)); + const std::string name = providerSegment.name(); // Copy before move. + return this->_derived().addProviderSegment(name, std::move(providerSegment)); } /// Insert a provider segment in-place. diff --git a/source/RobotAPI/libraries/armem/core/base/EntityBase.h b/source/RobotAPI/libraries/armem/core/base/EntityBase.h index ce366164faff3df80e71fb4d0ba2114b35bcf385..ca9fdd8d63babff5ed51f7b731966b3ee91829df 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntityBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntityBase.h @@ -529,26 +529,33 @@ namespace armarx::armem::base }); } - /** - * @brief Add a single snapshot with data. - * @param snapshot The snapshot. - * @return The stored snapshot. - */ + + /// Add a snapshot at the given time. + EntitySnapshotT& addSnapshot(const Time& timestamp) + { + return this->addSnapshot(timestamp, EntitySnapshotT(timestamp)); + } + + /// Copy and insert a snapshot EntitySnapshotT& addSnapshot(const EntitySnapshotT& snapshot) { - return addSnapshot(EntitySnapshotT(snapshot)); + return this->addSnapshot(snapshot.time(), EntitySnapshotT(snapshot)); } + /// Move and insert a snapshot EntitySnapshotT& addSnapshot(EntitySnapshotT&& snapshot) { - auto it = this->_container.emplace_hint(this->_container.end(), snapshot.time(), std::move(snapshot)); - it->second.id().setEntityID(this->id()); - return it->second; + Time timestamp = snapshot.time(); // Copy before move. + return this->addSnapshot(timestamp, std::move(snapshot)); } - EntitySnapshotT& addSnapshot(const Time& timestamp) + /// Insert a snapshot in-place. + template <class ...Args> + EntitySnapshotT& addSnapshot(const Time& timestamp, Args... args) { - return addSnapshot(EntitySnapshotT(timestamp, this->id())); + auto it = this->_container.emplace_hint(this->_container.end(), timestamp, args...); + it->second.id() = this->id().withTimestamp(timestamp); + return it->second; } diff --git a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h index e73db7d84b1b09c12ff435d727aea49d780c5ef3..e1729bbcd90cc6062e93b8e62ed8db29e3bb4387 100644 --- a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h +++ b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h @@ -223,7 +223,8 @@ namespace armarx::armem::base /// Move and insert a core segment. CoreSegmentT& addCoreSegment(CoreSegmentT&& coreSegment) { - return this->_derived().addCoreSegment(coreSegment.name(), std::move(coreSegment)); + const std::string name = coreSegment.name(); // Copy before move. + return this->_derived().addCoreSegment(name, std::move(coreSegment)); } /// Move and insert a core segment. diff --git a/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h b/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h index ba9b091a3c00653c2a80298461e58bdd2e39d998..6a5497444c9e5959ac7d59300e1bc99e0fac2018 100644 --- a/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h +++ b/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h @@ -231,8 +231,6 @@ namespace armarx::armem::base void append(const DerivedT& m) { - // ARMARX_INFO << "ProviderSegment: Merge name '" << m.name() << "' into '" << name() << "'"; - m.forEachEntity([this](const EntityT & entity) { auto it = this->_container.find(entity.name()); @@ -261,7 +259,8 @@ namespace armarx::armem::base /// Move and insert an entity. EntityT& addEntity(EntityT&& entity) { - return this->_derived().addEntity(entity.name(), std::move(entity)); + const std::string name = entity.name(); // Copy before move. + return this->_derived().addEntity(name, std::move(entity)); } /// Insert an entity in-place. @@ -278,7 +277,6 @@ namespace armarx::armem::base bool equalsDeep(const DerivedT& other) const { - //std::cout << "ProviderSegment::equalsDeep" << std::endl; if (this->size() != other.size()) { return false;