13#include <system_error>
27 "' cannot be indexed in '" +
37 std::string(s.full_key) +
"'");
44void set_param(std::string_view &v, ParamString s);
47void set_param(std::string &v, ParamString s);
50 requires((std::floating_point<T> || std::integral<T>) && !std::is_enum_v<T>)
56template <
class Rep,
class Period>
57void set_param(std::chrono::duration<Rep, Period> &t, ParamString s);
61template <
class T,
class A>
80 std::map<std::string_view, param_setter_fun_t<T>>;
94 auto penult = std::prev(tbl.end());
95 auto quote_concat = [](std::string &&a,
auto b) {
96 return a +
"'" + std::string(b.first) +
"', ";
98 return std::accumulate(tbl.begin(), penult, std::string{}, quote_concat) +
99 "'" + std::string(penult->first) +
"'";
105 requires requires { dict_to_struct_table<T>::table; }
109 auto it = m.find(key);
113 "' in '" + std::string(s.
full_key) +
114 "',\n possible keys are: " + possible_keys<T>());
116 it->second.set(t, s);
120#define PARAMS_TABLE(type_, ...) \
122 struct dict_to_struct_table<type_> { \
123 using type = type_; \
124 inline static const dict_to_struct_table_t<type> table{__VA_ARGS__}; \
129#define PARAMS_MEMBER(name) \
std::string demangled_typename(const std::type_info &t)
Get the pretty name of the given type as a string.
void set_param(bool &b, ParamString s)
auto param_setter(A T::*attr)
Return a function that applies set_param to the given attribute of a value of type T.
void unsupported_type(T &, ParamString s)
Throw a meaningful error to indicate that parameters of type T are not supported or implemented.
std::string_view key
The subkey to resolve next.
void assert_key_empty(ParamString s)
Throw a meaningful error when s.key is not empty, to indicate that the given type T is not of struct ...
std::string_view full_key
Full key string, used for diagnostics.
auto split_key(std::string_view full, char tok='.')
Split the string full on the first occurrence of tok.
std::map< std::string_view, param_setter_fun_t< T > > dict_to_struct_table_t
Dictionary that maps struct attribute names to type-erased functions that set those attributes.
auto possible_keys()
Return a string enumerating the possible attribute names for the struct type T.
Represents a parameter value encoded as a string in the format abc.def.key=value.
Specialize this type to define the attribute name to attribute setters dictionaries for a struct type...
Custom parameter parsing exception.
Function wrapper to set attributes of a struct, type-erasing the type of the attribute.
param_setter_fun_t(A T::*attr)
std::function< void(T &, ParamString)> set
void operator()(T &t, ParamString s) const