alpaqa develop
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 { \
43 #name, attribute_accessor<S>::template make<type>(&type::name, \
44 __VA_ARGS__) \
45 }
46
47/// Dictionary that maps struct attribute names to type-erased functions that
48/// set those attributes.
49template <class S>
50using attribute_alias_table_t = std::map<std::string_view, std::string_view>;
51
52/// Specialize this type to define the alternative attribute name to attribute
53/// setters dictionaries for a struct type @p T.
54template <class T, class S>
56
57/// Helper macro to easily specialize @ref alpaqa::params::attribute_alias_table.
58#define PARAMS_ALIAS_TABLE(type_, ...) \
59 template <class S> \
60 struct attribute_alias_table<type_, S> { \
61 using type = type_; \
62 inline static const attribute_alias_table_t<S> table{__VA_ARGS__}; \
63 }
64
65/// Helper macro to easily specialize @ref alpaqa::params::attribute_alias_table.
66#define PARAMS_ALIAS_TABLE_CONF(type_, ...) \
67 template <Config Conf, class S> \
68 struct attribute_alias_table<type_<Conf>, S> { \
69 using type = type_<Conf>; \
70 inline static const attribute_alias_table_t<S> table{__VA_ARGS__}; \
71 }
72
73/// Helper macro to easily initialize a
74/// @ref alpaqa::params::attribute_alias_table_t.
75#define PARAMS_MEMBER_ALIAS(alias, name) \
76 { #alias, #name }
77
78/// Function wrapper access the enumerators of an enum, type-erasing the type of
79/// the enum.
80template <class T, class S>
82
83/// Dictionary that maps enumerator names to their values and documentation.
84template <class T, class S>
85using enum_table_t = std::map<std::string_view, enum_accessor<T, S>>;
86
87/// Specialize this type to define the enumerator name to value dictionaries for
88/// an enum type @p T.
89template <class T, class S>
91
92/// Helper macro to easily specialize @ref alpaqa::params::enum_table.
93#define ENUM_TABLE(type_, ...) \
94 template <class S> \
95 struct enum_table<type_, S> { \
96 using type = type_; \
97 inline static const enum_table_t<type, S> table{__VA_ARGS__}; \
98 }
99
100/// Helper macro to easily initialize a
101/// @ref alpaqa::params::enum_table_t.
102#define ENUM_MEMBER(name, ...) \
103 { \
104 #name, { type::name, __VA_ARGS__ } \
105 }
106
107} // 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:50
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
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:85
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:55
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:81
Specialize this type to define the enumerator name to value dictionaries for an enum type T.
Definition structs.hpp:90