From 85f75d98149fe833469ee12131a3a32bdf93a490 Mon Sep 17 00:00:00 2001
From: Patrick Wuttke
Date: Tue, 17 Feb 2026 10:32:31 +0100
Subject: [PATCH] Changed config to save the data type with the data so it can
be loaded with the correct type.
---
private/raid/config.cpp | 39 +++++++++++++++++++++++++++++----------
public/raid/config.hpp | 3 +++
2 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/private/raid/config.cpp b/private/raid/config.cpp
index 1060756..c9e5bee 100644
--- a/private/raid/config.cpp
+++ b/private/raid/config.cpp
@@ -7,6 +7,13 @@
#include
#include
+namespace
+{
+const std::string TAG_BOOL = "bool";
+const std::string TAG_INT = "int";
+const std::string TAG_DOUBLE = "double";
+}
+
template<>
struct YAML::convert
{
@@ -68,6 +75,15 @@ struct YAML::convert
value.visit([&](const T& content) {
if constexpr (!std::is_same_v) {
node = content;
+ if constexpr (std::is_same_v) {
+ node.SetTag(TAG_BOOL);
+ }
+ else if constexpr (std::is_same_v) {
+ node.SetTag(TAG_INT);
+ }
+ else if constexpr (std::is_same_v) {
+ node.SetTag(TAG_DOUBLE);
+ }
}
else {
node = {};
@@ -91,19 +107,23 @@ struct YAML::convert
value = node.as();
break;
case YAML::NodeType::Scalar:
- try
- {
- value = node.as();
- break;
+ {
+ const std::string& tag = node.Tag();
+
+ if (tag == TAG_BOOL) {
+ value = node.as();
}
- catch(const YAML::Exception&) {} // NOLINT(bugprone-empty-catch)
- try
- {
+ else if (tag == TAG_INT) {
+ value = node.as();
+ }
+ else if (tag == TAG_DOUBLE) {
value = node.as();
}
- catch(const YAML::Exception&) {} // NOLINT(bugprone-empty-catch)
- value = node.as();
+ else {
+ value = node.as();
+ }
break;
+ }
default:
return false;
}
@@ -302,7 +322,6 @@ void FileConfig::setValue(std::string_view path, ConfigValue value) noexcept
mDirty = true;
}
-
mijin::Result<> FileConfig::init(mijin::PathReference path)
{
mPath = std::move(path);
diff --git a/public/raid/config.hpp b/public/raid/config.hpp
index 83937b5..9cc07e0 100644
--- a/public/raid/config.hpp
+++ b/public/raid/config.hpp
@@ -175,6 +175,9 @@ public:
void setValue(std::string_view path, ConfigValue value) noexcept;
+ [[nodiscard]]
+ bool valueExists(std::string_view path) const noexcept;
+
[[nodiscard]]
mijin::Result<> init(mijin::PathReference path);