From 405744eabf5187907a6c072150d7c764ae7255ad Mon Sep 17 00:00:00 2001
From: zykure <54305315+zykure@users.noreply.github.com>
Date: Tue, 25 Nov 2025 16:17:53 +0100
Subject: [PATCH 01/12] Add JSON/XML/YAML parsers and serializers [WIP]
FIXME: Compiles, but no symbols exported?
---
include/gul17/DataTree.h | 323 +++++++++++
include/gul17/data_processors.h | 55 ++
include/gul17/gul.h | 1 +
include/gul17/meson.build | 2 +
src/data_processors/json_processor.cc | 473 +++++++++++++++++
src/data_processors/xml_processor.cc | 511 ++++++++++++++++++
src/data_processors/yaml_processor.cc | 530 +++++++++++++++++++
src/meson.build | 3 +
tests/data_processors/test_json_processor.cc | 130 +++++
tests/data_processors/test_xml_processor.cc | 220 ++++++++
tests/data_processors/test_yaml_processor.cc | 134 +++++
tests/meson.build | 3 +
12 files changed, 2385 insertions(+)
create mode 100644 include/gul17/DataTree.h
create mode 100644 include/gul17/data_processors.h
create mode 100644 src/data_processors/json_processor.cc
create mode 100644 src/data_processors/xml_processor.cc
create mode 100644 src/data_processors/yaml_processor.cc
create mode 100644 tests/data_processors/test_json_processor.cc
create mode 100644 tests/data_processors/test_xml_processor.cc
create mode 100644 tests/data_processors/test_yaml_processor.cc
diff --git a/include/gul17/DataTree.h b/include/gul17/DataTree.h
new file mode 100644
index 0000000..7cf852f
--- /dev/null
+++ b/include/gul17/DataTree.h
@@ -0,0 +1,323 @@
+/**
+ * \file DataTree.h
+ * \author Jan Behrens
+ * \date Created on 19 November 2025
+ * \brief Declaration of the DataTree class.
+ *
+ * \copyright Copyright 2018-2025 Deutsches Elektronen-Synchrotron (DESY), Hamburg
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation, either version 2.1 of the license, or
+ * (at your option) any later version.
+ *
+ * This program 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef GUL17_DATA_TREE_H_
+#define GUL17_DATA_TREE_H_
+
+#include
+#include
+#include
+#include
+#include
+
+namespace gul17 {
+
+class DataTree
+{
+public:
+ using Object = std::unordered_map;
+ using Array = std::vector;
+ using Value = std::variant<
+ std::nullptr_t, // null
+ bool, // boolean
+ int, // integer
+ double, // float
+ std::string, // string
+ Array, // array
+ Object // object
+ >;
+
+ // Constructors
+ DataTree() : value_(Object()) {} // default to an empty object
+ DataTree(std::nullptr_t) : value_(nullptr) {}
+ DataTree(bool b) : value_(b) {}
+ DataTree(int i) : value_(i) {}
+ DataTree(double d) : value_(d) {}
+ DataTree(const std::string& s) : value_(s) {}
+ DataTree(const char* s) : value_(std::string(s)) {}
+ DataTree(const Array& a) : value_(a) {}
+ DataTree(const Object& o) : value_(o) {}
+
+ // Factory methods
+ static DataTree make_array() { return DataTree(Array{}); }
+ static DataTree make_object() { return DataTree(Object{}); }
+
+ // Move constructors
+ DataTree(Array&& a) : value_(std::move(a)) {}
+ DataTree(Object&& o) : value_(std::move(o)) {}
+ DataTree(std::string&& s) : value_(std::move(s)) {}
+
+ // Copy constructor
+ DataTree(const DataTree& other) = default;
+
+ // Move constructor
+ DataTree(DataTree&& other) = default;
+
+ // Assignment operators
+ DataTree& operator=(const DataTree& other) = default;
+ DataTree& operator=(DataTree&& other) = default;
+
+ // Type checking
+ bool is_null() const { return std::holds_alternative(value_); }
+ bool is_boolean() const { return std::holds_alternative(value_); }
+ bool is_int() const { return std::holds_alternative(value_); }
+ bool is_double() const { return std::holds_alternative(value_); }
+ bool is_number() const { return is_int() || is_double(); }
+ bool is_string() const { return std::holds_alternative(value_); }
+ bool is_array() const { return std::holds_alternative(value_); }
+ bool is_object() const { return std::holds_alternative