From b7dd22aa36f5179e7b4124e55d367dc55111af76 Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Fri, 11 Jun 2021 17:10:07 +0200
Subject: [PATCH] Remove duplicated function def, rename variables

---
 .../visitor/FunctionalVisitor.cpp             | 181 +-----------------
 .../workingmemory/visitor/FunctionalVisitor.h |  24 +--
 2 files changed, 13 insertions(+), 192 deletions(-)

diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/visitor/FunctionalVisitor.cpp b/source/RobotAPI/libraries/armem/core/workingmemory/visitor/FunctionalVisitor.cpp
index ede63a494..2ef261811 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/visitor/FunctionalVisitor.cpp
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/visitor/FunctionalVisitor.cpp
@@ -1,4 +1,4 @@
-#include "Visitor.h"
+#include "FunctionalVisitor.h"
 
 #include <ArmarXCore/core/exceptions/local/ExpressionException.h>
 
@@ -9,183 +9,4 @@
 namespace armarx::armem::wm
 {
 
-    Visitor::Visitor()
-    {
-    }
-
-    Visitor::~Visitor()
-    {
-    }
-
-    bool Visitor::applyTo(Memory& memory)
-    {
-        bool cont = true;
-        visitEnter(memory);
-        for (auto& [_, coreSeg] : memory)
-        {
-            if (!applyTo(coreSeg))
-            {
-                cont = false;
-                break;
-            }
-        }
-        visitExit(memory);
-        return cont;
-    }
-
-    bool Visitor::applyTo(CoreSegment& coreSegment)
-    {
-        bool cont = true;
-        visitEnter(coreSegment);
-        for (auto& [_, provSeg] : coreSegment)
-        {
-            if (!applyTo(provSeg))
-            {
-                cont = false;
-                break;
-            }
-        }
-        visitExit(coreSegment);
-        return cont;
-    }
-
-    bool Visitor::applyTo(ProviderSegment& providerSegment)
-    {
-        bool cont = true;
-        visitEnter(providerSegment);
-        for (auto& [_, entity] : providerSegment)
-        {
-            if (!applyTo(entity))
-            {
-                cont = false;
-                break;
-            }
-        }
-        visitExit(providerSegment);
-        return cont;
-    }
-
-    bool Visitor::applyTo(Entity& entity)
-    {
-        bool cont = true;
-        visitEnter(entity);
-        for (auto& [_, snapshot] : entity)
-        {
-            if (!applyTo(snapshot))
-            {
-                cont = false;
-                break;
-            }
-        }
-        visitExit(entity);
-        return cont;
-    }
-
-    bool Visitor::applyTo(EntitySnapshot& snapshot)
-    {
-        bool cont = true;
-        visitEnter(snapshot);
-        for (auto& instance : snapshot)
-        {
-            if (!applyTo(instance))
-            {
-                cont = false;
-                break;
-            }
-        }
-        visitExit(snapshot);
-        return cont;
-    }
-
-    bool Visitor::applyTo(EntityInstance& instance)
-    {
-        return visit(instance);
-    }
-
-
-    bool Visitor::applyTo(const Memory& memory)
-    {
-        bool cont = true;
-        visitEnter(memory);
-        for (const auto& [_, coreSeg] : memory)
-        {
-            if (!applyTo(coreSeg))
-            {
-                cont = false;
-                break;
-            }
-        }
-        visitExit(memory);
-        return cont;
-    }
-
-    bool Visitor::applyTo(const CoreSegment& coreSegment)
-    {
-        bool cont = true;
-        visitEnter(coreSegment);
-        for (const auto& [_, provSeg] : coreSegment)
-        {
-            if (!applyTo(provSeg))
-            {
-                cont = false;
-                break;
-            }
-        }
-        visitExit(coreSegment);
-        return cont;
-    }
-
-    bool Visitor::applyTo(const ProviderSegment& providerSegment)
-    {
-        bool cont = true;
-        visitEnter(providerSegment);
-        for (const auto& [_, entity] : providerSegment)
-        {
-            if (!applyTo(entity))
-            {
-                cont = false;
-                break;
-            }
-        }
-        visitExit(providerSegment);
-        return cont;
-    }
-
-    bool Visitor::applyTo(const Entity& entity)
-    {
-        bool cont = true;
-        visitEnter(entity);
-        for (const auto& [_, snapshot] : entity)
-        {
-            if (!applyTo(snapshot))
-            {
-                cont = false;
-                break;
-            }
-        }
-        visitExit(entity);
-        return cont;
-    }
-
-    bool Visitor::applyTo(const EntitySnapshot& snapshot)
-    {
-        bool cont = true;
-        visitEnter(snapshot);
-        for (const auto& instance : snapshot)
-        {
-            if (!applyTo(instance))
-            {
-                cont = false;
-                break;
-            }
-        }
-        visitExit(snapshot);
-        return cont;
-    }
-
-    bool Visitor::applyTo(const EntityInstance& instance)
-    {
-        return visit(instance);
-    }
-
 }
