From b79fcce1ffb6f66b40fa588be6004954e03a5789 Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Thu, 5 Aug 2021 07:45:11 +0200
Subject: [PATCH] Remove functions and base class related to copyWithoutData()

---
 .../RobotAPI/libraries/armem/CMakeLists.txt   |  2 --
 .../armem/core/workingmemory/CoreSegment.cpp  | 16 ++++------
 .../armem/core/workingmemory/CoreSegment.h    |  7 ++---
 .../armem/core/workingmemory/Entity.cpp       | 10 +------
 .../armem/core/workingmemory/Entity.h         |  8 +----
 .../core/workingmemory/EntityInstance.cpp     |  7 -----
 .../armem/core/workingmemory/EntityInstance.h | 10 +------
 .../core/workingmemory/EntitySnapshot.cpp     |  8 -----
 .../armem/core/workingmemory/EntitySnapshot.h |  9 +-----
 .../armem/core/workingmemory/Memory.cpp       | 10 -------
 .../armem/core/workingmemory/Memory.h         |  9 +-----
 .../core/workingmemory/ProviderSegment.cpp    | 10 -------
 .../core/workingmemory/ProviderSegment.h      |  9 +-----
 .../workingmemory/detail/CopyWithoutData.cpp  |  1 -
 .../workingmemory/detail/CopyWithoutData.h    | 30 -------------------
 .../workingmemory/EntityQueryProcessor.cpp    |  8 ++++-
 16 files changed, 20 insertions(+), 134 deletions(-)
 delete mode 100644 source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.cpp
 delete mode 100644 source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.h

diff --git a/source/RobotAPI/libraries/armem/CMakeLists.txt b/source/RobotAPI/libraries/armem/CMakeLists.txt
index a5274706c..84a5e312a 100644
--- a/source/RobotAPI/libraries/armem/CMakeLists.txt
+++ b/source/RobotAPI/libraries/armem/CMakeLists.txt
@@ -47,7 +47,6 @@ set(LIB_FILES
     # core/base/ProviderSegmentBase.cpp
 
     core/workingmemory/ice_conversions.cpp
-    core/workingmemory/detail/CopyWithoutData.cpp
     core/workingmemory/CoreSegment.cpp
     core/workingmemory/Entity.cpp
     core/workingmemory/EntityInstance.cpp
@@ -166,7 +165,6 @@ set(LIB_HEADERS
     core/base/MemoryBase.h
     core/base/ProviderSegmentBase.h
 
-    core/workingmemory/detail/CopyWithoutData.h
     core/workingmemory/CoreSegment.h
     core/workingmemory/Entity.h
     core/workingmemory/EntityInstance.h
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp
index 8097ab717..7a3ef7efe 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.cpp
@@ -39,25 +39,19 @@ namespace armarx::armem::wm
     }
 
 
-    Commit CoreSegment::toCommit() const
+    CoreSegment::~CoreSegment()
     {
-        Commit c;
-        for (const auto& [k, s] : _container)
-        {
-            c.append(s.toCommit());
-        }
-        return c;
     }
 
 
-    void CoreSegment::_copySelfWithoutData(CoreSegment& other) const
+    Commit CoreSegment::toCommit() const
     {
-        other.id() = _id;
-        other.setMaxHistorySize(_maxHistorySize);
+        Commit c;
         for (const auto& [k, s] : _container)
         {
-            other.addProviderSegment(s.copyWithoutData());
+            c.append(s.toCommit());
         }
+        return c;
     }
 
 
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h
index 54df4ff40..7dff9a9ad 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/CoreSegment.h
@@ -6,7 +6,6 @@
 #include <RobotAPI/libraries/armem/core/base/CoreSegmentBase.h>
 
 #include "ProviderSegment.h"
-#include "detail/CopyWithoutData.h"
 
 
 namespace armarx::armem::wm
@@ -16,14 +15,14 @@ namespace armarx::armem::wm
      * @brief Data of a core segment containing multiple provider segments.
      */
     class CoreSegment :
-        public base::CoreSegmentBase<ProviderSegment, CoreSegment>,
-        public detail::CopyWithoutData<CoreSegment>
+        public base::CoreSegmentBase<ProviderSegment, CoreSegment>
     {
         using Base = base::CoreSegmentBase<ProviderSegment, CoreSegment>;
 
     public:
 
         using Base::CoreSegmentBase;
+        virtual ~CoreSegment() override;
 
         CoreSegment(const CoreSegment& other);
         CoreSegment(CoreSegment&& other);
@@ -102,8 +101,6 @@ namespace armarx::armem::wm
 
     protected:
 
-        virtual void _copySelfWithoutData(CoreSegment& other) const override;
-
         mutable std::mutex _mutex;
 
     };
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp
index e704e96d5..27661a6ce 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.cpp
@@ -1,5 +1,6 @@
 #include "Entity.h"
 
+
 namespace armarx::armem::wm
 {
 
@@ -16,13 +17,4 @@ namespace armarx::armem::wm
         return c;
     }
 
-    void Entity::_copySelfWithoutData(Entity& other) const
-    {
-        other.id() = _id;
-        other.setMaxHistorySize(_maxHistorySize);
-        for (const auto& [k, s] : _container)
-        {
-            other.addSnapshot(s.copyWithoutData());
-        }
-    }
 }
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.h b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.h
index d8e29a794..450a95c81 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/Entity.h
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/Entity.h
@@ -3,7 +3,6 @@
 #include <RobotAPI/libraries/armem/core/base/EntityBase.h>
 
 #include "EntitySnapshot.h"
