YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeBot_ParamsParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6
7// Generated by yarpDeviceParamParserGenerator (2.0)
8// This is an automatically generated file. Please do not edit it.
9// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.
10
11// Generated on: Thu May 22 11:32:30 2025
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(FakeBotParamsCOMPONENT, "yarp.device.FakeBot")
20}
21
22
26
27
28std::vector<std::string> FakeBot_ParamsParser::getListOfParams() const
29{
30 std::vector<std::string> params;
31 params.push_back("background");
32 params.push_back("target");
33 params.push_back("noise");
34 params.push_back("sx");
35 params.push_back("sy");
36 params.push_back("lifetime");
37 return params;
38}
39
40
41bool FakeBot_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
42{
43 if (paramName =="background")
44 {
45 paramValue = m_background;
46 return true;
47 }
48 if (paramName =="target")
49 {
50 paramValue = m_target;
51 return true;
52 }
53 if (paramName =="noise")
54 {
55 paramValue = std::to_string(m_noise);
56 return true;
57 }
58 if (paramName =="sx")
59 {
60 paramValue = std::to_string(m_sx);
61 return true;
62 }
63 if (paramName =="sy")
64 {
65 paramValue = std::to_string(m_sy);
66 return true;
67 }
68 if (paramName =="lifetime")
69 {
70 paramValue = std::to_string(m_lifetime);
71 return true;
72 }
73
74 yError() <<"parameter '" << paramName << "' was not found";
75 return false;
76
77}
78
79
81{
82 //This is a sub-optimal solution.
83 //Ideally getConfiguration() should return all parameters but it is currently
84 //returning only user provided parameters (excluding default values)
85 //This behaviour will be fixed in the near future.
86 std::string s_cfg = m_provided_configuration;
87 return s_cfg;
88}
89
91{
92 //Check for --help option
93 if (config.check("help"))
94 {
95 yCInfo(FakeBotParamsCOMPONENT) << getDocumentationOfDeviceParams();
96 }
97
100 //Parser of parameter background
101 {
102 if (config.check("background"))
103 {
104 m_background = config.find("background").asString();
105 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'background' using value:" << m_background;
106 }
107 else
108 {
109 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'background' using DEFAULT value:" << m_background;
110 }
111 prop_check.unput("background");
112 }
113
114 //Parser of parameter target
115 {
116 if (config.check("target"))
117 {
118 m_target = config.find("target").asString();
119 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'target' using value:" << m_target;
120 }
121 else
122 {
123 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'target' using DEFAULT value:" << m_target;
124 }
125 prop_check.unput("target");
126 }
127
128 //Parser of parameter noise
129 {
130 if (config.check("noise"))
131 {
132 m_noise = config.find("noise").asFloat64();
133 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'noise' using value:" << m_noise;
134 }
135 else
136 {
137 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'noise' using DEFAULT value:" << m_noise;
138 }
139 prop_check.unput("noise");
140 }
141
142 //Parser of parameter sx
143 {
144 if (config.check("sx"))
145 {
146 m_sx = config.find("sx").asFloat64();
147 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'sx' using value:" << m_sx;
148 }
149 else
150 {
151 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'sx' using DEFAULT value:" << m_sx;
152 }
153 prop_check.unput("sx");
154 }
155
156 //Parser of parameter sy
157 {
158 if (config.check("sy"))
159 {
160 m_sy = config.find("sy").asFloat64();
161 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'sy' using value:" << m_sy;
162 }
163 else
164 {
165 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'sy' using DEFAULT value:" << m_sy;
166 }
167 prop_check.unput("sy");
168 }
169
170 //Parser of parameter lifetime
171 {
172 if (config.check("lifetime"))
173 {
174 m_lifetime = config.find("lifetime").asFloat64();
175 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'lifetime' using value:" << m_lifetime;
176 }
177 else
178 {
179 yCInfo(FakeBotParamsCOMPONENT) << "Parameter 'lifetime' using DEFAULT value:" << m_lifetime;
180 }
181 prop_check.unput("lifetime");
182 }
183
184 /*
185 //This code check if the user set some parameter which are not check by the parser
186 //If the parser is set in strict mode, this will generate an error
187 if (prop_check.size() > 0)
188 {
189 bool extra_params_found = false;
190 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
191 {
192 if (m_parser_is_strict)
193 {
194 yCError(FakeBotParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
195 extra_params_found = true;
196 }
197 else
198 {
199 yCWarning(FakeBotParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
200 }
201 }
202
203 if (m_parser_is_strict && extra_params_found)
204 {
205 return false;
206 }
207 }
208 */
209 return true;
210}
211
212
214{
215 std::string doc;
216 doc = doc + std::string("\n=============================================\n");
217 doc = doc + std::string("This is the help for device: FakeBot\n");
218 doc = doc + std::string("\n");
219 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
220 doc = doc + std::string("'background': background image to use\n");
221 doc = doc + std::string("'target': target image to use\n");
222 doc = doc + std::string("'noise': pixel noise level\n");
223 doc = doc + std::string("'sx': scaling for x coordinate\n");
224 doc = doc + std::string("'sy': scaling for y coordinate\n");
225 doc = doc + std::string("'lifetime': device should exist for this length of time\n");
226 doc = doc + std::string("\n");
227 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
228 doc = doc + " yarpdev --device fakebot --background textures/back.ppm --target textures/fore.ppm --noise 0.05 --sx 1.0 --sy 1.0 --lifetime -1.0\n";
229 doc = doc + std::string("Using only mandatory params:\n");
230 doc = doc + " yarpdev --device fakebot\n";
231 doc = doc + std::string("=============================================\n\n"); return doc;
232}
#define yError(...)
Definition Log.h:361
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
std::string getConfiguration() const override
Return the configuration of the device.
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
A class for storing options and configuration information.
Definition Property.h:33
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
#define yCInfo(component,...)
#define YARP_LOG_COMPONENT(name,...)