From 621e9207c6c414c43954e67ffe82c0115f5641e8 Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Fri, 30 Apr 2021 13:05:47 +0200
Subject: [PATCH] Fix Memory ctors and ops

---
 .../libraries/armem/core/base/MemoryBase.h    | 22 ++----
 .../core/base/detail/EntityContainerBase.h    |  9 +--
 .../armem/core/diskmemory/Memory.cpp          | 12 ----
 .../libraries/armem/core/diskmemory/Memory.h  |  3 +-
 .../armem/core/longtermmemory/Memory.cpp      |  6 --
 .../armem/core/longtermmemory/Memory.h        |  3 +-
 .../armem/core/workingmemory/Memory.cpp       |  3 -
 .../armem/core/workingmemory/Memory.h         |  6 +-
 .../libraries/armem/test/ArMemMemoryTest.cpp  | 69 +++++++++++++++++--
 9 files changed, 77 insertions(+), 56 deletions(-)

diff --git a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h
index b97faceca..7bcef9350 100644
--- a/source/RobotAPI/libraries/armem/core/base/MemoryBase.h
+++ b/source/RobotAPI/libraries/armem/core/base/MemoryBase.h
@@ -47,19 +47,10 @@ namespace armarx::armem::base
         {
         }
 
-        /*
-        MemoryBase(const MemoryBase& other) :
-            Base(other)
-        {
-        }
-
-
-        MemoryBase& operator=(const MemoryBase& other)
-        {
-            other._copySelf(*this);
-            return *this;
-        }
-        */
+        MemoryBase(const MemoryBase& other) = default;
+        MemoryBase(MemoryBase&& other) = default;
+        MemoryBase& operator=(const MemoryBase& other) = default;
+        MemoryBase& operator=(MemoryBase&& other) = default;
 
 
         inline const std::string& name() const
@@ -207,10 +198,5 @@ namespace armarx::armem::base
         {
             return this->name();
         }
-
-
-    protected:
-
-
     };
 }
diff --git a/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h b/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h
index 4aafc3df3..9e5c869c3 100644
--- a/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h
+++ b/source/RobotAPI/libraries/armem/core/base/detail/EntityContainerBase.h
@@ -36,14 +36,7 @@ namespace armarx::armem::base::detail
     public:
 
         using Base::MemoryContainerBase;
