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
9 namespace 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>
24  constexpr undefined_t element_decimals = {};
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&
42  get()
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
56 namespace 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>;
68  static constexpr auto description = element_description<CL, MT, ptr>;
69  static constexpr auto property_name = element_property_name<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>
187  element_details<CL, MT, ptr> to_element_detail(
188  const boost::hana::pair<VarName, boost::hana::struct_detail::member_ptr<MT CL::*, ptr>>&);
189 } // namespace armarx::meta::cfg
armarx::meta::cfg::element_label
constexpr undefined_t element_label
Definition: element_details.h:30
armarx::meta::cfg::element_default::set
static void set(CL &cl)
Definition: element_details.h:48
armarx::meta::cfg::element_details::property_name
static constexpr auto property_name
Definition: element_details.h:69
armarx::meta::cfg::element_details::max_t
decltype(max) max_t
Definition: element_details.h:78
armarx::meta::cfg::element_details::no_remote_gui
static constexpr bool no_remote_gui
Definition: element_details.h:75
armarx::meta::cfg::element_details::label_t
decltype(label) label_t
Definition: element_details.h:83
armarx::meta::cfg::element_details::member_t
MT member_t
Definition: element_details.h:62
armarx::meta::cfg::element_details::min_t
decltype(min) min_t
Definition: element_details.h:77
armarx::meta::cfg::element_details::member_ptr
static constexpr auto member_ptr
Definition: element_details.h:63
armarx::meta::cfg::element_no_prop
constexpr std::false_type element_no_prop
Definition: element_details.h:33
armarx::meta::cfg::element_details::assert_settings
static constexpr bool assert_settings()
Definition: element_details.h:112
armarx::meta::cfg::element_details::description_as_string
static std::string description_as_string()
Definition: element_details.h:87
armarx::meta::cfg::element_details::decimals_t
decltype(decimals) decimals_t
Definition: element_details.h:81
armarx::meta::cfg::element_default::get
static const MT & get()
Definition: element_details.h:42
armarx::meta::cfg::element_details::property_name_t
decltype(property_name) property_name_t
Definition: element_details.h:80
armarx::meta::cfg::element_details::label
static constexpr auto label
Definition: element_details.h:72
armarx::meta::cfg::element_details::max
static constexpr auto max
Definition: element_details.h:67
armarx::meta::cfg::element_max
constexpr undefined_t element_max
Definition: element_details.h:15
config_struct_details.h
armarx::meta::cfg::element_details::decimals
static constexpr auto decimals
Definition: element_details.h:70
armarx::meta::cfg::element_steps
constexpr undefined_t element_steps
Definition: element_details.h:27
armarx::meta::cfg
Definition: PluginCfgStruct.h:31
armarx::meta::cfg::element_no_rem_gui
constexpr std::false_type element_no_rem_gui
Definition: element_details.h:36
armarx::meta::cfg::struct_default::get
static const CL & get()
Definition: config_struct_details.h:28
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::meta::cfg::element_details::steps_t
decltype(steps) steps_t
Definition: element_details.h:82
armarx::meta::cfg::element_details::member_name
static constexpr auto member_name
Definition: element_details.h:64
armarx::meta::cfg::element_widget
undefined_t element_widget
Definition: config_struct_details.h:19
armarx::meta::cfg::element_min
constexpr undefined_t element_min
Definition: element_details.h:12
armarx::meta::cfg::element_decimals
constexpr undefined_t element_decimals
Definition: element_details.h:24
armarx::meta::cfg::element_details::class_t
CL class_t
Definition: element_details.h:61
armarx::meta::cfg::element_details::make_property_name
static std::string make_property_name(std::string pre)
Definition: element_details.h:97
armarx::meta::cfg::element_details
Definition: element_details.h:59
armarx::meta::cfg::element_details::widget_t
element_widget< CL, MT, ptr > widget_t
Definition: element_details.h:84
armarx::meta::cfg::element_details::description
static constexpr auto description
Definition: element_details.h:68
armarx::meta::cfg::to_element_detail
element_details< CL, MT, ptr > to_element_detail(const boost::hana::pair< VarName, boost::hana::struct_detail::member_ptr< MT CL::*, ptr >> &)
common.h
armarx::meta::cfg::element_details::is_no_prop
static constexpr bool is_no_prop
Definition: element_details.h:74
armarx::meta::cfg::element_details::steps
static constexpr auto steps
Definition: element_details.h:71
armarx::meta::cfg::element_description
constexpr undefined_t element_description
Definition: element_details.h:18
armarx::meta::cfg::element_details::min
static constexpr auto min
Definition: element_details.h:66
armarx::meta::cfg::element_details::description_t
decltype(description) description_t
Definition: element_details.h:79
armarx::meta::cfg::undefined_t
::simox::meta::undefined_t undefined_t
Definition: common.h:17
armarx::meta::cfg::element_property_name
constexpr undefined_t element_property_name
Definition: element_details.h:21