From b4f4358d4d4c8ca8798c011c23793400783cfe39 Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Wed, 22 Sep 2021 16:44:18 +0200
Subject: [PATCH] Make append() work between wm and server::wm classes

---
 .../libraries/armem/core/base/CoreSegmentBase.h       |  7 +++----
 .../RobotAPI/libraries/armem/core/base/EntityBase.h   | 11 +++++------
 .../RobotAPI/libraries/armem/core/base/MemoryBase.h   |  7 +++----
 .../libraries/armem/core/base/ProviderSegmentBase.h   |  6 ++++--
 4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h b/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h
index f4d0b530f..4f63c6f3a 100644
--- a/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h
+++ b/source/RobotAPI/libraries/armem/core/base/CoreSegmentBase.h
@@ -247,11 +247,10 @@ namespace armarx::armem::base
         }
 
 
-        void append(const _Derived& m)
+        template <class OtherDerivedT>
+        void append(const OtherDerivedT& other)
         {
-            // ARMARX_INFO << "CoreSegment: Merge name '" << m.name() << "' into '" << name() << "'";
-
-            m.forEachProviderSegment([this](const ProviderSegmentT & provSeg)
+            other.forEachProviderSegment([this](const auto& provSeg)
             {
                 auto it = this->_container.find(provSeg.name());
                 if (it == this->_container.end())
diff --git a/source/RobotAPI/libraries/armem/core/base/EntityBase.h b/source/RobotAPI/libraries/armem/core/base/EntityBase.h
index f45018ff9..30c58aeca 100644
--- a/source/RobotAPI/libraries/armem/core/base/EntityBase.h
+++ b/source/RobotAPI/libraries/armem/core/base/EntityBase.h
@@ -535,20 +535,19 @@ namespace armarx::armem::base
         }
 
 
-        void append(const DerivedT& m)
+        template <class OtherDerivedT>
+        void append(const OtherDerivedT& other)
         {
-            // ARMARX_INFO << "Entity: Merge name '" << m.name() << "' into '" << name() << "'";
-
-            m.forEachSnapshot([this](const EntitySnapshotT & snapshot)
+            other.forEachSnapshot([this](const auto& snapshot)
             {
                 auto it = this->_container.find(snapshot.time());
                 if (it == this->_container.end())
                 {
                     EntitySnapshotT copy { snapshot };
-                    copy.id() = this->id().withTimestamp(snapshot.time()); // update id (e.g. memory name) if necessary
+                    copy.id() = this->id().withTimestamp(snapshot.time());  // update id (e.g. memory name) if necessary
                     this->_container.emplace(snapshot.time(), copy);
                 }
-                // else: segment already exists
+                // else: snapshot already exists
                 // We assume that a snapshot does not change, so ignore
                 return true;
             });
diff --git a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h
index e1729bbcd..2d28474e2 100644
--- a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h
+++ b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h
@@ -281,11 +281,10 @@ namespace armarx::armem::base
          * @brief Merge another memory into this one. Append all data
          * @param m The other memory
          */
-        void append(const _Derived& m)
+        template <class OtherDerivedT>
+        void append(const OtherDerivedT& other)
         {
-            // ARMARX_INFO << "Memory: Merge name '" << m.name() << "' into '" << name() << "'";
-
-            m.forEachCoreSegment([this](const CoreSegmentT & coreSeg)
+            other.forEachCoreSegment([this](const auto& coreSeg)
             {
                 auto it = this->_container.find(coreSeg.name());
                 if (it == this->_container.end())
diff --git a/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h b/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h
index 6a5497444..a2a9f2a8c 100644
--- a/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h
+++ b/source/RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h
@@ -229,9 +229,11 @@ namespace armarx::armem::base
             return ret;
         }
 
-        void append(const DerivedT& m)
+
+        template <class OtherDerivedT>
+        void append(const OtherDerivedT& other)
         {
-            m.forEachEntity([this](const EntityT & entity)
+            other.forEachEntity([this](const auto& entity)
             {
                 auto it = this->_container.find(entity.name());
                 if (it == this->_container.end())
-- 
GitLab