#ifndef BASE_XML_UTILS_H #define BASE_XML_UTILS_H #include #include #include using namespace std; //---------------------------------------------------------------- namespace xml_utils { typedef std::map attributes; void build_attributes(attributes &a, char const **attr); template T get_attr(attributes const &attr, string const &key) { attributes::const_iterator it = attr.find(key); if (it == attr.end()) { ostringstream out; out << "could not find attribute: " << key; throw runtime_error(out.str()); } return boost::lexical_cast(it->second); } template boost::optional get_opt_attr(attributes const &attr, string const &key) { typedef boost::optional rtype; attributes::const_iterator it = attr.find(key); if (it == attr.end()) return rtype(); return rtype(boost::lexical_cast(it->second)); } } //---------------------------------------------------------------- #endif