fix(config): load config on demand in get/set instead of asserting

This commit is contained in:
2026-07-18 10:54:51 +08:00
parent 0f731530da
commit 41c145ab30

View File

@@ -1,5 +1,4 @@
#pragma once #pragma once
#include "Cubed/tools/cubed_assert.hpp"
#include "Cubed/tools/toml.utils.hpp" #include "Cubed/tools/toml.utils.hpp"
namespace Cubed { namespace Cubed {
@@ -20,7 +19,9 @@ public:
template <TOML::TomlValueType T> template <TOML::TomlValueType T>
T get(std::string_view key, T default_value) { T get(std::string_view key, T default_value) {
ASSERT(m_init); if (!m_init) {
load_config();
}
if (auto* node = find_node(m_tbl, key)) { if (auto* node = find_node(m_tbl, key)) {
if (auto value = node->value<T>()) if (auto value = node->value<T>())
return *value; return *value;
@@ -32,7 +33,9 @@ public:
} }
template <TOML::TomlValueType T> void set(std::string_view key, T&& value) { template <TOML::TomlValueType T> void set(std::string_view key, T&& value) {
ASSERT(m_init); if (!m_init) {
load_config();
}
auto pos = key.rfind('.'); auto pos = key.rfind('.');
toml::table* table; toml::table* table;