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& get()
42  {
43  return struct_default<CL>::get().*ptr;
44  }
45  static void set(CL& cl)
46  {
47  cl.*ptr = get();
48  }
49  };
50 }
51 
52 //collection of details + check of validity
53 namespace armarx::meta::cfg
54 {
55  template<class CL, class MT, MT CL::* ptr>
57  {
58  using class_t = CL;
59  using member_t = MT;
60  static constexpr auto member_ptr = ptr;
61  static constexpr auto member_name = hana_member_name <CL, MT, ptr>;
62 
63  static constexpr auto min = element_min <CL, MT, ptr>;
64  static constexpr auto max = element_max <CL, MT, ptr>;
65  static constexpr auto description = element_description <CL, MT, ptr>;
66  static constexpr auto property_name = element_property_name<CL, MT, ptr>;
67  static constexpr auto decimals = element_decimals <CL, MT, ptr>;
68  static constexpr auto steps = element_steps <CL, MT, ptr>;
69  static constexpr auto label = element_label <CL, MT, ptr>;
70 
71  static constexpr bool is_no_prop = decltype(element_no_prop<CL, MT, ptr>)::value;
72  static constexpr bool no_remote_gui = decltype(element_no_rem_gui<CL, MT, ptr>)::value;
73 
74  using min_t = decltype(min);
75  using max_t = decltype(max);
76  using description_t = decltype(description);
77  using property_name_t = decltype(property_name);
78  using decimals_t = decltype(decimals);
79  using steps_t = decltype(steps);
80  using label_t = decltype(label);
82 
83  static std::string description_as_string()
84  {
85  if constexpr(is_not_undefined_t(description))
86  {
87  return description;
88  }
89  return "";
90  }
91 
92  static std::string make_property_name(std::string pre)
93  {
94  if (!pre.empty())
95  {
96  pre += '.';
97  }
98  if constexpr(is_not_undefined_t(property_name))
99  {
100  return pre + property_name;
101  }
102  return pre + member_name;
103  }
104 
105  //general checks (does not check details for gui)
106  static constexpr bool assert_settings()
107  {
108  //check label / description
109  static_assert(undefined_t_or_type<const char*>(label), "if set, element_label has to be of type const char*");
110  static_assert(undefined_t_or_type<const char*>(description), "if set, element_description has to be of type const char*");
111  static_assert(undefined_t_or_type<const char*>(property_name), "if set, element_property_name has to be of type const char*");
112 
113  //check min / max / steps / decimals
114  if constexpr(simox::meta::is_any_of_v<MT, std::string, bool>)
115  {
116  static_assert(is_undefined_t(min), "element_min can't be set for std::string or bool");
117  static_assert(is_undefined_t(max), "element_max can't be set for std::string or bool");
118  static_assert(is_undefined_t(steps), "element_steps can't be set for std::string or bool");
119  static_assert(is_undefined_t(decimals), "element_decimals can't be set for std::string or bool");
120  }
121  else if constexpr(std::is_integral_v<MT>)
122  {
123  static_assert(undefined_t_or_type_or_array_sz_1<MT>(min), "if set, element_min has to be of the same type as the element");
124  static_assert(undefined_t_or_type_or_array_sz_1<MT>(max), "if set, element_max has to be of the same type as the element");
125 
126  static_assert(undefined_t_or_type_or_array_sz_1<int>(steps), "if set, element_steps has to be of type int");
127  static_assert(is_undefined_t(decimals), "element_decimals can't be set for integral types");
128  }
129  else if constexpr(std::is_floating_point_v<MT>)
130  {
131  static_assert(undefined_t_or_type_or_array_sz_1<MT>(min), "if set, element_min has to be of the same type as the element");
132  static_assert(undefined_t_or_type_or_array_sz_1<MT>(max), "if set, element_max has to be of the same type as the element");
133 
134  static_assert(undefined_t_or_type_or_array_sz_1<int>(steps), "if set, element_steps has to be of type int");
135  static_assert(undefined_t_or_type_or_array_sz_1<int>(decimals), "if set, element_decimals has to be of type int");
136  }
137  else if constexpr(std::is_same_v<MT, Eigen::Vector3f>)
138  {
139  static_assert(undefined_t_or_type_or_array_sz_1<float>(min), "if set, element_min has to be of the same type as the element");
140  static_assert(undefined_t_or_type_or_array_sz_1<float>(max), "if set, element_max has to be of the same type as the element");
141 
142  static_assert(undefined_t_or_type_or_array_sz_1<int>(steps), "if set, element_steps has to be of type int");
143  static_assert(undefined_t_or_type_or_array_sz_1<int>(decimals), "if set, element_decimals has to be of type int");
144  }
145  else
146  {
147  ///TODO MX
148 
149  static_assert(is_undefined_t(min), "element_min can't be set for this type");
150  static_assert(is_undefined_t(max), "element_max can't be set for this type");
151  static_assert(is_undefined_t(steps), "element_steps can't be set for this type");
152  static_assert(is_undefined_t(decimals), "element_decimals can't be set for this type");
153  }
154  return true;
155  }
156  static_assert(assert_settings());
157  };
158 
159  template<class VarName, class CL, class MT, MT CL::* ptr>
160  element_details<CL, MT, ptr>
162  const boost::hana::pair<VarName, boost::hana::struct_detail::member_ptr<MT CL::*, ptr>>&
163  );
164 }
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:45
armarx::meta::cfg::element_details::property_name
static constexpr auto property_name
Definition: element_details.h:66
armarx::meta::cfg::element_details::max_t
decltype(max) max_t
Definition: element_details.h:75
armarx::meta::cfg::element_details::no_remote_gui
static constexpr bool no_remote_gui
Definition: element_details.h:72
armarx::meta::cfg::element_details::label_t
decltype(label) label_t
Definition: element_details.h:80
armarx::meta::cfg::element_details::member_t
MT member_t
Definition: element_details.h:59
armarx::meta::cfg::element_details::min_t
decltype(min) min_t
Definition: element_details.h:74
armarx::meta::cfg::element_details::member_ptr
static constexpr auto member_ptr
Definition: element_details.h:60
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:106
armarx::meta::cfg::element_details::description_as_string
static std::string description_as_string()
Definition: element_details.h:83
armarx::meta::cfg::element_details::decimals_t
decltype(decimals) decimals_t
Definition: element_details.h:78
armarx::meta::cfg::element_default::get
static const MT & get()
Definition: element_details.h:41
armarx::meta::cfg::element_details::property_name_t
decltype(property_name) property_name_t
Definition: element_details.h:77
armarx::meta::cfg::element_details::label
static constexpr auto label
Definition: element_details.h:69
armarx::meta::cfg::element_details::max
static constexpr auto max
Definition: element_details.h:64
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:67
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:26
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::meta::cfg::element_details::steps_t
decltype(steps) steps_t
Definition: element_details.h:79
armarx::meta::cfg::element_details::member_name
static constexpr auto member_name
Definition: element_details.h:61
armarx::meta::cfg::element_widget
undefined_t element_widget
Definition: config_struct_details.h:18
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:58
armarx::meta::cfg::element_details::make_property_name
static std::string make_property_name(std::string pre)
Definition: element_details.h:92
armarx::meta::cfg::element_details
Definition: element_details.h:56
armarx::meta::cfg::element_details::widget_t
element_widget< CL, MT, ptr > widget_t
Definition: element_details.h:81
armarx::meta::cfg::element_details::description
static constexpr auto description
Definition: element_details.h:65
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:71
armarx::meta::cfg::element_details::steps
static constexpr auto steps
Definition: element_details.h:68
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:63
armarx::meta::cfg::element_details::description_t
decltype(description) description_t
Definition: element_details.h:76
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