From 70643a9e4821bd11c3f363f1708fe420965467d1 Mon Sep 17 00:00:00 2001 From: Rutger Broekhoff Date: Fri, 28 Aug 2026 22:17:10 +0200 Subject: Format again --- server/src/config.cpp | 163 +++++++++++++++++++++++++------------------------- 1 file changed, 81 insertions(+), 82 deletions(-) (limited to 'server/src/config.cpp') diff --git a/server/src/config.cpp b/server/src/config.cpp index 84c436a..e9a728b 100644 --- a/server/src/config.cpp +++ b/server/src/config.cpp @@ -17,7 +17,7 @@ namespace routemon::config { class location { std::optional>> - next_; + next_; auto append_to(std::string& s) const -> void { @@ -64,7 +64,7 @@ public: catch (boost::system::system_error const&) { throw std::runtime_error{std::format( - "expected an object at {}", loc.to_string())}; + "expected an object at {}", loc.to_string())}; } auto check_unused() const -> void @@ -74,7 +74,7 @@ public: if (!visited_.contains(std::string{kv.key()})) { throw std::runtime_error{std::format( - "unexpected key {}", loc_.sub(kv.key()).to_string())}; + "unexpected key {}", loc_.sub(kv.key()).to_string())}; } } } @@ -93,21 +93,21 @@ public: catch (boost::system::system_error const& e) { throw std::runtime_error{std::format( - "failed to read {}: {}", loc.to_string(), e.code().message())}; + "failed to read {}: {}", loc.to_string(), e.code().message())}; } } else { throw std::runtime_error{std::format( - "did not find expected key {}", loc.to_string())}; + "did not find expected key {}", loc.to_string())}; } } }; auto as_checked_object( - json::value const& jv, location const& loc, - std::invocable auto const& f) - -> decltype(f(std::declval())) + json::value const& jv, location const& loc, + std::invocable auto const& f) + -> decltype(f(std::declval())) { auto r = object_reader{jv, loc}; auto&& v = f(r); @@ -116,110 +116,109 @@ auto as_checked_object( } auto tag_invoke( - json::value_to_tag const&, json::value const& jv, - location const& loc) -> rwgps + json::value_to_tag const&, json::value const& jv, location const& loc) + -> rwgps { return as_checked_object( - jv, loc, - [](object_reader& r) -> rwgps - { - return { - .api_key = r.expect_at("api_key"), - .auth_token = r.expect_at("auth_token"), - }; - }); + jv, loc, + [](object_reader& r) -> rwgps + { + return { + .api_key = r.expect_at("api_key"), + .auth_token = r.expect_at("auth_token"), + }; + }); } auto tag_invoke( - json::value_to_tag const&, json::value const& jv, - location const& loc) -> situations + json::value_to_tag const&, json::value const& jv, + location const& loc) -> situations { return as_checked_object( - jv, loc, - [](object_reader& r) -> situations - { - return { - .datex2_filename = r.expect_at("datex2_filename"), - }; - }); + jv, loc, + [](object_reader& r) -> situations + { + return { + .datex2_filename = r.expect_at("datex2_filename"), + }; + }); } auto tag_invoke( - json::value_to_tag const&, json::value const& jv, - location const& loc) -> database + json::value_to_tag const&, json::value const& jv, + location const& loc) -> database { return as_checked_object( - jv, loc, - [](object_reader& r) -> database - { - return { - .sqlite3_filename = r.expect_at("sqlite3_filename"), - }; - }); + jv, loc, + [](object_reader& r) -> database + { + return { + .sqlite3_filename = r.expect_at("sqlite3_filename"), + }; + }); } auto tag_invoke( - json::value_to_tag const&, json::value const& jv, - location const& loc) -> http_server + json::value_to_tag const&, json::value const& jv, + location const& loc) -> http_server { return as_checked_object( - jv, loc, - [](object_reader& r) -> http_server - { - return { - .lax_cors = r.expect_at("lax_cors"), - }; - }); + jv, loc, + [](object_reader& r) -> http_server + { + return { + .lax_cors = r.expect_at("lax_cors"), + }; + }); } auto tag_invoke( - json::value_to_tag const&, json::value const& jv, - location const& loc) -> logger + json::value_to_tag const&, json::value const& jv, location const& loc) + -> logger { return as_checked_object( - jv, loc, - [obj_loc = loc](object_reader& r) -> logger - { - auto const level_str = r.expect_at("level"); - auto level = log::level{}; - if (level_str == "debug") - level = log::level::debug; - else if (level_str == "info") - level = log::level::info; - else if (level_str == "warn") - level = log::level::warn; - else if (level_str == "error") - level = log::level::error; - else - throw std::runtime_error{std::format( - "unable to parse log level {:?} at {}: expected one " - "of {{debug, info, warn, error}}", - level_str, obj_loc.sub("level").to_string())}; - return logger{level}; - }); + jv, loc, + [obj_loc = loc](object_reader& r) -> logger + { + auto const level_str = r.expect_at("level"); + auto level = log::level{}; + if (level_str == "debug") + level = log::level::debug; + else if (level_str == "info") + level = log::level::info; + else if (level_str == "warn") + level = log::level::warn; + else if (level_str == "error") + level = log::level::error; + else + throw std::runtime_error{std::format( + "unable to parse log level {:?} at {}: expected one " + "of {{debug, info, warn, error}}", + level_str, obj_loc.sub("level").to_string())}; + return logger{level}; + }); } auto json_value_to_app(json::value const& jv) -> app { return as_checked_object( - jv, location{}, - [](object_reader& r) -> app - { - return { - .rwgps = r.expect_at("rwgps"), - .situations = r.expect_at("situations"), - .database = r.expect_at("database"), - .http_server = r.expect_at("http_server"), - .logger = r.expect_at("logger"), - }; - }); + jv, location{}, + [](object_reader& r) -> app + { + return { + .rwgps = r.expect_at("rwgps"), + .situations = r.expect_at("situations"), + .database = r.expect_at("database"), + .http_server = r.expect_at("http_server"), + .logger = r.expect_at("logger"), + }; + }); } auto load_file(std::string const& filename) -> app { - auto f = std::ifstream{ - filename - }; // TODO: ensure that we are opening in binary mode? + auto f = + std::ifstream{filename}; // TODO: ensure that we are opening in binary mode? if (!f.is_open()) throw std::runtime_error{std::format("failed to open {}", filename)}; auto jv = json::value{}; @@ -230,7 +229,7 @@ auto load_file(std::string const& filename) -> app catch (boost::system::system_error const& e) { throw std::runtime_error{std::format( - "failed to parse: {}", e.code().message())}; + "failed to parse: {}", e.code().message())}; } return json_value_to_app(jv); } -- cgit v1.3