-#include "detail/CopyWithoutData.h"
 
 
 namespace armarx::armem::wm
@@ -28,8 +27,7 @@ namespace armarx::armem::wm
      * each containing a single `AronData` object of a specific `AronType`.
      */
     class Entity :
-        public base::EntityBase<EntitySnapshot, Entity>,
-        public detail::CopyWithoutData<Entity>
+        public base::EntityBase<EntitySnapshot, Entity>
     {
         using Base = base::EntityBase<EntitySnapshot, Entity>;
 
@@ -48,10 +46,6 @@ namespace armarx::armem::wm
          */
         Commit toCommit() const;
 
-    protected:
-
-        virtual void _copySelfWithoutData(Entity& other) const override;
-
     };
 
 }
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp
index 0962f86fb..1be40a131 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.cpp
@@ -57,11 +57,4 @@ namespace armarx::armem::wm
         this->_metadata.timeArrived = update.timeArrived;
     }
 
-
-    void EntityInstance::_copySelfWithoutData(EntityInstance& other) const
-    {
-        other._id = _id;
-        other._metadata = _metadata;
-        // no: other._data = _data;
-    }
 }
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.h b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.h
index 06389c366..fbeb3f19f 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.h
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntityInstance.h
@@ -2,8 +2,6 @@
 
 #include <RobotAPI/libraries/armem/core/base/EntityInstanceBase.h>
 
-#include "detail/CopyWithoutData.h"
-
 
 namespace armarx::armem::wm
 {
@@ -42,8 +40,7 @@ namespace armarx::armem::wm
      * @brief Data of a single entity instance.
      */
     class EntityInstance :
-        public base::EntityInstanceBase<EntityInstance>,
-        public detail::CopyWithoutData<EntityInstance>
+        public base::EntityInstanceBase<EntityInstance>
     {
         using Base = base::EntityInstanceBase<EntityInstance>;
 
@@ -87,11 +84,6 @@ namespace armarx::armem::wm
         virtual bool equalsDeep(const EntityInstance& other) const override;
 
 
-    protected:
-
-        virtual void _copySelfWithoutData(EntityInstance& other) const override;
-
-
     private:
 
         /// The metadata.
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp
index 76d540013..5d7506a0f 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.cpp
@@ -17,12 +17,4 @@ namespace armarx::armem::wm
         return ret;
     }
 
-    void EntitySnapshot::_copySelfWithoutData(EntitySnapshot& other) const
-    {
-        other.id() = _id;
-        for (const auto& s : _container)
-        {
-            other.addInstance(s.copyWithoutData());
-        }
-    }
 }
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h
index 226fefd83..90b03d1ae 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/EntitySnapshot.h
@@ -3,7 +3,6 @@
 #include <RobotAPI/libraries/armem/core/base/EntitySnapshotBase.h>
 
 #include "EntityInstance.h"
-#include "detail/CopyWithoutData.h"
 
 
 namespace armarx::armem::wm
@@ -13,8 +12,7 @@ namespace armarx::armem::wm
      * @brief Data of an entity at one point in time.
      */
     class EntitySnapshot :
-        public base::EntitySnapshotBase<EntityInstance, EntitySnapshot>,
-        public detail::CopyWithoutData<EntitySnapshot>
+        public base::EntitySnapshotBase<EntityInstance, EntitySnapshot>
     {
         using Base = base::EntitySnapshotBase<EntityInstance, EntitySnapshot>;
 
@@ -31,10 +29,5 @@ namespace armarx::armem::wm
 
         std::vector<aron::datanavigator::DictNavigatorPtr> getAronData() const;
 
-
-    protected:
-
-        virtual void _copySelfWithoutData(EntitySnapshot& other) const override;
-
     };
 }
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp
index 70fd41e7c..c69a222b3 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp
@@ -82,14 +82,4 @@ namespace armarx::armem::wm
         return c;
     }
 
