From 212d0e116d72b062ec448c83f76729daa046fd24 Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@kit.edu> Date: Thu, 5 Aug 2021 08:41:48 +0200 Subject: [PATCH] Add getFirstSnapshot() --- .../libraries/armem/core/base/EntityBase.h | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/source/RobotAPI/libraries/armem/core/base/EntityBase.h b/source/RobotAPI/libraries/armem/core/base/EntityBase.h index f28f12b7b..57dd4dad2 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(); + } + + }; } -- GitLab