6#include <nlohmann/json.hpp>
18 auto keys = std::views::keys(members);
30 auto it = members.find(key);
32 if (it == members.end()) {
38 "Invalid key '" + key +
"' for type '" +
type_name +
44 if (it == members.end())
45 throw std::logic_error(
"Alias '" + std::string(
alias_it->first) +
46 "' refers to nonexistent option '" +
47 std::string(
alias_it->second) +
"' in '" +
56 const std::false_type &,
const std::string &
type_name) ->
58 auto it = members.find(key);
60 if (it == members.end()) {
62 "Invalid key '" + key +
"' for type '" +
type_name +
68template <
class Aliases>
76 "' (expected object, but got " +
j.type_name() +
')');
78 for (
auto &&
el :
j.items()) {
79 const auto &key =
el.key();
83 it->second.set(t,
el.value());
96 template <
class T,
class T_actual,
class A>
126 requires requires { enum_table<T, json>::table; }
131 "' (expected string, but got " +
132 j.type_name() +
')');
135 std::string value =
j;
136 auto it = m.find(value);
139 "Invalid value '" + value +
"' for enum '" +
143 t = it->second.value;
147 requires requires { enum_table<T, json>::table; }
153 requires requires { attribute_table<T, json>::table; }
157 for (
auto &&[k,
v] : m)
158 v.get(&t, s[std::string{k}]);
Like std::any, but storing just the pointer, without any dynamic allocation.
std::string demangled_typename(const std::type_info &t)
Get the pretty name of the given type as a string.
void set_param_json(const any_ptr &t, const json &j, const attribute_table_t< json > &members, const Aliases &aliases, const std::string &type_name)
auto find_param_or_throw(const std::string &key, const attribute_table_t< S > &members, const attribute_alias_table_t< S > &aliases, const std::string &type_name) -> typename attribute_table_t< S >::const_iterator
std::string join_sorted_keys(const auto &members)
std::map< std::string_view, std::string_view > attribute_alias_table_t
Dictionary that maps struct attribute names to type-erased functions that set those attributes.
void get_param(const T &, json &j)
Get the first argument as a JSON object j.
std::map< std::string_view, attribute_accessor< S > > attribute_table_t
Dictionary that maps struct attribute names to type-erased functions that set those attributes.
void get_param_default(const T &t, json &j)
void set_param_default(T &t, const json &j)
void set_param(T &, const json &j)
Update/overwrite the first argument based on the JSON object j.
Function wrapper to set attributes of a struct, type-erasing the type of the attribute.
Specialize this type to define the alternative attribute name to attribute setters dictionaries for a...
Specialize this type to define the attribute name to attribute setters dictionaries for a struct type...
Specialize this type to define the enumerator name to value dictionaries for an enum type T.
std::string join(std::ranges::input_range auto strings, join_opt opt={})
Join the list of strings into a single string, using the separator given by opt.
void sort_case_insensitive(auto &range)
Sort the given range of strings in-place in a case-insensitive manner.
EigenConfigd DefaultConfig
constexpr const char * enum_name(LBFGSStepSize s)
Double-precision double configuration.
static attribute_accessor make(A T_actual::*attr, std::string_view="")
std::function< void(const any_ptr &, const json &)> set
std::function< void(const any_ptr &, json &)> get
Custom parameter parsing exception.
std::vector< std::string > backtrace