YARP
Yet Another Robot Platform
Types.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
7 
9 
10 #include <yarp/os/LogStream.h>
11 
12 #include <sstream>
13 #include <string>
14 
15 
16 bool yarp::robotinterface::hasParam(const yarp::robotinterface::ParamList& list, const std::string& name)
17 {
18  for (const auto& param : list) {
19  if (name == param.name()) {
20  return true;
21  }
22  }
23  return false;
24 }
25 
26 std::string yarp::robotinterface::findParam(const yarp::robotinterface::ParamList& list, const std::string& name)
27 {
28  for (const auto& param : list) {
29  if (name == param.name()) {
30  return param.value();
31  }
32  }
33  yError() << "Param" << name << "not found";
34  return {};
35 }
36 
37 bool yarp::robotinterface::hasGroup(const yarp::robotinterface::ParamList& list, const std::string& name)
38 {
39  for (const auto& param : list) {
40  if (param.isGroup() && name == param.name()) {
41  return true;
42  }
43  }
44  return false;
45 }
46 
47 std::string yarp::robotinterface::findGroup(const yarp::robotinterface::ParamList& list, const std::string& name)
48 {
49  for (const auto& param : list) {
50  if (param.isGroup() && name == param.name()) {
51  return param.value();
52  }
53  }
54  yError() << "Param" << name << "not found";
55  return {};
56 }
57 
59 {
60  yarp::robotinterface::ParamList params = list;
61  for (auto it1 = params.begin(); it1 != params.end(); ++it1) {
62  yarp::robotinterface::Param& param1 = *it1;
63  for (auto it2 = it1 + 1; it2 != params.end();) {
64  yarp::robotinterface::Param& param2 = *it2;
65  if (param1.name() == param2.name()) {
66  if (!param1.isGroup() || !param2.isGroup()) {
67  yFatal() << "Duplicate parameter \"" << param1.name() << "\" found and at least one of them is not a group.";
68  }
69  param1.value() += std::string(" ");
70  param1.value() += param2.value();
71  it2 = params.erase(it2);
72  } else {
73  it2++;
74  }
75  }
76  }
77  return params;
78 }
79 
80 
82 {
83  if (phase == "startup") {
85  } else if (phase == "run") {
87  } else if (phase == "interrupt1") {
89  } else if (phase == "interrupt2") {
91  } else if (phase == "interrupt3") {
93  } else if (phase == "shutdown") {
95  }
97 }
98 
100 {
101  switch (actionphase) {
103  return std::string("startup");
105  return std::string("run");
107  return std::string("interrupt1");
109  return std::string("interrupt2");
111  return std::string("interrupt3");
113  return std::string("shutdown");
115  default:
116  return {};
117  }
118 }
119 
120 void yarp::robotinterface::operator>>(const std::stringstream& sstream, yarp::robotinterface::ActionPhase& actionphase)
121 {
122  actionphase = yarp::robotinterface::StringToActionPhase(sstream.str());
123 }
124 
125 
127 {
128  if (type == "configure") {
130  } else if (type == "calibrate") {
132  } else if (type == "attach") {
134  } else if (type == "abort") {
136  } else if (type == "detach") {
138  } else if (type == "park") {
140  } else if (type == "custom") {
142  } else {
144  }
145 }
146 
148 {
149  switch (actiontype) {
151  return std::string("configure");
153  return std::string("calibrate");
155  return std::string("attach");
157  return std::string("abort");
159  return std::string("detach");
161  return std::string("park");
163  return std::string("custom");
165  default:
166  return {};
167  }
168 }
169 
170 void yarp::robotinterface::operator>>(const std::stringstream& sstream, yarp::robotinterface::ActionType& actiontype)
171 {
172  actiontype = yarp::robotinterface::StringToActionType(sstream.str());
173 }
#define yError(...)
Definition: Log.h:279
#define yFatal(...)
Definition: Log.h:290
std::string & name()
Definition: Param.cpp:80
std::string & value()
Definition: Param.cpp:85
robotinterface::ParamList mergeDuplicateGroups(const robotinterface::ParamList &list)
Definition: Types.cpp:58
std::string ActionTypeToString(robotinterface::ActionType actiontype)
Definition: Types.cpp:147
void operator>>(const std::stringstream &sstream, robotinterface::ActionPhase &actionphase)
Definition: Types.cpp:120
bool hasParam(const robotinterface::ParamList &list, const std::string &name)
Definition: Types.cpp:16
std::vector< robotinterface::Param > ParamList
Definition: Types.h:28
std::string findGroup(const robotinterface::ParamList &list, const std::string &name)
Definition: Types.cpp:47
robotinterface::ActionPhase StringToActionPhase(const std::string &phase)
Definition: Types.cpp:81
robotinterface::ActionType StringToActionType(const std::string &type)
Definition: Types.cpp:126
bool hasGroup(const robotinterface::ParamList &list, const std::string &name)
Definition: Types.cpp:37
std::string findParam(const robotinterface::ParamList &list, const std::string &name)
Definition: Types.cpp:26
std::string ActionPhaseToString(robotinterface::ActionPhase actionphase)
Definition: Types.cpp:99