diff --git a/source/RobotAPI/libraries/armem/core/base/EntityBase.h b/source/RobotAPI/libraries/armem/core/base/EntityBase.h index f28f12b7be82e7c594c9306f6fa5e24b5decdd42..57dd4dad21c9702187f7aaf4a515bef0f567d0ca 100644 --- a/source/RobotAPI/libraries/armem/core/base/EntityBase.h +++ b/source/RobotAPI/libraries/armem/core/base/EntityBase.h @@ -178,12 +178,25 @@ namespace armarx::armem::base { return const_cast<EntitySnapshotT&>(const_cast<const EntityBase*>(this)->getLatestSnapshot()); } - const EntitySnapshotT& getLatestSnapshot() const { return getLatestItem().second; } + /** + * @brief Return the snapshot with the most recent timestamp. + * @return The latest snapshot. + * @throw `armem::error::EntityHistoryEmpty` If the history is empty. + */ + EntitySnapshotT& getFirstSnapshot() + { + return const_cast<EntitySnapshotT&>(const_cast<const EntityBase*>(this)->getFirstSnapshot()); + } + const EntitySnapshotT& getFirstSnapshot() const + { + return getFirstItem().second; + } + /** * @brief Return the lastest snapshot before time. @@ -541,6 +554,23 @@ namespace armarx::armem::base return *this->_container.rbegin(); } + /** + * @brief Return the snapshot with the least recent timestamp. + * @return The first snapshot. + * @throw `armem::error::EntityHistoryEmpty` If the history is empty. + */ + virtual + const typename ContainerT::value_type& + getFirstItem() const + { + if (this->_container.empty()) + { + throw armem::error::EntityHistoryEmpty(name(), "when getting the first snapshot."); + } + return *this->_container.begin(); + } + + }; }