FluxioParameter.cpp
Go to the documentation of this file.
1#include "FluxioParameter.h"
2#include <vector>
3
5
9#include <RobotAPI/interface/skills/SkillManagerInterface.h>
10#include <RobotAPI/libraries/skills/core/aron/FluxioParameter.aron.generated.h>
11#include <RobotAPI/libraries/skills/core/aron/FluxioValue.aron.generated.h>
12
13#include "FluxioValue.h"
14
15namespace armarx
16{
17 namespace skills
18 {
19 manager::dto::FluxioParameter
21 {
22 manager::dto::FluxioParameter ret;
23
24 ret.id = id;
25 ret.name = name;
26 ret.description = description;
27 ret.type = typeIdentificator.toManagerIce();
28 ret.required = required;
29 ret.isInput = isInput;
30
31 skills::manager::dto::FluxioValueList ret_values;
32 for (const FluxioValue& value : values)
33 {
34 const auto& v = value.toManagerIce();
35
36 if (!v.has_value())
37 {
38 ARMARX_WARNING << "Value could not be converted.";
39 continue;
40 }
41
42 ret_values.push_back(v.value());
43 }
44 ret.values = ret_values;
45
46 return ret;
47 }
48
49 manager::dto::FluxioIdentificator
51 {
52 manager::dto::FluxioIdentificator ret;
53 ret.id = id;
54 ret.hint = name;
55 return ret;
56 }
57
58 void
59 FluxioParameter::updateFromIce(const manager::dto::FluxioParameter& i,
60 std::map<std::string, FluxioProfile>& profilesMap,
61 std::map<std::string, aron::type::ObjectPtr>& typesMap)
62 {
63 name = i.name;
64 description = i.description;
66 type = typesMap[typeIdentificator.skillId]->getMemberType(
67 typeIdentificator.parameterId); // TODO: Error handling
68 required = i.required;
69 isInput = i.isInput;
70 this->updateValuesFromIce(i.values, profilesMap);
71 }
72
73 void
74 FluxioParameter::updateFromAron(const manager::arondto::FluxioParameter& i,
75 std::map<std::string, FluxioProfile>& profilesMap,
76 std::map<std::string, aron::type::ObjectPtr>& typesMap)
77 {
78 name = i.name;
79 description = i.description;
81 type = typesMap[typeIdentificator.skillId]->getMemberType(
82 typeIdentificator.parameterId); // TODO: Error handling
83 required = i.required;
84 isInput = i.isInput;
85 this->updateValuesFromAron(i.values, profilesMap);
86 }
87
88 void
89 FluxioParameter::updateValuesFromIce(const manager::dto::FluxioValueList& i,
90 std::map<std::string, FluxioProfile>& profilesMap)
91 {
92 values.clear(); // clear old values and create them anew
93 for (const auto& value : i)
94 {
95 const auto& v = FluxioValue::FromIce(value, profilesMap);
96
97 if (!v.has_value())
98 {
99 // TODO: error handling
100 ARMARX_WARNING << "Value could not be converted.";
101 continue;
102 }
103
104 values.push_back(v.value());
105 }
106 }
107
108 void
109 FluxioParameter::updateValuesFromAron(const std::vector<manager::arondto::FluxioValue>& i,
110 std::map<std::string, FluxioProfile>& profilesMap)
111 {
112 values.clear(); // clear old values and create them anew
113 for (const auto& value : i)
114 {
115 const auto& v = FluxioValue::FromAron(value, profilesMap);
116
117 if (!v.has_value())
118 {
119 // TODO: error handling
120 ARMARX_WARNING << "Value could not be converted.";
121 continue;
122 }
123
124 values.push_back(v.value());
125 }
126 }
127
130 const manager::dto::FluxioIdentificator& i,
131 const std::map<std::string, FluxioParameter>& parametersMap)
132 {
133 const auto& parameterIt = parametersMap.find(i.id);
134
135 if (parameterIt == parametersMap.end())
136 {
137 ARMARX_WARNING << "Parameter with id " << i.id << " not found";
138 return nullptr;
139 }
140
141 return std::experimental::make_observer(&parameterIt->second);
142 }
143
146 const manager::arondto::FluxioIdentificator& i,
147 const std::map<std::string, FluxioParameter>& parametersMap)
148 {
149 const auto& parameterIt = parametersMap.find(i.id);
150
151 if (parameterIt == parametersMap.end())
152 {
153 ARMARX_WARNING << "Parameter with id " << i.id << " not found";
154 return nullptr;
155 }
156
157 return std::experimental::make_observer(&parameterIt->second);
158 }
159
161 FluxioParameter::FromIce(const manager::dto::FluxioParameter& i,
162 std::map<std::string, FluxioProfile>& profilesMap,
163 std::map<std::string, aron::type::ObjectPtr>& typesMap)
164 {
165 FluxioParameter ret;
166
167 ret.id = i.id;
168 ret.name = i.name;
169 ret.description = i.description;
171 ret.type = typesMap[ret.typeIdentificator.skillId]->getMemberType(
172 ret.typeIdentificator.parameterId); // TODO: Error handling
173 ret.required = i.required;
174 ret.isInput = i.isInput;
175
176 for (const manager::dto::FluxioValue& value : i.values)
177 {
178 const auto& v = FluxioValue::FromIce(value, profilesMap);
179
180 if (!v.has_value())
181 {
182 ARMARX_WARNING << "Value could not be converted.";
183 continue;
184 }
185
186 ret.values.push_back(v.value());
187 }
188
189 return ret;
190 }
191
193 FluxioParameter::FromAron(const manager::arondto::FluxioParameter& i,
194 std::map<std::string, FluxioProfile>& profilesMap,
195 std::map<std::string, aron::type::ObjectPtr>& typesMap)
196 {
197 FluxioParameter ret;
198
199 ret.id = i.id;
200 ret.name = i.name;
201 ret.description = i.description;
203 ret.type = typesMap[ret.typeIdentificator.skillId]->getMemberType(
204 ret.typeIdentificator.parameterId); // TODO: Error handling
205 ret.required = i.required;
206 ret.isInput = i.isInput;
207
208 for (const manager::arondto::FluxioValue& value : i.values)
209 {
210 const auto& v = FluxioValue::FromAron(value, profilesMap);
211
212 if (!v.has_value())
213 {
214 ARMARX_WARNING << "Value could not be converted.";
215 continue;
216 }
217
218 ret.values.push_back(v.value());
219 }
220
221 return ret;
222 }
223
224 manager::arondto::FluxioParameter
226 {
227 manager::arondto::FluxioParameter ret;
228
229 ret.id = id;
230 ret.name = name;
231 ret.description = description;
232 ret.type = typeIdentificator.toAron();
233 ret.required = required;
234 ret.isInput = isInput;
235
236 std::vector<manager::arondto::FluxioValue> ret_values;
237 for (const FluxioValue& value : values)
238 {
239 const auto& v = value.toAron();
240
241 if (!v.has_value())
242 {
243 ARMARX_WARNING << "Value could not be converted.";
244 continue;
245 }
246
247 ret_values.push_back(v.value());
248 }
249 ret.values = ret_values;
250
251 return ret;
252 }
253
254 manager::arondto::FluxioIdentificator
256 {
257 manager::arondto::FluxioIdentificator ret;
258 ret.id = id;
259 ret.hint = name;
260 return ret;
261 }
262 } // namespace skills
263} // namespace armarx
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
observer_ptr< _Tp > make_observer(_Tp *__p) noexcept
manager::arondto::FluxioIdentificator toFluxioIdentificatorAron() const
void updateFromIce(const manager::dto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
aron::type::VariantPtr type
static std::experimental::observer_ptr< const FluxioParameter > FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator &i, const std::map< std::string, FluxioParameter > &parametersMap)
static FluxioParameter FromIce(const manager::dto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
void updateValuesFromAron(const std::vector< manager::arondto::FluxioValue > &i, std::map< std::string, FluxioProfile > &profilesMap)
manager::arondto::FluxioParameter toAron() const
static std::experimental::observer_ptr< const FluxioParameter > FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator &i, const std::map< std::string, FluxioParameter > &parametersMap)
static FluxioParameter FromAron(const manager::arondto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
void updateFromAron(const manager::arondto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
manager::dto::FluxioParameter toManagerIce() const
std::list< FluxioValue > values
FluxioTypeIdentificator typeIdentificator
manager::dto::FluxioIdentificator toFluxioIdentificatorIce() const
void updateValuesFromIce(const manager::dto::FluxioValueList &i, std::map< std::string, FluxioProfile > &profilesMap)
static FluxioTypeIdentificator FromAron(const manager::arondto::FluxioTypeIdentificator &i)
static FluxioTypeIdentificator FromIce(const manager::dto::FluxioTypeIdentificator &i)
static std::optional< FluxioValue > FromAron(const manager::arondto::FluxioValue &i, std::map< std::string, FluxioProfile > &profilesMap)
static std::optional< FluxioValue > FromIce(const manager::dto::FluxioValue &i, std::map< std::string, FluxioProfile > &profilesMap)