update
This commit is contained in:
@@ -283,6 +283,14 @@ namespace robot
|
||||
*/
|
||||
bool getParam (const std::string &key, YAML::Node &v, YAML::Node default_value = YAML::Node()) const;
|
||||
|
||||
/**
|
||||
* @brief Get a parameter as robot_xmlrpcpp::XmlRpcValue (converted from YAML).
|
||||
* @param key The parameter key (supports nested keys with '/' separator).
|
||||
* @param v Storage for the retrieved value. Left unchanged if key not found.
|
||||
* @return true if the parameter was retrieved and converted successfully, false otherwise.
|
||||
*/
|
||||
bool getParam (const std::string &key, robot_xmlrpcpp::XmlRpcValue &v) const;
|
||||
|
||||
/**
|
||||
* @brief Template method to get a parameter value (without default).
|
||||
*
|
||||
|
||||
@@ -2,11 +2,17 @@
|
||||
#define ROBOT_ROBOT_H
|
||||
|
||||
#include <robot/init.h>
|
||||
#include <robot/time.h>
|
||||
#include <robot/timer.h>
|
||||
#include <robot/rate.h>
|
||||
#include <robot/console.h>
|
||||
#include <robot/node_handle.h>
|
||||
#include <robot/plugin_loader_helper.h>
|
||||
|
||||
|
||||
#include <robot/time.h>
|
||||
#include <robot/timer.h>
|
||||
#include <robot/duration.h>
|
||||
#include <robot/wall_timer.h>
|
||||
#include <robot/rate.h>
|
||||
#include <robot/exception.h>
|
||||
#include <robot/macros.h>
|
||||
#include <robot/platform.h>
|
||||
#endif
|
||||
@@ -1727,6 +1727,87 @@ namespace robot
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
bool yamlToXmlRpc(const YAML::Node &y, robot_xmlrpcpp::XmlRpcValue &out)
|
||||
{
|
||||
if (!y.IsDefined())
|
||||
return false;
|
||||
if (y.IsScalar())
|
||||
{
|
||||
try
|
||||
{
|
||||
std::string s = y.as<std::string>();
|
||||
std::string lower = s;
|
||||
std::transform(lower.begin(), lower.end(), lower.begin(), ::tolower);
|
||||
if (lower == "true" || lower == "1" || lower == "yes" || lower == "on")
|
||||
{
|
||||
out = robot_xmlrpcpp::XmlRpcValue(true);
|
||||
return true;
|
||||
}
|
||||
if (lower == "false" || lower == "0" || lower == "no" || lower == "off")
|
||||
{
|
||||
out = robot_xmlrpcpp::XmlRpcValue(false);
|
||||
return true;
|
||||
}
|
||||
try
|
||||
{
|
||||
int i = y.as<int>();
|
||||
out = robot_xmlrpcpp::XmlRpcValue(i);
|
||||
return true;
|
||||
}
|
||||
catch (...) {}
|
||||
try
|
||||
{
|
||||
double d = y.as<double>();
|
||||
out = robot_xmlrpcpp::XmlRpcValue(d);
|
||||
return true;
|
||||
}
|
||||
catch (...) {}
|
||||
out = robot_xmlrpcpp::XmlRpcValue(s);
|
||||
return true;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (y.IsSequence())
|
||||
{
|
||||
out = robot_xmlrpcpp::XmlRpcValue();
|
||||
out.setSize(static_cast<int>(y.size()));
|
||||
for (size_t i = 0; i < y.size(); ++i)
|
||||
{
|
||||
robot_xmlrpcpp::XmlRpcValue item;
|
||||
if (yamlToXmlRpc(y[i], item))
|
||||
out[static_cast<int>(i)] = item;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (y.IsMap())
|
||||
{
|
||||
out = robot_xmlrpcpp::XmlRpcValue();
|
||||
for (YAML::const_iterator it = y.begin(); it != y.end(); ++it)
|
||||
{
|
||||
std::string k = it->first.as<std::string>();
|
||||
robot_xmlrpcpp::XmlRpcValue item;
|
||||
if (yamlToXmlRpc(it->second, item))
|
||||
out[k] = item;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool NodeHandle::getParam(const std::string &key, robot_xmlrpcpp::XmlRpcValue &v) const
|
||||
{
|
||||
YAML::Node value = getNestedValue(key);
|
||||
if (!value.IsDefined())
|
||||
return false;
|
||||
return yamlToXmlRpc(value, v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T NodeHandle::param(const std::string ¶m_name) const
|
||||
{
|
||||
|
||||
Submodule src/Libraries/robot_time updated: 750dc94c61...8201dcc6bd
Reference in New Issue
Block a user