h2-mod/src/client/component/config.hpp

28 lines
472 B
C++
Raw Normal View History

2023-02-16 11:01:53 -05:00
#pragma once
namespace config
{
nlohmann::json read_config();
void write_config(const nlohmann::json& json);
template <typename T>
std::optional<T> get(const std::string& key)
{
const auto cfg = read_config();
if (!cfg.is_object() || !cfg.contains(key))
{
return {};
}
return {cfg[key].get<T>()};
}
template <typename T>
void set(const std::string& key, const T& value)
{
auto cfg = read_config();
cfg[key] = value;
write_config(cfg);
}
}