From d3347a521d7461c5b5bae7243344189a680ff68a Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Mon, 12 Jul 2021 09:28:39 +0200
Subject: [PATCH] Properly use typedefs

---
 .../libraries/armem/core/base/EntityBase.h    | 26 ++++++++++---------
 .../armem/core/longtermmemory/Entity.cpp      |  5 ++--
 .../armem/core/longtermmemory/Entity.h        |  2 +-
 3 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/source/RobotAPI/libraries/armem/core/base/EntityBase.h b/source/RobotAPI/libraries/armem/core/base/EntityBase.h
index ab227c33e..0775a71f9 100644
--- a/source/RobotAPI/libraries/armem/core/base/EntityBase.h
+++ b/source/RobotAPI/libraries/armem/core/base/EntityBase.h
@@ -114,13 +114,13 @@ namespace armarx::armem::base
         }
 
 
-        inline const std::map<Time, EntitySnapshotT>& history() const
+        inline const ContainerT& history() const
         {
             return this->_container;
         }
-        inline std::map<Time, EntitySnapshotT>& history()
+        inline ContainerT& history()
         {
-            return const_cast<std::map<Time, EntitySnapshotT>&>(const_cast<const EntityBase*>(this)->history());
+            return const_cast<ContainerT&>(const_cast<const EntityBase*>(this)->history());
         }
 
 
@@ -226,7 +226,7 @@ namespace armarx::armem::base
         virtual const EntitySnapshotT& getLatestSnapshotBeforeOrAt(const Time& time) const
         {
             // first element equal or greater
-            typename std::map<Time, EntitySnapshotT>::const_iterator refIt = this->_container.upper_bound(time);
+            typename ContainerT::const_iterator refIt = this->_container.upper_bound(time);
 
             if (refIt == this->_container.begin())
             {
@@ -238,7 +238,7 @@ namespace armarx::armem::base
             }
 
             // last element less than
-            typename std::map<Time, EntitySnapshotT>::const_iterator refItPrev = std::prev(refIt);
+            typename ContainerT::const_iterator refItPrev = std::prev(refIt);
 
             // ... or we return the element before if possible
             if (refItPrev != this->_container.begin())
@@ -259,7 +259,7 @@ namespace armarx::armem::base
         virtual const EntitySnapshotT& getLatestSnapshotBefore(const Time& time) const
         {
             // first element equal or greater
-            typename std::map<Time, EntitySnapshotT>::const_iterator refIt = this->_container.upper_bound(time);
+            typename ContainerT::const_iterator refIt = this->_container.upper_bound(time);
 
             if (refIt == this->_container.begin())
             {
@@ -267,7 +267,7 @@ namespace armarx::armem::base
             }
 
             // last element less than
-            typename std::map<Time, EntitySnapshotT>::const_iterator refItPrev = std::prev(refIt);
+            typename ContainerT::const_iterator refItPrev = std::prev(refIt);
 
             // we return the element before if possible
             if (refItPrev != this->_container.begin())
@@ -311,7 +311,7 @@ namespace armarx::armem::base
         virtual const EntitySnapshotT& getFirstSnapshotAfterOrAt(const Time& time) const
         {
             // first element equal or greater
-            typename std::map<Time, EntitySnapshotT>::const_iterator refIt = this->_container.upper_bound(time);
+            typename ContainerT::const_iterator refIt = this->_container.upper_bound(time);
 
             if (refIt == this->_container.end())
             {
@@ -330,7 +330,7 @@ namespace armarx::armem::base
         virtual const EntitySnapshotT& getFirstSnapshotAfter(const Time& time) const
         {
             // first element equal or greater
-            typename std::map<Time, EntitySnapshotT>::const_iterator refIt = this->_container.upper_bound(time);
+            typename ContainerT::const_iterator refIt = this->_container.upper_bound(time);
 
             if (refIt == this->_container.end())
             {
@@ -343,7 +343,7 @@ namespace armarx::armem::base
             }
 
             // first element greater than
-            typename std::map<Time, EntitySnapshotT>::const_iterator refItNext = std::next(refIt);
+            typename ContainerT::const_iterator refItNext = std::next(refIt);
 
             if (refItNext != this->_container.end())
             {
@@ -418,7 +418,7 @@ namespace armarx::armem::base
 
         EntitySnapshotT& addSnapshot(EntitySnapshotT&& snapshot)
         {
-            auto it = this->_container.emplace(snapshot.time(), std::move(snapshot)).first;
+            auto it = this->_container.emplace_hint(this->_container.end(), snapshot.time(), std::move(snapshot));
             it->second.id().setEntityID(this->id());
             return it->second;
         }
@@ -473,7 +473,9 @@ namespace armarx::armem::base
          * @return The latest snapshot.
          * @throw `armem::error::EntityHistoryEmpty` If the history is empty.
          */
-        virtual const typename std::map<Time, EntitySnapshotT>::value_type& getLatestItem() const
+        virtual
+        const typename ContainerT::value_type&
+        getLatestItem() const
         {
             if (this->_container.empty())
             {
diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp
index 3865e6df0..a3c3b2e89 100644
--- a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp
+++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.cpp
@@ -1,5 +1,6 @@
 #include "Entity.h"
 
+
 namespace armarx::armem::ltm
 {
 
@@ -106,7 +107,7 @@ namespace armarx::armem::ltm
             snapshot.addInstance(instance);
         }
 
-        _container.insert({time, snapshot});
+        _container.emplace(time, snapshot);
         //truncateHistoryToSize();
         return true;
     }
@@ -142,7 +143,7 @@ namespace armarx::armem::ltm
         return Base::getSnapshot(time);
     }
 
-    const std::map<Time, EntitySnapshot>::value_type& Entity::getLatestItem() const
+    auto Entity::getLatestItem() const -> const ContainerT::value_type&
     {
         // Directly query mongodb (cache cant know whether it is the latest or not)
         // TODO
diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h
index a5bca08c7..20377befd 100644
--- a/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h
+++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Entity.h
@@ -71,7 +71,7 @@ namespace armarx::armem::ltm
 
     protected:
         // virtual overrides for LTM storage
-        virtual const std::map<Time, EntitySnapshot>::value_type& getLatestItem() const override;
+        virtual const ContainerT::value_type& getLatestItem() const override;
 
     public:
         MongoDBConnectionManager::MongoDBSettings dbsettings;
-- 
GitLab