26 if ( !param.defaultValue.empty() &&
27 (param.type ==
"vector<int>" ||
28 param.type ==
"vector<string>" ||
29 param.type ==
"vector<double>"))
32 if (param.type ==
"vector<int>") { typ =
".asInt64()"; }
33 else if (param.type ==
"vector<string>") { typ =
".asString()"; }
34 else if (param.type ==
"vector<double>") { typ =
".asFloat64()"; }
35 s <<
S_TAB1 <<
"//Default value of parameter" << param.getFullParamVariable() <<
"\n";
37 s <<
S_TAB1 <<
" m_" << param.getFullParamVariable() <<
".clear();\n";
38 s <<
S_TAB1 <<
" yarp::os::Value tempVal;\n";
39 s <<
S_TAB1 <<
" tempVal.fromString(m_" << param.getFullParamVariable() <<
"_defaultValue.c_str()" <<
");\n";
40 s <<
S_TAB1 <<
" yarp::os::Bottle* tempBot = tempVal.asList();\n";
41 s <<
S_TAB1 <<
" if (tempBot && tempBot->size()!=0)\n";
43 s <<
S_TAB1 <<
" for (size_t i=0; i<tempBot->size(); i++)\n";
45 s <<
S_TAB1 <<
" m_" << param.getFullParamVariable() <<
".push_back(tempBot->get(i)" << typ <<
");\n";
50 s <<
S_TAB1 <<
" yError() <<" <<
"\"parameter '" << param.getFullParamVariable() <<
"' is not a properly formatted bottle\";\n";
65std::vector<std::string> " <<
m_classname <<
"_ParamsParser::getListOfParams() const\n\
68s <<
S_TAB1 <<
"std::vector<std::string> params;\n";
73 s <<
S_TAB1 <<
"params.push_back(\"" << param.getFullParamName() <<
"\");\n";
77s <<
S_TAB1 <<
"return params;\n\
91 <<
m_classname <<
"_ParamsParser::getConfiguration() const\n\
93 s <<
S_TAB1 <<
"//This is a sub-optimal solution.\n";
94 s <<
S_TAB1 <<
"//Ideally getConfiguration() should return all parameters but it is currently\n";
95 s <<
S_TAB1 <<
"//returning only user provided parameters (excluding default values)\n";
96 s <<
S_TAB1 <<
"//This behaviour will be fixed in the near future.\n";
97 s <<
S_TAB1 <<
"std::string s_cfg = m_provided_configuration;\n";
98 s <<
S_TAB1 <<
"return s_cfg;\n";
105 std::ostringstream s;
109 <<
m_classname <<
"_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const\n\
114 s <<
S_TAB1 <<
"return false\n\
123 const std::string vec2string_string =
"\
124 std::ostringstream oss;\n\
126 for (auto x : m_" + param.getFullParamVariable() +
")\n\
128 oss << x << \" \";\n\
131 paramValue = oss.str();\n";
133 s <<
S_TAB1 <<
"if (paramName ==\"" << param.getFullParamName() <<
"\")\n";
135 if (param.type ==
"string") {
136 s <<
S_TAB1 <<
" paramValue = m_" << param.getFullParamVariable() <<
";\n";
137 s <<
S_TAB1 <<
" return true;\n";
138 }
else if (param.type ==
"bool") {
139 s <<
S_TAB1 <<
" if (m_" << param.getFullParamVariable() <<
"==true) paramValue = \"true\";\n";
140 s <<
S_TAB1 <<
" else paramValue = \"false\";\n";
141 s <<
S_TAB1 <<
" return true;\n";
142 }
else if (param.type ==
"double") {
143 s <<
S_TAB1 <<
" paramValue = std::to_string(m_" << param.getFullParamVariable() <<
");\n";
144 s <<
S_TAB1 <<
" return true;\n";
145 }
else if (param.type ==
"int") {
146 s <<
S_TAB1 <<
" paramValue = std::to_string(m_" << param.getFullParamVariable() <<
");\n";
147 s <<
S_TAB1 <<
" return true;\n";
148 }
else if (param.type ==
"char") {
149 s <<
S_TAB1 <<
" paramValue = std::string(1, m_" << param.getFullParamVariable() <<
");\n";
150 s <<
S_TAB1 <<
" return true;\n";
151 }
else if (param.type ==
"size_t") {
152 s <<
S_TAB1 <<
" paramValue = std::to_string(m_" << param.getFullParamVariable() <<
");\n";
153 s <<
S_TAB1 <<
" return true;\n";
154 }
else if (param.type ==
"float") {
155 s <<
S_TAB1 <<
" paramValue = std::to_string(m_" << param.getFullParamVariable() <<
");\n";
156 s <<
S_TAB1 <<
" return true;\n";
157 }
else if (param.type ==
"char") {
158 s <<
S_TAB1 <<
" return false;\n";
159 }
else if (param.type ==
"vector<int>") {
160 s <<
S_TAB1 << vec2string_string;
161 s <<
S_TAB1 <<
" return true;\n";
162 }
else if (param.type ==
"vector<string>") {
163 s <<
S_TAB1 << vec2string_string;
164 s <<
S_TAB1 <<
" return true;\n";
165 }
else if (param.type ==
"vector<double>") {
166 s <<
S_TAB1 << vec2string_string;
167 s <<
S_TAB1 <<
" return true;\n";
172 s <<
S_TAB1 <<
"yError() <<" <<
"\"parameter '\" << paramName << \"' was not found\";\n";
173 s <<
S_TAB1 <<
"return false;\n";
184 std::ostringstream s;
188 s <<
"std::string " <<
m_classname <<
"_ParamsParser::getDocumentationOfDeviceParams() const\n";
190 s <<
S_TAB1 <<
"std::string doc;\n";
192 s <<
S_TAB1 <<
"doc = doc + std::string(\"\\n=============================================\\n\");\n";
193 s <<
S_TAB1 <<
"doc = doc + std::string(\"This is the help for device: " <<
m_classname <<
"\\n\");\n";
194 s <<
S_TAB1 <<
"doc = doc + std::string(\"\\n\");\n";
195 s <<
S_TAB1 <<
"doc = doc + std::string(\"This is the list of the parameters accepted by the device:\\n\");\n";
199 s <<
S_TAB1 <<
"doc = doc + std::string(\"'" << param.getFullParamName() <<
"': ";
200 s << param.description;
204 s <<
S_TAB1 <<
"doc = doc + std::string(\"\\n\");\n";
205 s <<
S_TAB1 <<
"doc = doc + std::string(\"Here are some examples of invocation command with yarpdev, with all params:\\n\");\n";
207 s <<
S_TAB1 <<
"doc = doc + std::string(\"Using only mandatory params:\\n\");\n";
209 s <<
S_TAB1 <<
"doc = doc + std::string(\"=============================================\\n\\n\");";
210 s <<
S_TAB1 <<
"return doc;\n";
217 if (vec.size()==0)
return;
225 s <<
S_TAB2 <<
"yarp::os::Bottle sectionp" <<
";\n";
226 s <<
S_TAB2 <<
"sectionp" <<
" = config.findGroup(\"" << vec.front() <<
"\");\n";
231 s <<
S_TAB2 <<
"yarp::os::Bottle sectionp" << count <<
";\n";
232 s <<
S_TAB2 <<
"sectionp" << count <<
" = config.findGroup(\"" << vec.front() <<
"\");\n";
241 s <<
S_TAB2 <<
"yarp::os::Bottle sectionp" <<
";\n";
242 s <<
S_TAB2 <<
"sectionp" <<
" = " <<
"sectionp" << count - 1 <<
".findGroup(\"" << vec.front() <<
"\");\n";
247 s <<
S_TAB2 <<
"yarp::os::Bottle sectionp" << count <<
";\n";
248 s <<
S_TAB2 <<
"sectionp" << count <<
" = " <<
"sectionp" << count - 1 <<
".findGroup(\"" << vec.front() <<
"\");\n";
256inline void KK (std::string origin, std::ostringstream& s,
const Parameter& param, std::string as, std::string component)
262inline void AA (std::string origin, std::ostringstream& s,
const Parameter& param, std::string typ, std::string component)
267 s <<
S_TAB3 <<
" yarp::os::Bottle* tempBot = " << origin <<
".find(\"" << param.
getParamOnly() <<
"\").asList();\n";
268 s <<
S_TAB3 <<
" if (tempBot)\n";
270 s <<
S_TAB3 <<
" std::string tempBots = tempBot->toString();\n";
271 s <<
S_TAB3 <<
" for (size_t i=0; i<tempBot->size(); i++)\n";
278 s <<
S_TAB3 <<
" yCError(" << component <<
") <<" <<
"\"parameter '" << param.
getFullParamVariable() <<
"' is not a properly formatted bottle\";\n";
283inline void BB (std::string origin, std::ostringstream& s,
const Parameter& param, std::string typ, std::string component)
288 s <<
S_TAB3 <<
" std::string tempString = "<<origin<<
".find(\"" << param.
getParamOnly() <<
"\").asString();\n";
289 s <<
S_TAB3 <<
" std::istringstream iss(tempString);\n";
290 s <<
S_TAB3 <<
" " << typ <<
" val;\n";
291 s <<
S_TAB3 <<
" while (iss >> val)\n";
298inline void CC(std::string origin, std::ostringstream& s,
const Parameter& param, std::string typ, std::string component)
303 s <<
S_TAB3 <<
" yarp::os::Bottle tempBot = " << origin <<
".findGroup(\"" << param.
getParamOnly() <<
"\");\n";
304 s <<
S_TAB3 <<
" if (tempBot.size()>0)\n";
306 s <<
S_TAB3 <<
" int sizes = tempBot.size();\n";
307 s <<
S_TAB3 <<
" std::string tempBots = tempBot.toString();\n";
308 s <<
S_TAB3 <<
" tempBot = tempBot.tail();\n";
309 s <<
S_TAB3 <<
" for (size_t i=0; i<tempBot.size(); i++)\n";
316 s <<
S_TAB3 <<
" yCError("<< component <<
") << " <<
"\"parameter '" << param.
getFullParamVariable() <<
"' is not a properly formatted bottle\";\n";
329 if (param.
type ==
"string") {
KK(origin, s, param,
".asString()",
m_component); }
330 else if (param.
type ==
"bool") {
KK(origin, s, param,
".asBool()",
m_component); }
331 else if (param.
type ==
"double") {
KK(origin, s, param,
".asFloat64()",
m_component); }
332 else if (param.
type ==
"int") {
KK(origin, s, param,
".asInt64()",
m_component); }
333 else if (param.
type ==
"size_t") {
KK(origin, s, param,
".asInt64()",
m_component); }
334 else if (param.
type ==
"float") {
KK(origin, s, param,
".asFloat32()",
m_component); }
335 else if (param.
type ==
"char") {
KK(origin, s, param,
".asInt8()",
m_component); }
336 else if (param.
type ==
"vector<int>") {
AA(origin, s, param,
".asInt64()",
m_component); }
337 else if (param.
type ==
"vector<string>") {
AA(origin, s, param,
".asString()",
m_component); }
338 else if (param.
type ==
"vector<double>") {
AA(origin, s, param,
".asFloat64()",
m_component); }
368 if (!param.
units.empty())
371 S_TAB3 <<
"yCError(" <<
m_component <<
") << \"Remember: Units for this parameter are: '" << param.
units <<
"'\";\n";
374 S_TAB3 <<
"return false;\n";
392 std::ostringstream s;
395bool "<<
m_classname <<
"_ParamsParser::parseParams(const yarp::os::Searchable & config)\n\
398 s <<
S_TAB1 <<
"//Check for --help option\n";
399 s <<
S_TAB1 <<
"if (config.check(\"help\"))\n";
401 s <<
S_TAB1 <<
" yCInfo(" <<
m_component <<
") << getDocumentationOfDeviceParams();\n";
406 s <<
S_TAB1 <<
"m_provided_configuration = config.toString();\n";
407 s <<
S_TAB1 <<
"yarp::os::Property prop_check(m_provided_configuration.c_str());\n";
411 for (
const auto& param : copy_of_m_params)
413 if (param.getListOfGroups().empty())
415 s <<
S_TAB1 <<
"//Parser of parameter " << param.getParamOnly() <<
"\n";
418 s <<
S_TAB2 <<
"prop_check.unput(\"" << param.getParamOnly() <<
"\");\n";
424 s <<
S_TAB1 <<
"//Parser of parameter " << param.getFullParamName() <<
"\n";
426 auto pg = param.getListOfGroups();
429 s <<
S_TAB2 <<
"prop_check.unput(\"" << param.getFullParamName() <<
"\");\n";
440 s <<
S_TAB1 <<
"//This code check if the user set some parameter which are not check by the parser\n";
441 s <<
S_TAB1 <<
"//If the parser is set in strict mode, this will generate an error\n";
442 s <<
S_TAB1 <<
"if (prop_check.size() > 0)\n";
444 s <<
S_TAB1 <<
" bool extra_params_found = false;\n";
445 s <<
S_TAB1 <<
" for (auto it=prop_check.begin(); it!=prop_check.end(); it++)\n";
447 s <<
S_TAB1 <<
" if (m_parser_is_strict)\n";
449 s <<
S_TAB1 <<
" yCError(" <<
m_component <<
") << \"User asking for parameter: \"<<it->name <<\" which is unknown to this parser!\";\n";
450 s <<
S_TAB1 <<
" extra_params_found = true;\n";
454 s <<
S_TAB1 <<
" yCWarning(" <<
m_component <<
") << \"User asking for parameter: \"<< it->name <<\" which is unknown to this parser!\";\n";
458 s <<
S_TAB1 <<
" if (m_parser_is_strict && extra_params_found)\n";
460 s <<
S_TAB1 <<
" return false;\n";
std::string getParamOnly() const
std::string getFullParamName() const
std::string getFullParamVariable() const
std::string generateFunction_getDocumentationOfDeviceParams()
std::string generateFunction_getParamValue()
std::string generateYarpdevStringAllParams()
void generate_param(std::string origin, std::ostringstream &s, const Parameter ¶m)
std::string generateFunction_getListOfParams()
std::string generateFunction_getConfiguration()
std::string generateFunction_parseParams()
std::deque< Parameter > m_params
void generate_section(std::ostringstream &s, std::deque< std::string > vec, size_t count, size_t siz)
std::string generateConstructor()
std::string generateYarpdevStringMandatoryParamsOnly()
void CC(std::string origin, std::ostringstream &s, const Parameter ¶m, std::string typ, std::string component)
void AA(std::string origin, std::ostringstream &s, const Parameter ¶m, std::string typ, std::string component)
void KK(std::string origin, std::ostringstream &s, const Parameter ¶m, std::string as, std::string component)
void BB(std::string origin, std::ostringstream &s, const Parameter ¶m, std::string typ, std::string component)
#define ADD_DEBUG_COMMENT(out)