alpaqa matlab
Nonconvex constrained optimization
Loading...
Searching...
No Matches
json.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <alpaqa/export.h>
5#include <nlohmann/json_fwd.hpp>
6#include <functional>
7#include <string>
8#include <vector>
9
10namespace alpaqa::params {
11
12using nlohmann::json;
13
14/// Update/overwrite the first argument based on the JSON object @p j.
15template <class T>
16void ALPAQA_EXPORT set_param(T &, const json &j); /* deliberately undefined */
17
18/// Get the first argument as a JSON object @p j.
19template <class T>
20void ALPAQA_EXPORT get_param(const T &, json &j); /* deliberately undefined */
21
22template <class T>
23struct attribute_accessor<T, json> {
24 template <class T_actual, class A>
26 : set([attr](T &t, const json &s) { return set_param(t.*attr, s); }),
27 get([attr](const T &t, json &s) { return get_param(t.*attr, s); }) {}
28 std::function<void(T &, const json &)> set;
29 std::function<void(const T &, json &)> get;
30};
31
32/// Custom parameter parsing exception.
33struct ALPAQA_EXPORT invalid_json_param : std::invalid_argument {
34 using std::invalid_argument::invalid_argument;
35 std::vector<std::string> backtrace;
36};
37
38} // namespace alpaqa::params
void get_param(const T &t, json &s)
Get the first argument as a JSON object j.
Definition json.tpp:85
void set_param(T &t, const json &j)
Update/overwrite the first argument based on the JSON object j.
Definition json.tpp:24
Function wrapper to set attributes of a struct, type-erasing the type of the attribute.
Definition structs.hpp:9
constexpr const auto inf
Definition config.hpp:85
std::function< void(T &, const json &)> set
Definition json.hpp:28
std::function< void(const T &, json &)> get
Definition json.hpp:29
Custom parameter parsing exception.
Definition json.hpp:33
std::vector< std::string > backtrace
Definition json.hpp:35