element_details.h
Go to the documentation of this file.
1#pragma once
2
3#include <SimoxUtility/meta/type_traits/is_any_of.h>
4
5#include "common.h"
7
8//possible details
9namespace armarx::meta::cfg
10{
11 template <class CL, class MT, MT CL::*ptr>
12 constexpr undefined_t element_min = {};
13
14 template <class CL, class MT, MT CL::*ptr>
15 constexpr undefined_t element_max = {};
16
17 template <class CL, class MT, MT CL::*ptr>
19
20 template <class CL, class MT, MT CL::*ptr>
22
23 template <class CL, class MT, MT CL::*ptr>
25
26 template <class CL, class MT, MT CL::*ptr>
27 constexpr undefined_t element_steps = {};
28
29 template <class CL, class MT, MT CL::*ptr>
30 constexpr undefined_t element_label = {};
31
32 template <class CL, class MT, MT CL::*ptr>
33 constexpr std::false_type element_no_prop = {};
34
35 template <class CL, class MT, MT CL::*ptr>
36 constexpr std::false_type element_no_rem_gui = {};
37
38 template <class CL, class MT, MT CL::*ptr>
39 struct element_default : std::false_type
40 {
41 static const MT&
43 {
44 return struct_default<CL>::get().*ptr;
45 }
46
47 static void
48 set(CL& cl)
49 {
50 cl.*ptr = get();
51 }
52 };
53} // namespace armarx::meta::cfg
54
55//collection of details + check of validity
56namespace armarx::meta::cfg
57{
58 template <class CL, class MT, MT CL::*ptr>
60 {
61 using class_t = CL;
62 using member_t = MT;
63 static constexpr auto member_ptr = ptr;
64 static constexpr auto member_name = hana_member_name<CL, MT, ptr>;
65
66 static constexpr auto min = element_min<CL, MT, ptr>;
67 static constexpr auto max = element_max<CL, MT, ptr>;
70 static constexpr auto decimals = element_decimals<CL, MT, ptr>;
71 static constexpr auto steps = element_steps<CL, MT, ptr>;
72 static constexpr auto label = element_label<CL, MT, ptr>;
73
74 static constexpr bool is_no_prop = decltype(element_no_prop<CL, MT, ptr>)::value;
75 static constexpr bool no_remote_gui = decltype(element_no_rem_gui<CL, MT, ptr>)::value;
76
77 using min_t = decltype(min);
78 using max_t = decltype(max);
79 using description_t = decltype(description);
80 using property_name_t = decltype(property_name);
81 using decimals_t = decltype(decimals);
82 using steps_t = decltype(steps);
83 using label_t = decltype(label);
85
86 static std::string
88 {
89 if constexpr (is_not_undefined_t(description))
90 {
91 return description;
92 }
93 return "";
94 }
95
96 static std::string
97 make_property_name(std::string pre)
98 {
99 if (!pre.empty())
100 {
101 pre += '.';
102 }
103 if constexpr (is_not_undefined_t(property_name))
104 {
105 return pre + property_name;
106 }
107 return pre + member_name;
108 }
109
110 //general checks (does not check details for gui)
111 static constexpr bool
113 {
114 //check label / description
115 static_assert(undefined_t_or_type<const char*>(label),
116 "if set, element_label has to be of type const char*");
117 static_assert(undefined_t_or_type<const char*>(description),
118 "if set, element_description has to be of type const char*");
119 static_assert(undefined_t_or_type<const char*>(property_name),
120 "if set, element_property_name has to be of type const char*");
121
122 //check min / max / steps / decimals
123 if constexpr (simox::meta::is_any_of_v<MT, std::string, bool>)
124 {
125 static_assert(is_undefined_t(min),
126 "element_min can't be set for std::string or bool");
127 static_assert(is_undefined_t(max),
128 "element_max can't be set for std::string or bool");
129 static_assert(is_undefined_t(steps),
130 "element_steps can't be set for std::string or bool");
131 static_assert(is_undefined_t(decimals),
132 "element_decimals can't be set for std::string or bool");
133 }
134 else if constexpr (std::is_integral_v<MT>)
135 {
136 static_assert(undefined_t_or_type_or_array_sz_1<MT>(min),
137 "if set, element_min has to be of the same type as the element");
138 static_assert(undefined_t_or_type_or_array_sz_1<MT>(max),
139 "if set, element_max has to be of the same type as the element");
140
141 static_assert(undefined_t_or_type_or_array_sz_1<int>(steps),
142 "if set, element_steps has to be of type int");
143 static_assert(is_undefined_t(decimals),
144 "element_decimals can't be set for integral types");
145 }
146 else if constexpr (std::is_floating_point_v<MT>)
147 {
148 static_assert(undefined_t_or_type_or_array_sz_1<MT>(min),
149 "if set, element_min has to be of the same type as the element");
150 static_assert(undefined_t_or_type_or_array_sz_1<MT>(max),
151 "if set, element_max has to be of the same type as the element");
152
153 static_assert(undefined_t_or_type_or_array_sz_1<int>(steps),
154 "if set, element_steps has to be of type int");
155 static_assert(undefined_t_or_type_or_array_sz_1<int>(decimals),
156 "if set, element_decimals has to be of type int");
157 }
158 else if constexpr (std::is_same_v<MT, Eigen::Vector3f>)
159 {
160 static_assert(undefined_t_or_type_or_array_sz_1<float>(min),
161 "if set, element_min has to be of the same type as the element");
162 static_assert(undefined_t_or_type_or_array_sz_1<float>(max),
163 "if set, element_max has to be of the same type as the element");
164
165 static_assert(undefined_t_or_type_or_array_sz_1<int>(steps),
166 "if set, element_steps has to be of type int");
167 static_assert(undefined_t_or_type_or_array_sz_1<int>(decimals),
168 "if set, element_decimals has to be of type int");
169 }
170 else
171 {
172 ///TODO MX
173
174 static_assert(is_undefined_t(min), "element_min can't be set for this type");
175 static_assert(is_undefined_t(max), "element_max can't be set for this type");
176 static_assert(is_undefined_t(steps), "element_steps can't be set for this type");
177 static_assert(is_undefined_t(decimals),
178 "element_decimals can't be set for this type");
179 }
180 return true;
181 }
182
183 static_assert(assert_settings());
184 };
185
186 template <class VarName, class CL, class MT, MT CL::*ptr>
188 const boost::hana::pair<VarName, boost::hana::struct_detail::member_ptr<MT CL::*, ptr>>&);
189} // namespace armarx::meta::cfg
::simox::meta::undefined_t undefined_t
Definition common.h:17
constexpr undefined_t element_decimals
constexpr undefined_t element_steps
element_details< CL, MT, ptr > to_element_detail(const boost::hana::pair< VarName, boost::hana::struct_detail::member_ptr< MT CL::*, ptr > > &)
constexpr undefined_t element_min
constexpr std::false_type element_no_prop
constexpr undefined_t element_property_name
constexpr undefined_t element_label
constexpr std::false_type element_no_rem_gui
constexpr undefined_t element_description
constexpr undefined_t element_max
static constexpr auto property_name
decltype(property_name) property_name_t
static constexpr bool assert_settings()
static constexpr bool no_remote_gui
decltype(description) description_t
static std::string description_as_string()
static std::string make_property_name(std::string pre)
element_widget< CL, MT, ptr > widget_t