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>)
57void set_param(vec_from_file<config_t> &v, ParamString s);
59template <
class Rep,
class Period>
60void set_param(std::chrono::duration<Rep, Period> &t, ParamString s);
64template <
class T,
class A>
83 std::map<std::string_view, param_setter_fun_t<T>>;
97 auto penult = std::prev(tbl.end());
98 auto quote_concat = [](std::string &&a,
auto b) {
99 return a +
"'" + std::string(b.first) +
"', ";
101 return std::accumulate(tbl.begin(), penult, std::string{}, quote_concat) +
102 "'" + std::string(penult->first) +
"'";
108 requires requires { dict_to_struct_table<T>::table; }
112 auto it = m.find(key);
116 "' in '" + std::string(s.
full_key) +
117 "',\n possible keys are: " + possible_keys<T>());
119 it->second.set(t, s);
123#define PARAMS_TABLE(type_, ...) \
125 struct dict_to_struct_table<type_> { \
126 using type = type_; \
127 inline static const dict_to_struct_table_t<type> table{__VA_ARGS__}; \
132#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