36 #include <boost/thread/recursive_mutex.hpp>
37 #include <boost/lexical_cast.hpp>
48 typedef std::map<std::string, XmlRpc::XmlRpcValue>
M_Param;
56 while (ns_key !=
"" && ns_key !=
"/")
73 params[1] = mapped_key;
94 void set(
const std::string& key,
const std::string& s)
102 void set(
const std::string& key,
const char* s)
106 std::string sxx = std::string(
s);
111 void set(
const std::string& key,
double d)
117 void set(
const std::string& key,
int i)
123 void set(
const std::string& key,
bool b)
130 void setImpl(
const std::string& key,
const std::vector<T>& vec)
138 for(
size_t i=0; i < vec.size(); i++) {
139 xml_vec[i] = vec.at(i);
145 void set(
const std::string& key,
const std::vector<std::string>& vec)
150 void set(
const std::string& key,
const std::vector<double>& vec)
155 void set(
const std::string& key,
const std::vector<float>& vec)
160 void set(
const std::string& key,
const std::vector<int>& vec)
165 void set(
const std::string& key,
const std::vector<bool>& vec)
171 void setImpl(
const std::string& key,
const std::map<std::string, T>& map)
179 for(
typename std::map<std::string, T>::const_iterator it = map.begin(); it != map.end(); ++it) {
180 xml_value[it->first] = it->second;
186 void set(
const std::string& key,
const std::map<std::string, std::string>& map)
191 void set(
const std::string& key,
const std::map<std::string, double>& map)
196 void set(
const std::string& key,
const std::map<std::string, float>& map)
201 void set(
const std::string& key,
const std::map<std::string, int>& map)
206 void set(
const std::string& key,
const std::map<std::string, bool>& map)
211 bool has(
const std::string& key)
228 bool del(
const std::string& key)
245 params[1] = mapped_key;
260 if (mapped_key.empty()) mapped_key =
"/";
268 M_Param::iterator it =
g_params.find(mapped_key);
271 if (it->second.valid())
290 params[2] = mapped_key;
292 if (!
master::execute(
"subscribeParam", params, result, payload,
false))
303 params[1] = mapped_key;
319 bool getImpl(
const std::string& key, std::string& s,
bool use_cache)
322 if (!
getImpl(key, v, use_cache))
330 bool getImpl(
const std::string& key,
double& d,
bool use_cache)
333 if (!
getImpl(key, v, use_cache))
354 bool getImpl(
const std::string& key,
float& f,
bool use_cache)
356 double d =
static_cast<double>(
f);
357 bool result =
getImpl(key,
d, use_cache);
359 f =
static_cast<float>(
d);
363 bool getImpl(
const std::string& key,
int& i,
bool use_cache)
366 if (!
getImpl(key, v, use_cache))
375 if (fmod(
d, 1.0) < 0.5)
398 bool getImpl(
const std::string& key,
bool& b,
bool use_cache)
401 if (!
getImpl(key, v, use_cache))
409 bool get(
const std::string& key, std::string& s)
414 bool get(
const std::string& key,
double& d)
419 bool get(
const std::string& key,
float& f)
424 bool get(
const std::string& key,
int& i)
429 bool get(
const std::string& key,
bool& b)
471 return static_cast<T
>(xml_value);
479 template<>
bool xml_castable<std::string>(
int XmlType)
520 case XmlRpcValue::TypeDouble:
521 return static_cast<double>(xml_value);
522 case XmlRpcValue::TypeInt:
523 return static_cast<double>(
static_cast<int>(xml_value));
524 case XmlRpcValue::TypeBoolean:
525 return static_cast<double>(
static_cast<bool>(xml_value));
535 case XmlRpcValue::TypeDouble:
536 return static_cast<float>(
static_cast<double>(xml_value));
537 case XmlRpcValue::TypeInt:
538 return static_cast<float>(
static_cast<int>(xml_value));
539 case XmlRpcValue::TypeBoolean:
540 return static_cast<float>(
static_cast<bool>(xml_value));
550 case XmlRpcValue::TypeDouble:
551 return static_cast<int>(
static_cast<double>(xml_value));
552 case XmlRpcValue::TypeInt:
553 return static_cast<int>(xml_value);
554 case XmlRpcValue::TypeBoolean:
555 return static_cast<int>(
static_cast<bool>(xml_value));
565 case XmlRpcValue::TypeDouble:
566 return static_cast<bool>(
static_cast<double>(xml_value));
567 case XmlRpcValue::TypeInt:
568 return static_cast<bool>(
static_cast<int>(xml_value));
569 case XmlRpcValue::TypeBoolean:
570 return static_cast<bool>(xml_value);
577 bool getImpl(
const std::string& key, std::vector<T>& vec,
bool cached)
580 if(!
getImpl(key, xml_array, cached)) {
590 vec.resize(xml_array.
size());
593 for (
int i = 0; i < xml_array.
size(); i++) {
594 if(!xml_castable<T>(xml_array[i].getType())) {
598 vec[i] = xml_cast<T>(xml_array[i]);
604 bool get(
const std::string& key, std::vector<std::string>& vec)
606 return getImpl(key, vec,
false);
608 bool get(
const std::string& key, std::vector<double>& vec)
610 return getImpl(key, vec,
false);
612 bool get(
const std::string& key, std::vector<float>& vec)
614 return getImpl(key, vec,
false);
616 bool get(
const std::string& key, std::vector<int>& vec)
618 return getImpl(key, vec,
false);
620 bool get(
const std::string& key, std::vector<bool>& vec)
622 return getImpl(key, vec,
false);
625 bool getCached(
const std::string& key, std::vector<std::string>& vec)
627 return getImpl(key, vec,
true);
629 bool getCached(
const std::string& key, std::vector<double>& vec)
631 return getImpl(key, vec,
true);
633 bool getCached(
const std::string& key, std::vector<float>& vec)
635 return getImpl(key, vec,
true);
637 bool getCached(
const std::string& key, std::vector<int>& vec)
639 return getImpl(key, vec,
true);
641 bool getCached(
const std::string& key, std::vector<bool>& vec)
643 return getImpl(key, vec,
true);
647 bool getImpl(
const std::string& key, std::map<std::string, T>& map,
bool cached)
650 if(!
getImpl(key, xml_value, cached)) {
660 for (XmlRpc::XmlRpcValue::ValueStruct::const_iterator it = xml_value.
begin();
661 it != xml_value.
end();
665 if(!xml_castable<T>(it->second.getType())) {
669 map[it->first] = xml_cast<T>(it->second);
675 bool get(
const std::string& key, std::map<std::string, std::string>& map)
677 return getImpl(key, map,
false);
679 bool get(
const std::string& key, std::map<std::string, double>& map)
681 return getImpl(key, map,
false);
683 bool get(
const std::string& key, std::map<std::string, float>& map)
685 return getImpl(key, map,
false);
687 bool get(
const std::string& key, std::map<std::string, int>& map)
689 return getImpl(key, map,
false);
691 bool get(
const std::string& key, std::map<std::string, bool>& map)
693 return getImpl(key, map,
false);
696 bool getCached(
const std::string& key, std::map<std::string, std::string>& map)
698 return getImpl(key, map,
true);
700 bool getCached(
const std::string& key, std::map<std::string, double>& map)
702 return getImpl(key, map,
true);
704 bool getCached(
const std::string& key, std::map<std::string, float>& map)
706 return getImpl(key, map,
true);
708 bool getCached(
const std::string& key, std::map<std::string, int>& map)
710 return getImpl(key, map,
true);
712 bool getCached(
const std::string& key, std::map<std::string, bool>& map)
714 return getImpl(key, map,
true);
721 if (!
master::execute(
"getParamNames", params, result, payload,
false)) {
729 if (result.
size() != 3) {
735 keys.resize(parameters.
size());
738 for (
int i = 0; i < parameters.
size(); ++i) {
742 keys[i] = std::string(parameters[i]);
747 bool search(
const std::string& key, std::string& result_out)
752 bool search(
const std::string& ns,
const std::string& key, std::string& result_out)
760 std::string remapped = key;
764 remapped = it->second;
767 params[1] = remapped;
776 result_out = (std::string)payload;
784 ROS_DEBUG_NAMED(
"cached_parameters",
"Received parameter update for key [%s]", clean_key.c_str());
798 result[1] = std::string(
"");
821 const std::string mapped_key(*itr);
828 M_string::const_iterator it = remappings.begin();
829 M_string::const_iterator end = remappings.end();
830 for (; it != end; ++it)
832 const std::string& name = it->first;
833 const std::string&
param = it->second;
840 if (name[0] ==
'_' && name[1] !=
'_')
842 std::string local_name =
"~" + name.substr(1);
844 bool success =
false;
848 int32_t i = boost::lexical_cast<int32_t>(
param);
852 catch (boost::bad_lexical_cast&)
864 double d = boost::lexical_cast<double>(
param);
868 catch (boost::bad_lexical_cast&)