Nonconvex constrained optimization
Loading...
Searching...
No Matches
structs.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <map>
4#include <string_view>
5
6namespace alpaqa::params {
7
8/// Function wrapper to set attributes of a struct, type-erasing the type of the
9/// attribute.
10template <class S>
12
13/// Dictionary that maps struct attribute names to type-erased functions that
14/// set those attributes.
15template <class S>
16using attribute_table_t = std::map<std::string_view, attribute_accessor<S>>;
17
18/// Specialize this type to define the attribute name to attribute setters
19/// dictionaries for a struct type @p T.
20template <class T, class S>
22
23/// Helper macro to easily specialize @ref alpaqa::params::attribute_table.
24#define PARAMS_TABLE(type_, ...) \
25 template <class S> \
26 struct attribute_table<type_, S> { \
27 using type = type_; \
28 inline static const attribute_table_t<S> table{__VA_ARGS__}; \
29 }
30
31/// Helper macro to easily specialize @ref alpaqa::params::attribute_table.
32#define PARAMS_TABLE_CONF(type_, ...) \
33 template <Config Conf, class S> \
34 struct attribute_table<type_<Conf>, S> { \
35 using type = type_<Conf>; \
36 inline static const attribute_table_t<S> table{__VA_ARGS__}; \
37 }
38
39/// Helper macro to easily initialize a
40/// @ref alpaqa::params::attribute_table_t.
41#define PARAMS_MEMBER(name, ...) \
42 {#name, \
43 attribute_accessor<S>::template make<type>(&type::name, __VA_ARGS__)}
44
45/// Dictionary that maps struct attribute names to type-erased functions that
46/// set those attributes.
47template <class S>
48using attribute_alias_table_t = std::map<std::string_view, std::string_view>;
49
50/// Specialize this type to define the alternative attribute name to attribute
51/// setters dictionaries for a struct type @p T.
52template <class T, class S>
54
55/// Helper macro to easily specialize @ref alpaqa::params::attribute_alias_table.
56#define PARAMS_ALIAS_TABLE(type_, ...) \
57 template <class S> \
58 struct attribute_alias_table<type_, S> { \
59 using type = type_; \
60 inline static const attribute_alias_table_t<S> table{__VA_ARGS__}; \
61 }
62
63/// Helper macro to easily specialize @ref alpaqa::params::attribute_alias_table.
64#define PARAMS_ALIAS_TABLE_CONF(type_, ...) \
65 template <Config Conf, class S> \
66 struct attribute_alias_table<type_<Conf>, S> { \
67 using type = type_<Conf>; \
68 inline static const attribute_alias_table_t<S> table{__VA_ARGS__}; \
69 }
70
71/// Helper macro to easily initialize a
72/// @ref alpaqa::params::attribute_alias_table_t.
73#define PARAMS_MEMBER_ALIAS(alias, name) {#alias, #name}
74
75/// Function wrapper access the enumerators of an enum, type-erasing the type of
76/// the enum.
77template <class T, class S>
79
80/// Dictionary that maps enumerator names to their values and documentation.
81template <class T, class S>
82using enum_table_t = std::map<std::string_view, enum_accessor<T, S>>;
83
84/// Specialize this type to define the enumerator name to value dictionaries for
85/// an enum type @p T.
86template <class T, class S>
88
89/// Helper macro to easily specialize @ref alpaqa::params::enum_table.
90#define ENUM_TABLE(type_, ...) \
91 template <class S> \
92 struct enum_table<type_, S> { \
93 using type = type_; \
94 inline static const enum_table_t<type, S> table{__VA_ARGS__}; \
95 }
96
97/// Helper macro to easily initialize a
98/// @ref alpaqa::params::enum_table_t.
99#define ENUM_MEMBER(name, ...) \
100 { \
101 #name, { type::name, __VA_ARGS__ } \
102 }
103
104} // namespace alpaqa::params
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.
Definition structs.hpp:48
std::map< std::string_view, enum_accessor< T, S > > enum_table_t
Dictionary that maps enumerator names to their values and documentation.
Definition structs.hpp:82
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.
Definition structs.hpp:16
Function wrapper to set attributes of a struct, type-erasing the type of the attribute.
Definition structs.hpp:11
Specialize this type to define the alternative attribute name to attribute setters dictionaries for a...
Definition structs.hpp:53
Specialize this type to define the attribute name to attribute setters dictionaries for a struct type...
Definition structs.hpp:21
Function wrapper access the enumerators of an enum, type-erasing the type of the enum.
Definition structs.hpp:78
Specialize this type to define the enumerator name to value dictionaries for an enum type T.
Definition structs.hpp:87