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