-
-    void Memory::_copySelfWithoutData(Memory& other) const
-    {
-        other.id() = _id;
-        for (const auto& [k, s] : _container)
-        {
-            other.addCoreSegment(s.copyWithoutData());
-        }
-    }
-
 }
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h
index d52bce5ca..b6595c83d 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h
@@ -3,7 +3,6 @@
 #include <RobotAPI/libraries/armem/core/base/MemoryBase.h>
 
 #include "CoreSegment.h"
-#include "detail/CopyWithoutData.h"
 
 
 namespace armarx::armem::wm
@@ -13,8 +12,7 @@ namespace armarx::armem::wm
      * @brief Data of a memory consisting of multiple core segments.
      */
     class Memory :
-        public base::MemoryBase<CoreSegment, Memory>,
-        public detail::CopyWithoutData<Memory>
+        public base::MemoryBase<CoreSegment, Memory>
     {
         using Base = base::MemoryBase<CoreSegment, Memory>;
 
@@ -47,10 +45,5 @@ namespace armarx::armem::wm
          */
         Commit toCommit() const;
 
-
-    protected:
-
-        virtual void _copySelfWithoutData(Memory& other) const override;
-
     };
 }
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp
index bd03cf21c..b67fa10f5 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.cpp
@@ -18,14 +18,4 @@ namespace armarx::armem::wm
         return c;
     }
 
-    void ProviderSegment::_copySelfWithoutData(ProviderSegment& other) const
-    {
-        other.id() = _id;
-        other.setMaxHistorySize(_maxHistorySize);
-        for (const auto& [k, s] : _container)
-        {
-            other.addEntity(s.copyWithoutData());
-        }
-    }
-
 }
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.h b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.h
index f3e708628..e837469d8 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.h
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/ProviderSegment.h
@@ -3,7 +3,6 @@
 #include <RobotAPI/libraries/armem/core/base/ProviderSegmentBase.h>
 
 #include "Entity.h"
-#include "detail/CopyWithoutData.h"
 
 
 namespace armarx::armem::wm
@@ -13,8 +12,7 @@ namespace armarx::armem::wm
      * @brief Data of a provider segment containing multiple entities.
      */
     class ProviderSegment :
-        public base::ProviderSegmentBase<Entity, ProviderSegment>,
-        public detail::CopyWithoutData<ProviderSegment>
+        public base::ProviderSegmentBase<Entity, ProviderSegment>
     {
         using Base = base::ProviderSegmentBase<Entity, ProviderSegment>;
 
@@ -33,11 +31,6 @@ namespace armarx::armem::wm
          */
         Commit toCommit() const;
 
-
-    protected:
-
-        virtual void _copySelfWithoutData(ProviderSegment& other) const override;
-
     };
 
 }
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.cpp
deleted file mode 100644
index 70441033d..000000000
--- a/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.cpp
+++ /dev/null
@@ -1 +0,0 @@
-#include "CopyWithoutData.h"
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.h b/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.h
deleted file mode 100644
index caabd1e60..000000000
--- a/source/RobotAPI/libraries/armem/core/workingmemory/detail/CopyWithoutData.h
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma once
-
-
-namespace armarx::armem::wm::detail
-{
-
-    /**
-     * @class Allows copying `*this` without data in the leaf
-     * data structures.
-     */
-    template <class DerivedT>
-    class CopyWithoutData
-    {
-    public:
-
-        /// Get a copy of `this` without data.
-        virtual DerivedT copyWithoutData() const
-        {
-            DerivedT t;
-            _copySelfWithoutData(t);
-            return t;
-        }
-
-
-    protected:
-
-        virtual void _copySelfWithoutData(DerivedT& other) const = 0;
-
-    };
-}
diff --git a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/EntityQueryProcessor.cpp b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/EntityQueryProcessor.cpp
index cc2744906..0c41d3a6f 100644
--- a/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/EntityQueryProcessor.cpp
+++ b/source/RobotAPI/libraries/armem/server/query_proc/workingmemory/EntityQueryProcessor.cpp
@@ -22,7 +22,13 @@ namespace armarx::armem::wm::query_proc
         }
         else
         {
-            result.addSnapshot(snapshot.copyWithoutData());
+            wm::EntitySnapshot copy = snapshot;
+            copy.forEachEntityInstance([](EntityInstance & i)
+            {
+                i.setData(nullptr);
+                return true;
+            });
+            result.addSnapshot(std::move(copy));
         }
     }
 
-- 
GitLab