diff --git a/source/RobotAPI/libraries/armem/core/workingmemory/visitor/FunctionalVisitor.h b/source/RobotAPI/libraries/armem/core/workingmemory/visitor/FunctionalVisitor.h
index ba0fd3d6f..2cd0e2057 100644
--- a/source/RobotAPI/libraries/armem/core/workingmemory/visitor/FunctionalVisitor.h
+++ b/source/RobotAPI/libraries/armem/core/workingmemory/visitor/FunctionalVisitor.h
@@ -59,48 +59,48 @@ namespace armarx::armem::wm
 
         bool visitEnter(const Memory& memory) override
         {
-            return memoryFn ? constMemoryFn(memory) : Visitor::visitEnter(memory);
+            return memoryFn ? memoryConstFn(memory) : Visitor::visitEnter(memory);
         }
         bool visitEnter(const CoreSegment& coreSegment) override
         {
-            return coreSegmentFn ? constCoreSegmentFn(coreSegment) : Visitor::visitEnter(coreSegment);
+            return coreSegmentFn ? coreSegmentConstFn(coreSegment) : Visitor::visitEnter(coreSegment);
         }
         bool visitEnter(const ProviderSegment& providerSegment) override
         {
-            return providerSegmentFn ? constProviderSegmentFn(providerSegment) : Visitor::visitEnter(providerSegment);
+            return providerSegmentFn ? providerSegmentConstFn(providerSegment) : Visitor::visitEnter(providerSegment);
         }
         bool visitEnter(const Entity& entity) override
         {
-            return entityFn ? constEntityFn(entity) : Visitor::visitEnter(entity);
+            return entityFn ? entityConstFn(entity) : Visitor::visitEnter(entity);
         }
         bool visitEnter(const EntitySnapshot& snapshot) override
         {
-            return memoryFn ? constSnapshotFn(snapshot) : Visitor::visitEnter(snapshot);
+            return memoryFn ? snapshotConstFn(snapshot) : Visitor::visitEnter(snapshot);
         }
 
         bool visit(const EntityInstance& instance) override
         {
-            return instanceFn ? constInstanceFn(instance) : Visitor::visit(instance);
+            return instanceFn ? instanceConstFn(instance) : Visitor::visit(instance);
         }
 
 
         std::function<bool(Memory& memory)> memoryFn;
-        std::function<bool(const Memory& memory)> constMemoryFn;
+        std::function<bool(const Memory& memory)> memoryConstFn;
 
         std::function<bool(CoreSegment& coreSegment)> coreSegmentFn;
-        std::function<bool(const CoreSegment& coreSegment)> constCoreSegmentFn;
+        std::function<bool(const CoreSegment& coreSegment)> coreSegmentConstFn;
 
         std::function<bool(ProviderSegment& providerSegment)> providerSegmentFn;
-        std::function<bool(const ProviderSegment& providerSegment)> constProviderSegmentFn;
+        std::function<bool(const ProviderSegment& providerSegment)> providerSegmentConstFn;
 
         std::function<bool(Entity& entity)> entityFn;
-        std::function<bool(const Entity& entity)> constEntityFn;
+        std::function<bool(const Entity& entity)> entityConstFn;
 
         std::function<bool(EntitySnapshot& snapshot)> snapshotFn;
-        std::function<bool(const EntitySnapshot& snapshot)> constSnapshotFn;
+        std::function<bool(const EntitySnapshot& snapshot)> snapshotConstFn;
 
         std::function<bool(EntityInstance& instance)> instanceFn;
-        std::function<bool(const EntityInstance& instance)> constInstanceFn;
+        std::function<bool(const EntityInstance& instance)> instanceConstFn;
 
     };
 
-- 
GitLab