11#include " phlex/configuration.hpp"
22#include " phlex/core/product_query.hpp"
3+ #include " phlex/model/product_specification.hpp"
34
4- #include < ranges>
5+ #include < algorithm>
6+ #include < array>
57#include < string>
8+ #include < string_view>
9+
10+ namespace {
11+ [[maybe_unused]] std::optional<std::string> value_if_exists (boost::json::object const & obj, // will be used later for new product_query
12+ std::string_view parameter)
13+ {
14+ if (!obj.contains (parameter)) {
15+ return std::nullopt ;
16+ }
17+ auto const & val = obj.at (parameter);
18+ if (!val.is_string ()) {
19+ std::string_view kind;
20+ switch (val.kind ()) {
21+ case boost::json::kind::null:
22+ // seems reasonable to interpret this as if the value were not provided
23+ return std::nullopt ;
24+ break ;
25+ case boost::json::kind::bool_:
26+ kind = " bool" ;
27+ break ;
28+ case boost::json::kind::int64:
29+ kind = " std::int64_t" ;
30+ break ;
31+ case boost::json::kind::uint64:
32+ kind = " std::uint64_t" ;
33+ break ;
34+ case boost::json::kind::double_:
35+ kind = " double" ;
36+ break ;
37+ case boost::json::kind::array:
38+ kind = " array" ;
39+ break ;
40+ case boost::json::kind::object:
41+ kind = " object" ;
42+ break ;
43+ default :
44+ // std::unreachable();
45+ break ;
46+ }
47+ throw std::runtime_error (
48+ fmt::format (" Error retrieving parameter '{}'. Should be a string but is instead a {}" ,
49+ parameter,
50+ kind));
51+ }
52+ return boost::json::value_to<std::string>(val);
53+ }
54+ }
655
756namespace phlex {
857 std::vector<std::string> configuration::keys () const
@@ -25,7 +74,8 @@ namespace phlex {
2574 {
2675 using detail::value_decorate_exception;
2776 auto query_object = jv.as_object ();
28- return product_query{{value_decorate_exception<std::string>(query_object, " product" )},
29- value_decorate_exception<std::string>(query_object, " layer" )};
77+ auto product = value_decorate_exception<std::string>(query_object, " product" );
78+ auto layer = value_decorate_exception<std::string>(query_object, " layer" );
79+ return product_query{experimental::product_specification::create (product), layer};
3080 }
3181}
0 commit comments