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 s <<
S_TAB1 <<
"if (paramName ==\"" << param.getFullParamName() <<
"\")\n";
125 if (param.type ==
"string") {
126 s <<
S_TAB1 <<
" paramValue = m_" << param.getFullParamVariable() <<
";\n";
127 s <<
S_TAB1 <<
" return true;\n";
128 }
else if (param.type ==
"bool") {
129 s <<
S_TAB1 <<
" if (m_" << param.getFullParamVariable() <<
"==true) paramValue = \"true\";\n";
130 s <<
S_TAB1 <<
" else paramValue = \"false\";\n";
131 s <<
S_TAB1 <<
" return true;\n";
132 }
else if (param.type ==
"double") {
133 s <<
S_TAB1 <<
" paramValue = std::to_string(m_" << param.getFullParamVariable() <<
");\n";
134 s <<
S_TAB1 <<
" return true;\n";
135 }
else if (param.type ==
"int") {
136 s <<
S_TAB1 <<
" paramValue = std::to_string(m_" << param.getFullParamVariable() <<
");\n";
137 s <<
S_TAB1 <<
" return true;\n";
138 }
else if (param.type ==
"size_t") {
139 s <<
S_TAB1 <<
" paramValue = std::to_string(m_" << param.getFullParamVariable() <<
");\n";
140 s <<
S_TAB1 <<
" return true;\n";
141 }
else if (param.type ==
"float") {
142 s <<
S_TAB1 <<
" paramValue = std::to_string(m_" << param.getFullParamVariable() <<
");\n";
143 s <<
S_TAB1 <<
" return true;\n";
144 }
else if (param.type ==
"char") {
145 s <<
S_TAB1 <<
" return false;\n";
146 }
else if (param.type ==
"vector<int>") {
147 s <<
S_TAB1 <<
" return false;\n";
148 }
else if (param.type ==
"vector<string>") {
149 s <<
S_TAB1 <<
" return false;\n";
150 }
else if (param.type ==
"vector<double>") {
151 s <<
S_TAB1 <<
" return false;\n";
156 s <<
S_TAB1 <<
"yError() <<" <<
"\"parameter '\" << paramName << \"' was not found\";\n";
157 s <<
S_TAB1 <<
"return false;\n";
168 std::ostringstream s;
172 s <<
"std::string " <<
m_classname <<
"_ParamsParser::getDocumentationOfDeviceParams() const\n";
174 s <<
S_TAB1 <<
"std::string doc;\n";
176 s <<
S_TAB1 <<
"doc = doc + std::string(\"\\n=============================================\\n\");\n";
177 s <<
S_TAB1 <<
"doc = doc + std::string(\"This is the help for device: " <<
m_classname <<
"\\n\");\n";
178 s <<
S_TAB1 <<
"doc = doc + std::string(\"\\n\");\n";
179 s <<
S_TAB1 <<
"doc = doc + std::string(\"This is the list of the parameters accepted by the device:\\n\");\n";
183 s <<
S_TAB1 <<
"doc = doc + std::string(\"'" << param.getFullParamName() <<
"': ";
184 s << param.description;
188 s <<
S_TAB1 <<
"doc = doc + std::string(\"\\n\");\n";
189 s <<
S_TAB1 <<
"doc = doc + std::string(\"Here are some examples of invocation command with yarpdev, with all params:\\n\");\n";
191 s <<
S_TAB1 <<
"doc = doc + std::string(\"Using only mandatory params:\\n\");\n";
193 s <<
S_TAB1 <<
"doc = doc + std::string(\"=============================================\\n\\n\");";
194 s <<
S_TAB1 <<
"return doc;\n";
201 if (vec.size()==0)
return;
209 s <<
S_TAB2 <<
"yarp::os::Bottle sectionp" <<
";\n";
210 s <<
S_TAB2 <<
"sectionp" <<
" = config.findGroup(\"" << vec.front() <<
"\");\n";
215 s <<
S_TAB2 <<
"yarp::os::Bottle sectionp" << count <<
";\n";
216 s <<
S_TAB2 <<
"sectionp" << count <<
" = config.findGroup(\"" << vec.front() <<
"\");\n";
225 s <<
S_TAB2 <<
"yarp::os::Bottle sectionp" <<
";\n";
226 s <<
S_TAB2 <<
"sectionp" <<
" = " <<
"sectionp" << count - 1 <<
".findGroup(\"" << vec.front() <<
"\");\n";
231 s <<
S_TAB2 <<
"yarp::os::Bottle sectionp" << count <<
";\n";
232 s <<
S_TAB2 <<
"sectionp" << count <<
" = " <<
"sectionp" << count - 1 <<
".findGroup(\"" << vec.front() <<
"\");\n";
240inline void KK (std::string origin, std::ostringstream& s,
const Parameter& param, std::string as, std::string component)
246inline void AA (std::string origin, std::ostringstream& s,
const Parameter& param, std::string typ, std::string component)
251 s <<
S_TAB3 <<
" yarp::os::Bottle* tempBot = " << origin <<
".find(\"" << param.
getParamOnly() <<
"\").asList();\n";
252 s <<
S_TAB3 <<
" if (tempBot)\n";
254 s <<
S_TAB3 <<
" std::string tempBots = tempBot->toString();\n";
255 s <<
S_TAB3 <<
" for (size_t i=0; i<tempBot->size(); i++)\n";
262 s <<
S_TAB3 <<
" yCError(" << component <<
") <<" <<
"\"parameter '" << param.
getFullParamVariable() <<
"' is not a properly formatted bottle\";\n";
267inline void BB (std::string origin, std::ostringstream& s,
const Parameter& param, std::string typ, std::string component)
272 s <<
S_TAB3 <<
" std::string tempString = "<<origin<<
".find(\"" << param.
getParamOnly() <<
"\").asString();\n";
273 s <<
S_TAB3 <<
" std::istringstream iss(tempString);\n";
274 s <<
S_TAB3 <<
" " << typ <<
" val;\n";
275 s <<
S_TAB3 <<
" while (iss >> val)\n";
282inline void CC(std::string origin, std::ostringstream& s,
const Parameter& param, std::string typ, std::string component)
287 s <<
S_TAB3 <<
" yarp::os::Bottle tempBot = " << origin <<
".findGroup(\"" << param.
getParamOnly() <<
"\");\n";
288 s <<
S_TAB3 <<
" if (tempBot.size()>0)\n";
290 s <<
S_TAB3 <<
" int sizes = tempBot.size();\n";
291 s <<
S_TAB3 <<
" std::string tempBots = tempBot.toString();\n";
292 s <<
S_TAB3 <<
" tempBot = tempBot.tail();\n";
293 s <<
S_TAB3 <<
" for (size_t i=0; i<tempBot.size(); i++)\n";
300 s <<
S_TAB3 <<
" yCError("<< component <<
") << " <<
"\"parameter '" << param.
getFullParamVariable() <<
"' is not a properly formatted bottle\";\n";
313 if (param.
type ==
"string") {
KK(origin, s, param,
".asString()",
m_component); }
314 else if (param.
type ==
"bool") {
KK(origin, s, param,
".asBool()",
m_component); }
315 else if (param.
type ==
"double") {
KK(origin, s, param,
".asFloat64()",
m_component); }
316 else if (param.
type ==
"int") {
KK(origin, s, param,
".asInt64()",
m_component); }
317 else if (param.
type ==
"size_t") {
KK(origin, s, param,
".asInt64()",
m_component); }
318 else if (param.
type ==
"float") {
KK(origin, s, param,
".asFloat32()",
m_component); }
319 else if (param.
type ==
"char") {
KK(origin, s, param,
".asInt8()",
m_component); }
320 else if (param.
type ==
"vector<int>") {
AA(origin, s, param,
".asInt64()",
m_component); }
321 else if (param.
type ==
"vector<string>") {
AA(origin, s, param,
".asString()",
m_component); }
322 else if (param.
type ==
"vector<double>") {
AA(origin, s, param,
".asFloat64()",
m_component); }
352 if (!param.
units.empty())
355 S_TAB3 <<
"yCError(" <<
m_component <<
") << \"Remember: Units for this parameter are: '" << param.
units <<
"'\";\n";
358 S_TAB3 <<
"return false;\n";
376 std::ostringstream s;
379bool "<<
m_classname <<
"_ParamsParser::parseParams(const yarp::os::Searchable & config)\n\
382 s <<
S_TAB1 <<
"//Check for --help option\n";
383 s <<
S_TAB1 <<
"if (config.check(\"help\"))\n";
385 s <<
S_TAB1 <<
" yCInfo(" <<
m_component <<
") << getDocumentationOfDeviceParams();\n";
390 s <<
S_TAB1 <<
"m_provided_configuration = config.toString();\n";
391 s <<
S_TAB1 <<
"yarp::os::Property prop_check(m_provided_configuration.c_str());\n";
395 for (
const auto& param : copy_of_m_params)
397 if (param.getListOfGroups().empty())
399 s <<
S_TAB1 <<
"//Parser of parameter " << param.getParamOnly() <<
"\n";
402 s <<
S_TAB2 <<
"prop_check.unput(\"" << param.getParamOnly() <<
"\");\n";
408 s <<
S_TAB1 <<
"//Parser of parameter " << param.getFullParamName() <<
"\n";
410 auto pg = param.getListOfGroups();
413 s <<
S_TAB2 <<
"prop_check.unput(\"" << param.getFullParamName() <<
"\");\n";
424 s <<
S_TAB1 <<
"//This code check if the user set some parameter which are not check by the parser\n";
425 s <<
S_TAB1 <<
"//If the parser is set in strict mode, this will generate an error\n";
426 s <<
S_TAB1 <<
"if (prop_check.size() > 0)\n";
428 s <<
S_TAB1 <<
" bool extra_params_found = false;\n";
429 s <<
S_TAB1 <<
" for (auto it=prop_check.begin(); it!=prop_check.end(); it++)\n";
431 s <<
S_TAB1 <<
" if (m_parser_is_strict)\n";
433 s <<
S_TAB1 <<
" yCError(" <<
m_component <<
") << \"User asking for parameter: \"<<it->name <<\" which is unknown to this parser!\";\n";
434 s <<
S_TAB1 <<
" extra_params_found = true;\n";
438 s <<
S_TAB1 <<
" yCWarning(" <<
m_component <<
") << \"User asking for parameter: \"<< it->name <<\" which is unknown to this parser!\";\n";
442 s <<
S_TAB1 <<
" if (m_parser_is_strict && extra_params_found)\n";
444 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)