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 
15 namespace 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;
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  {
166 
167  ret.id = i.id;
168  ret.name = i.name;
169  ret.description = i.description;
170  ret.typeIdentificator = FluxioTypeIdentificator::FromIce(i.type);
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  {
198 
199  ret.id = i.id;
200  ret.name = i.name;
201  ret.description = i.description;
202  ret.typeIdentificator = FluxioTypeIdentificator::FromAron(i.type);
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
armarx::skills::FluxioParameter::toFluxioIdentificatorAron
manager::arondto::FluxioIdentificator toFluxioIdentificatorAron() const
Definition: FluxioParameter.cpp:255
armarx::skills::FluxioParameter
Definition: FluxioParameter.h:23
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
skills
This file is part of ArmarX.
armarx::skills::FluxioParameter::FromIce
static FluxioParameter FromIce(const manager::dto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
Definition: FluxioParameter.cpp:161
armarx::skills::FluxioValue::FromIce
static std::optional< FluxioValue > FromIce(const manager::dto::FluxioValue &i, std::map< std::string, FluxioProfile > &profilesMap)
Definition: FluxioValue.cpp:39
FluxioValue.h
armarx::skills::FluxioParameter::description
std::string description
Definition: FluxioParameter.h:27
std::experimental::fundamentals_v2::make_observer
observer_ptr< _Tp > make_observer(_Tp *__p) noexcept
armarx::skills::FluxioParameter::FromFluxioIdentificatorIce
static std::experimental::observer_ptr< const FluxioParameter > FromFluxioIdentificatorIce(const manager::dto::FluxioIdentificator &i, const std::map< std::string, FluxioParameter > &parametersMap)
Definition: FluxioParameter.cpp:129
FluxioProfile.h
std::experimental::fundamentals_v2::observer_ptr
Definition: ManagedIceObject.h:53
armarx::skills::FluxioParameter::FromFluxioIdentificatorAron
static std::experimental::observer_ptr< const FluxioParameter > FromFluxioIdentificatorAron(const manager::arondto::FluxioIdentificator &i, const std::map< std::string, FluxioParameter > &parametersMap)
Definition: FluxioParameter.cpp:145
armarx::skills::FluxioParameter::updateFromIce
void updateFromIce(const manager::dto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
Definition: FluxioParameter.cpp:59
armarx::skills::FluxioParameter::name
std::string name
Definition: FluxioParameter.h:26
armarx::skills::FluxioParameter::typeIdentificator
FluxioTypeIdentificator typeIdentificator
Definition: FluxioParameter.h:28
armarx::skills::FluxioParameter::FromAron
static FluxioParameter FromAron(const manager::arondto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
Definition: FluxioParameter.cpp:193
Object.h
Variant.h
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::skills::FluxioParameter::updateValuesFromAron
void updateValuesFromAron(const std::vector< manager::arondto::FluxioValue > &i, std::map< std::string, FluxioProfile > &profilesMap)
Definition: FluxioParameter.cpp:109
FluxioParameter.h
armarx::skills::FluxioParameter::values
std::list< FluxioValue > values
Definition: FluxioParameter.h:32
armarx::skills::FluxioTypeIdentificator::FromAron
static FluxioTypeIdentificator FromAron(const manager::arondto::FluxioTypeIdentificator &i)
Definition: FluxioTypeIdentificator.cpp:46
armarx::skills::FluxioParameter::toAron
manager::arondto::FluxioParameter toAron() const
Definition: FluxioParameter.cpp:225
armarx::skills::FluxioParameter::isInput
bool isInput
Definition: FluxioParameter.h:31
armarx::skills::FluxioParameter::id
std::string id
Definition: FluxioParameter.h:25
armarx::skills::FluxioTypeIdentificator::skillId
std::string skillId
Definition: FluxioTypeIdentificator.h:13
armarx::skills::FluxioParameter::updateValuesFromIce
void updateValuesFromIce(const manager::dto::FluxioValueList &i, std::map< std::string, FluxioProfile > &profilesMap)
Definition: FluxioParameter.cpp:89
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::skills::FluxioParameter::toFluxioIdentificatorIce
manager::dto::FluxioIdentificator toFluxioIdentificatorIce() const
Definition: FluxioParameter.cpp:50
armarx::skills::FluxioTypeIdentificator::parameterId
std::string parameterId
Definition: FluxioTypeIdentificator.h:14
armarx::skills::FluxioTypeIdentificator::FromIce
static FluxioTypeIdentificator FromIce(const manager::dto::FluxioTypeIdentificator &i)
Definition: FluxioTypeIdentificator.cpp:35
armarx::skills::FluxioTypeIdentificator::toAron
manager::arondto::FluxioTypeIdentificator toAron() const
Definition: FluxioTypeIdentificator.cpp:24
armarx::skills::FluxioParameter::updateFromAron
void updateFromAron(const manager::arondto::FluxioParameter &i, std::map< std::string, FluxioProfile > &profilesMap, std::map< std::string, aron::type::ObjectPtr > &typesMap)
Definition: FluxioParameter.cpp:74
armarx::skills::FluxioParameter::required
bool required
Definition: FluxioParameter.h:30
armarx::skills::FluxioParameter::type
aron::type::VariantPtr type
Definition: FluxioParameter.h:29
Logging.h
armarx::skills::FluxioTypeIdentificator::toManagerIce
manager::dto::FluxioTypeIdentificator toManagerIce() const
Definition: FluxioTypeIdentificator.cpp:13
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::skills::FluxioValue::FromAron
static std::optional< FluxioValue > FromAron(const manager::arondto::FluxioValue &i, std::map< std::string, FluxioProfile > &profilesMap)
Definition: FluxioValue.cpp:58
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
armarx::skills::FluxioParameter::toManagerIce
manager::dto::FluxioParameter toManagerIce() const
Definition: FluxioParameter.cpp:20
armarx::skills::FluxioValue
Definition: FluxioValue.h:17