Skip to content
Snippets Groups Projects
fixCppTrackableModel.patch 2.56 KiB
Newer Older
--- Trackable.cpp	2024-09-26 23:29:18.935379613 +0200
+++ Trackable_corrected.cpp	2024-09-26 23:27:10.814691574 +0200
@@ -46,8 +46,9 @@
 	std::stringstream ss;
 	write_json(ss, this->toPropertyTree(), prettyJson);
     // workaround inspired by: https://stackoverflow.com/a/56395440
-    std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
+    std::regex reg("\\\"([+-]?[0-9]+\\.{0,1}[0-9]*([eE][-+]?[0-9]+)?)\\\"");
     std::string result = std::regex_replace(ss.str(), reg, "$1");
+    result.erase(std::remove(result.begin(), result.end(), '|'), result.end());
Hugo Kreber's avatar
Hugo Kreber committed
     return result;
 }
 
Jerome Royan's avatar
Jerome Royan committed
@@ -65,7 +66,10 @@
 	ptree tmp_node;
 	pt.put("UUID", m_UUID);
 	pt.put("name", m_Name);
+    pt.put("trackablePayload", "|" + m_TrackablePayload +  "|" );
 	pt.put("creatorUUID", m_CreatorUUID);
+    pt.put("trackableType", m_TrackableType.getEnumValue());
+    pt.put("unit", m_Unit.getEnumValue());
 	pt.add_child("trackableEncodingInformation", m_TrackableEncodingInformation.toPropertyTree());
 	// generate tree for LocalCRS
     tmp_node.clear();
@@ -83,8 +87,19 @@
 	}
 	// generate tree for KeyvalueTags
     if (!m_KeyvalueTags.empty()) {
-        tmp_node = toPt(m_KeyvalueTags);
-        pt.add_child("keyvalueTags", tmp_node);
+        ptree keyvalueTags;
+        for (const auto& kv : m_KeyvalueTags) {
+            ptree tag_node;
+            for (const auto& val : kv.second) {
+                ptree value_node;
+                value_node.put("", "|" + val + "|"); // Ensure value is treated as string
+                tag_node.push_back(std::make_pair("", value_node));
+            }
+
+            keyvalueTags.add_child(kv.first,tag_node);
+           
+        }
Jerome Royan's avatar
Jerome Royan committed
+        pt.add_child("keyvalueTags", keyvalueTags);
     }
     tmp_node.clear();
 	pt.put("confidence", m_Confidence);
Jerome Royan's avatar
Jerome Royan committed
@@ -96,6 +111,9 @@
 	ptree tmp_node;
 	m_UUID = pt.get("UUID", "");
 	m_Name = pt.get("name", "");
+    m_TrackableType.setEnumValue(pt.get("trackableType",""));
+    m_Unit.setEnumValue(pt.get("unit",""));
+
 	m_CreatorUUID = pt.get("creatorUUID", "");
 	if (pt.get_child_optional("trackableEncodingInformation")) {
         m_TrackableEncodingInformation = fromPt<EncodingInformationStructure>(pt.get_child("trackableEncodingInformation"));
@@ -111,6 +129,9 @@
     if (pt.get_child_optional("keyvalueTags")) {
         m_KeyvalueTags = fromPt<std::map<std::string, std::vector<std::string>>>(pt.get_child("keyvalueTags"));
     }
+    if (pt.get_child_optional("trackablePayload")) {
+        m_TrackablePayload = fromPt<std::string>(pt.get_child("trackablePayload"));
Jerome Royan's avatar
Jerome Royan committed
+    }
 	m_Confidence = pt.get("confidence", 0.0);
 }