From 7feefe9d5c922481081d31b12e02f42d9e028ef9 Mon Sep 17 00:00:00 2001 From: aqua Date: Wed, 1 May 2024 11:17:07 +0300 Subject: Drop python-kcofiglib build time dependency --- lib/configuration/configuration.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'lib/configuration/configuration.h') diff --git a/lib/configuration/configuration.h b/lib/configuration/configuration.h index 30f258c..f2de92f 100644 --- a/lib/configuration/configuration.h +++ b/lib/configuration/configuration.h @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include #include @@ -44,10 +46,10 @@ public: void read(std::basic_istream &input); template - [[nodiscard]] std::optional value(const char *path) const + [[nodiscard]] std::optional value(const char *path, const std::source_location location = std::source_location::current()) const { if(use_global) { - return instance()->value(path); + return instance()->value(path, location); } if(count(path) == 0) { @@ -58,13 +60,14 @@ public: } template - [[nodiscard]] std::optional value(const char *p_path) const + [[nodiscard]] std::optional value(const char *p_path, const std::source_location location = std::source_location::current()) const { if(use_global) { - return instance()->value(p_path); + return instance()->value(p_path, location); } if(this->count(p_path) == 0) { + spdlog::warn("requested non-existent configuration value {} at {}:{}", p_path, location.file_name(), location.line()); return std::nullopt; } @@ -79,11 +82,11 @@ public: } } else if(std::holds_alternative(value)) { - if constexpr(std::is_constructible::value) { + if constexpr(std::is_constructible_v || std::is_same_v) { return std::get(value); } else if constexpr(std::is_arithmetic_v) { return static_cast(std::get(value)); - } else if constexpr(std::is_constructible::value) { + } else if constexpr(std::is_constructible_v) { return std::get(value) ? T{ "true" } : T{ "false" }; } @@ -115,11 +118,12 @@ public: } template - T &shortcut(T & /* unused */, const char * /* unused */) const + T &shortcut(T & /* unused */, const char * /* unused */, const std::source_location location = std::source_location::current()) const { return T{}; } + static std::string init_global(const std::string &p_path); static void move_global(std::unique_ptr && conf); protected: -- cgit v1.2.1