-
-        /*
-        EntityContainerBase& operator=(const EntityContainerBase& other)
-        {
-            other._copySelf(*this);
-            return *this;
-        }
-        */
+        using Base::operator=;
 
 
         /**
diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp
index f7461b4cf..874d189d6 100644
--- a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp
+++ b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.cpp
@@ -8,18 +8,6 @@
 
 namespace armarx::armem::d_ltm
 {
-    Memory::Memory(const Memory& other) :
-        Base(other),
-        path(other.path)
-    {
-    }
-
-    Memory& Memory::operator=(const Memory& other)
-    {
-        other._copySelf(*this);
-        return *this;
-    }
-
     std::filesystem::path Memory::_fullPath() const
     {
         if (path)
diff --git a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.h b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.h
index f1a9d446d..7f7872f7a 100644
--- a/source/RobotAPI/libraries/armem/core/diskmemory/Memory.h
+++ b/source/RobotAPI/libraries/armem/core/diskmemory/Memory.h
@@ -22,9 +22,8 @@ namespace armarx::armem::d_ltm
     public:
 
         using Base::MemoryBase;
+        using Base::operator=;
 
-        Memory(const Memory& other);
-        Memory& operator=(const Memory& other);
 
         // Conversion
         wm::Memory convert() const;
diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp
index cf012cc37..ac2048160 100644
--- a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp
+++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.cpp
@@ -9,12 +9,6 @@
 namespace armarx::armem::ltm
 {
 
-    Memory& Memory::operator=(const Memory& other)
-    {
-        other._copySelf(*this);
-        return *this;
-    }
-
     wm::Memory Memory::convert() const
     {
         wm::Memory m;
diff --git a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h
index dcf6b7e55..a381972a8 100644
--- a/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h
+++ b/source/RobotAPI/libraries/armem/core/longtermmemory/Memory.h
@@ -20,8 +20,7 @@ namespace armarx::armem::ltm
     public:
 
         using Base::MemoryBase;
-
-        Memory& operator=(const Memory& other);
+        using Base::operator=;
 
 
         // Conversion
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp
index 85aa8c394..b7af1a645 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.cpp
@@ -3,9 +3,6 @@
 
 namespace armarx::armem::wm
 {
-
-    static Memory _memory("mymem");
-
     void Memory::_copySelfWithoutData(Memory& other) const
     {
         other.id() = _id;
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h
index 463695b44..e8b7cb353 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/Memory.h
@@ -21,7 +21,11 @@ namespace armarx::armem::wm
     public:
 
         using Base::MemoryBase;
-        virtual ~Memory() override = default;
+
+        Memory(const Memory& other) = default;
+        Memory(Memory&& other) = default;
+        Memory& operator=(const Memory& other) = default;
+        Memory& operator=(Memory&& other) = default;
 
 
     protected:
diff --git a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp
index 880f0833e..b7fffdbff 100644
--- a/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp
+++ b/source/RobotAPI/libraries/armem/test/ArMemMemoryTest.cpp
@@ -268,6 +268,19 @@ struct CustomChecks
         (void) moved;
     }
 };
+
+
+template <class T>
+void checkEqual_d_ltm(const T& lhs, const T& rhs)
+{
+    BOOST_CHECK_EQUAL(lhs.path, rhs.path);
+}
+template <class T>
+void checkMoved_d_ltm(const T& moved)
+{
+    BOOST_CHECK_EQUAL(moved.path, nullptr);
+}
+
 template <>
 struct CustomChecks<armem::wm::EntityInstance>
 {
@@ -286,11 +299,11 @@ struct CustomChecks<armem::d_ltm::EntityInstance>
 {
     static void checkEqual(const armem::d_ltm::EntityInstance& lhs, const armem::d_ltm::EntityInstance& rhs)
     {
-        BOOST_CHECK_EQUAL(lhs.path, rhs.path);
+        checkEqual_d_ltm(lhs, rhs);
     }
     static void checkMoved(const armem::d_ltm::EntityInstance& moved)
     {
-        BOOST_CHECK_EQUAL(moved.path, nullptr);
+        checkMoved_d_ltm(moved);
     }
 };
 template <>
@@ -298,11 +311,59 @@ struct CustomChecks<armem::d_ltm::EntitySnapshot>
 {
     static void checkEqual(const armem::d_ltm::EntitySnapshot& lhs, const armem::d_ltm::EntitySnapshot& rhs)
     {
-        BOOST_CHECK_EQUAL(lhs.path, rhs.path);
+        checkEqual_d_ltm(lhs, rhs);
     }
     static void checkMoved(const armem::d_ltm::EntitySnapshot& moved)
     {
-        BOOST_CHECK_EQUAL(moved.path, nullptr);
+        checkMoved_d_ltm(moved);
+    }
+};
+template <>
+struct CustomChecks<armem::d_ltm::Entity>
+{
+    static void checkEqual(const armem::d_ltm::Entity& lhs, const armem::d_ltm::Entity& rhs)
+    {
+        checkEqual_d_ltm(lhs, rhs);
+    }
+    static void checkMoved(const armem::d_ltm::Entity& moved)
+    {
+        checkMoved_d_ltm(moved);
+    }
+};
+template <>
+struct CustomChecks<armem::d_ltm::ProviderSegment>
+{
+    static void checkEqual(const armem::d_ltm::ProviderSegment& lhs, const armem::d_ltm::ProviderSegment& rhs)
+    {
+        checkEqual_d_ltm(lhs, rhs);
+    }
+    static void checkMoved(const armem::d_ltm::ProviderSegment& moved)
+    {
+        checkMoved_d_ltm(moved);
+    }
+};
+template <>
+struct CustomChecks<armem::d_ltm::CoreSegment>
+{
+    static void checkEqual(const armem::d_ltm::CoreSegment& lhs, const armem::d_ltm::CoreSegment& rhs)
+    {
+        checkEqual_d_ltm(lhs, rhs);
+    }
+    static void checkMoved(const armem::d_ltm::CoreSegment& moved)
+    {
+        checkMoved_d_ltm(moved);
+    }
+};
+template <>
+struct CustomChecks<armem::d_ltm::Memory>
+{
+    static void checkEqual(const armem::d_ltm::Memory& lhs, const armem::d_ltm::Memory& rhs)
+    {
+        checkEqual_d_ltm(lhs, rhs);
+    }
+    static void checkMoved(const armem::d_ltm::Memory& moved)
+    {
+        checkMoved_d_ltm(moved);
     }
 };
 
-- 
GitLab