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