1 #ifndef RADIAL_MENU_MODEL_XML_ELEMENT_HPP 2 #define RADIAL_MENU_MODEL_XML_ELEMENT_HPP 11 #include <boost/optional.hpp> 12 #include <boost/property_tree/exceptions.hpp> 13 #include <boost/property_tree/ptree.hpp> 14 #include <boost/property_tree/xml_parser.hpp> 24 XmlElement(
const std::shared_ptr< const boost::property_tree::ptree > &xml,
25 const boost::property_tree::ptree::value_type *
const elm)
32 const std::string &
name()
const {
return elm_->first; }
35 template <
typename T > T
attribute(
const std::string &key,
const T &default_val)
const {
36 return elm_->second.get(
"<xmlattr>." + key, default_val);
40 template <
typename T >
bool getAttribute(
const std::string &key, T *
const val)
const {
41 const boost::optional< T > opt_val(
elm_->second.get_optional< T >(
"<xmlattr>." + key));
51 for (
const boost::property_tree::ptree::value_type &child_elm :
elm_->second) {
52 if (child_elm.first !=
"<xmlattr>") {
60 std::vector< XmlElementConstPtr > elms;
61 for (
const boost::property_tree::ptree::value_type &child_elm :
elm_->second) {
62 if (child_elm.first !=
"<xmlattr>") {
69 static XmlElementConstPtr
fromString(
const std::string &str) {
70 namespace bpt = boost::property_tree;
73 const std::shared_ptr< bpt::ptree > xml(
new bpt::ptree());
75 std::istringstream iss(str);
76 bpt::read_xml(iss, *xml, bpt::xml_parser::no_comments);
77 }
catch (
const bpt::ptree_error &ex) {
84 ROS_ERROR(
"XmlElement::fromString(): No root element in xml");
86 }
else if (xml->size() >= 2) {
87 ROS_ERROR(
"XmlElement::fromString(): Multiple root elements in xml");
96 const std::shared_ptr< const boost::property_tree::ptree >
xml_;
97 const boost::property_tree::ptree::value_type *
const elm_;
#define ROS_ERROR_STREAM(args)