PluginCfgStruct.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core
19 * @author Jan Issac (jan dot issac at gmx dot de)
20 * @date 2011
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26
30
32{
33 template <class T>
34 struct properties_definition_enabled : std::bool_constant<meta::has_hana_accessor_v<T>>
35 {
36 };
37
38 template <class T>
39 static constexpr bool properties_definition_enabled_v = properties_definition_enabled<T>::value;
40} // namespace armarx::meta::cfg
41
42//GetPropertyPlugin
44{
45 template <class T>
46 struct GetPropertyPlugin<T, std::enable_if_t<meta::cfg::properties_definition_enabled_v<T>>> :
47 std::true_type
48 {
49 static void
50 Get(armarx::PropertyUser& pu, T& val, const std::string& name)
51 {
53 namespace hana = boost::hana;
54 static constexpr auto accessors = hana::accessors<T>();
55 hana::for_each(accessors,
56 [&](auto& e)
57 {
59 using elem_det = decltype(armarx::meta::cfg::to_element_detail(e));
60 pu.getProperty(hana::second(e)(val),
61 elem_det::make_property_name(name));
62 });
63 }
64 };
65} // namespace armarx::meta::properties
66
67//DefinePropertyPlugin
69{
70 template <class T>
72 std::enable_if_t<meta::cfg::properties_definition_enabled_v<T>>> :
73 std::true_type
74 {
75 static void
77 bool required,
78 T& setter,
79 const std::string& name,
80 const std::string& description,
82 {
84 namespace hana = boost::hana;
85 static constexpr auto accessors = hana::accessors<T>();
86 hana::for_each(
87 accessors,
88 [&](auto& e)
89 {
91 using elem_det = decltype(armarx::meta::cfg::to_element_detail(e));
92 if constexpr (elem_det::is_no_prop)
93 {
94 return;
95 }
96 else
97 {
98 using sub_result_t = std::remove_reference_t<decltype(pc.required(
99 hana::second(e)(setter), "", "", constness))>;
100 const auto varname = hana::to<char const*>(hana::first(e));
101#define call_params \
102 required, hana::second(e)(setter), elem_det::make_property_name(name), \
103 description + " (parameter " + varname + ") " + elem_det::description_as_string(), \
104 constness
105
106 static constexpr bool min_set =
107 simox::meta::is_not_undefined_t(elem_det::min);
108 static constexpr bool max_set =
109 simox::meta::is_not_undefined_t(elem_det::max);
110 if constexpr (std::is_same_v<sub_result_t, void> || (!min_set && !max_set))
111 {
113 }
114 else
115 {
116 auto& subpdef = pc.requiredOrOptional(call_params);
117 if constexpr (min_set)
118 {
119 subpdef.setMin(elem_det::min);
120 }
121 if constexpr (max_set)
122 {
123 subpdef.setMax(elem_det::max);
124 }
125 }
126#undef call_params
127 }
128 });
129 }
130 };
131} // namespace armarx::meta::properties
#define call_params
decltype(auto) requiredOrOptional(bool isRequired, PropertyType &setter, const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
decltype(auto) required(PropertyType &setter, const std::string &name, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
Abstract PropertyUser class.
Property< PropertyType > getProperty(const std::string &name)
Property creation and retrieval.
element_details< CL, MT, ptr > to_element_detail(const boost::hana::pair< VarName, boost::hana::struct_detail::member_ptr< MT CL::*, ptr > > &)
static void Define(armarx::PropertyDefinitionContainer &pc, bool required, T &setter, const std::string &name, const std::string &description, PropertyDefinitionBase::PropertyConstness constness)
#define ARMARX_TRACE
Definition trace.h:77
#define ARMARX_TRACE_LITE
Definition trace.h:98