#pragma once namespace config { typedef nlohmann::json::value_t field_type; typedef nlohmann::json field_value; nlohmann::json read_config(); void write_config(const nlohmann::json& json); nlohmann::json validate_config_field(const std::string& key, const field_value& value); template std::optional get(const std::string& key) { const auto cfg = read_config(); if (!cfg.is_object() || !cfg.contains(key)) { return {}; } const auto value = validate_config_field(key, cfg[key]); return {value.get()}; } template void set(const std::string& key, const T& value) { auto cfg = read_config(); cfg[key] = validate_config_field(key, value); write_config(cfg); } }