23template <
class TSettings,
class TSnapshot = TSettings>
28 using Builder = std::function<TSnapshot(TSettings)>;
32 requires std::same_as<TSettings, TSnapshot>
33 : _build([](TSettings parsed) {
return parsed; })
44 _path = std::string(path);
48 return std::unexpected(parsed.error());
51 TSnapshot next = _build(std::move(*parsed));
52 _snapshot = std::move(next);
53 Log::Info(
"Loaded settings from {}", path);
62 return std::unexpected(
Error::NotReady(
"no settings file was loaded yet"));
64 return Load(std::string(_path));
68 const TSnapshot&
Get()
const {
return _snapshot; }
73 TSnapshot _snapshot{};
static Result< T > ReadFile(std::string_view path)
Parse path (resolved via ResolvePath) into T.
std::function< TSnapshot(TSettings)> Builder
Validates the parsed settings and derives whatever Get() offers beside them.
const TSnapshot & Get() const
Status Load(std::string_view path)
Load path (JSONC tolerated), build the snapshot, then publish it in one move.
void Info(std::format_string< Args... > fmt, Args &&... args)
std::expected< void, Error > Status
static Error NotReady(std::string detail)