From 24f1c38d966eb9d0f28773310e16d45566b27232 Mon Sep 17 00:00:00 2001
From: Rainer Kartmann <rainer.kartmann@kit.edu>
Date: Thu, 10 Nov 2022 14:19:27 +0100
Subject: [PATCH] Add and use constants for memory IDs

---
 .../armem/server/IndexMemory/IndexMemory.cpp  |  9 +++--
 .../libraries/armem_index/CMakeLists.txt      |  2 ++
 .../libraries/armem_index/memory_ids.cpp      | 34 ++++++++++++++++++
 .../libraries/armem_index/memory_ids.h        | 36 +++++++++++++++++++
 4 files changed, 78 insertions(+), 3 deletions(-)
 create mode 100644 source/RobotAPI/libraries/armem_index/memory_ids.cpp
 create mode 100644 source/RobotAPI/libraries/armem_index/memory_ids.h

diff --git a/source/RobotAPI/components/armem/server/IndexMemory/IndexMemory.cpp b/source/RobotAPI/components/armem/server/IndexMemory/IndexMemory.cpp
index a036531b7..e380ad6da 100644
--- a/source/RobotAPI/components/armem/server/IndexMemory/IndexMemory.cpp
+++ b/source/RobotAPI/components/armem/server/IndexMemory/IndexMemory.cpp
@@ -28,6 +28,7 @@
 #include <RobotAPI/libraries/armem/server/wm/memory_definitions.h>
 #include <RobotAPI/libraries/armem_index/aron/Named.aron.generated.h>
 #include <RobotAPI/libraries/armem_index/aron/Spatial.aron.generated.h>
+#include <RobotAPI/libraries/armem_index/memory_ids.h>
 
 
 namespace armarx
@@ -39,7 +40,7 @@ namespace armarx
         armarx::PropertyDefinitionsPtr defs =
             new ComponentPropertyDefinitions(getConfigIdentifier());
 
-        setMemoryName("Index");
+        setMemoryName(armem::index::memoryID.memoryName);
 
         return defs;
     }
@@ -55,8 +56,10 @@ namespace armarx
     void
     IndexMemory::onInitComponent()
     {
-        workingMemory().addCoreSegment("Named", armem::index::arondto::Named::ToAronType());
-        workingMemory().addCoreSegment("Spatial", armem::index::arondto::Spatial::ToAronType());
+        workingMemory().addCoreSegment(armem::index::namedSegmentID.coreSegmentName,
+                                       armem::index::arondto::Named::ToAronType());
+        workingMemory().addCoreSegment(armem::index::spatialSegmentID.coreSegmentName,
+                                       armem::index::arondto::Spatial::ToAronType());
     }
 
 
diff --git a/source/RobotAPI/libraries/armem_index/CMakeLists.txt b/source/RobotAPI/libraries/armem_index/CMakeLists.txt
index 0d82fcf13..e586cd150 100644
--- a/source/RobotAPI/libraries/armem_index/CMakeLists.txt
+++ b/source/RobotAPI/libraries/armem_index/CMakeLists.txt
@@ -20,9 +20,11 @@ armarx_add_library(
 
         aron_conversions.h
         aron_forward_declarations.h
+        memory_ids.h
 
     SOURCES
         aron_conversions.cpp
+        memory_ids.cpp
 
     ARON_FILES
         aron/Named.xml
diff --git a/source/RobotAPI/libraries/armem_index/memory_ids.cpp b/source/RobotAPI/libraries/armem_index/memory_ids.cpp
new file mode 100644
index 000000000..e70c2b0e7
--- /dev/null
+++ b/source/RobotAPI/libraries/armem_index/memory_ids.cpp
@@ -0,0 +1,34 @@
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package    RobotAPI::ArmarXObjects::armem_index
+ * @author     Rainer Kartmann ( rainer dot kartmann at kit dot edu )
+ * @date       2022
+ * @copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+
+#include "memory_ids.h"
+
+
+namespace armarx::armem
+{
+
+    const MemoryID index::memoryID { "RobotState" };
+
+    const MemoryID index::namedSegmentID { memoryID.withCoreSegmentName("Named") };
+    const MemoryID index::spatialSegmentID { memoryID.withCoreSegmentName("Spatial") };
+
+}
diff --git a/source/RobotAPI/libraries/armem_index/memory_ids.h b/source/RobotAPI/libraries/armem_index/memory_ids.h
new file mode 100644
index 000000000..6173e7a2a
--- /dev/null
+++ b/source/RobotAPI/libraries/armem_index/memory_ids.h
@@ -0,0 +1,36 @@
+/*
+ * This file is part of ArmarX.
+ *
+ * ArmarX is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * ArmarX is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package    RobotAPI::ArmarXObjects::armem_index
+ * @author     Rainer Kartmann ( rainer dot kartmann at kit dot edu )
+ * @date       2022
+ * @copyright  http://www.gnu.org/licenses/gpl-2.0.txt
+ *             GNU General Public License
+ */
+
+#pragma once
+
+#include <RobotAPI/libraries/armem/core/MemoryID.h>
+
+
+namespace armarx::armem::index
+{
+
+    extern const MemoryID memoryID;
+
+    extern const MemoryID spatialSegmentID;
+    extern const MemoryID namedSegmentID;
+
+} // namespace armarx::armem::objects
-- 
GitLab