}
+string
+cxml::Node::name () const
+{
+ assert (_node);
+ return _node->get_name ();
+}
+
shared_ptr<cxml::Node>
-cxml::Node::node_child (string name)
+cxml::Node::node_child (string name) const
{
list<shared_ptr<cxml::Node> > n = node_children (name);
if (n.size() > 1) {
return n.front ();
}
+shared_ptr<cxml::Node>
+cxml::Node::optional_node_child (string name) const
+{
+ list<shared_ptr<cxml::Node> > n = node_children (name);
+ if (n.size() > 1) {
+ throw cxml::Error ("duplicate XML tag " + name);
+ } else if (n.empty ()) {
+ return shared_ptr<cxml::Node> ();
+ }
+
+ return n.front ();
+}
+
list<shared_ptr<cxml::Node> >
-cxml::Node::node_children (string name)
+cxml::Node::node_children (string name) const
{
/* XXX: using find / get_path should work here, but I can't follow
how get_path works.
}
string
-cxml::Node::string_child (string c)
+cxml::Node::string_child (string c) const
{
return node_child(c)->content ();
}
optional<string>
-cxml::Node::optional_string_child (string c)
+cxml::Node::optional_string_child (string c) const
{
list<shared_ptr<Node> > nodes = node_children (c);
if (nodes.size() > 1) {
}
bool
-cxml::Node::bool_child (string c)
+cxml::Node::bool_child (string c) const
{
string const s = string_child (c);
return (s == "1" || s == "yes");
}
optional<bool>
-cxml::Node::optional_bool_child (string c)
+cxml::Node::optional_bool_child (string c) const
{
optional<string> s = optional_string_child (c);
if (!s) {
}
void
-cxml::Node::ignore_child (string name)
+cxml::Node::ignore_child (string name) const
{
_taken.push_back (name);
}
string
-cxml::Node::string_attribute (string name)
+cxml::Node::string_attribute (string name) const
{
xmlpp::Element const * e = dynamic_cast<const xmlpp::Element *> (_node);
if (!e) {
}
optional<string>
-cxml::Node::optional_string_attribute (string name)
+cxml::Node::optional_string_attribute (string name) const
{
xmlpp::Element const * e = dynamic_cast<const xmlpp::Element *> (_node);
if (!e) {
}
bool
-cxml::Node::bool_attribute (string name)
+cxml::Node::bool_attribute (string name) const
{
string const s = string_attribute (name);
return (s == "1" || s == "yes");
}
optional<bool>
-cxml::Node::optional_bool_attribute (string name)
+cxml::Node::optional_bool_attribute (string name) const
{
optional<string> s = optional_string_attribute (name);
if (!s) {
}
void
-cxml::Node::done ()
+cxml::Node::done () const
{
xmlpp::Node::NodeList c = _node->get_children ();
for (xmlpp::Node::NodeList::iterator i = c.begin(); i != c.end(); ++i) {
}
string
-cxml::Node::content ()
+cxml::Node::content () const
{
string content;
#include <boost/optional.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/erase.hpp>
+#include <glibmm.h>
namespace xmlpp {
class Node;
*/
Node (xmlpp::Node const * node);
+ std::string name () const;
+
/* A set of methods which look up a child of this node by
* its name, and return its contents as some type or other.
*
* than one of the specified child node.
*/
- std::string string_child (std::string c);
- boost::optional<std::string> optional_string_child (std::string);
+ std::string string_child (std::string c) const;
+ boost::optional<std::string> optional_string_child (std::string) const;
- bool bool_child (std::string);
- boost::optional<bool> optional_bool_child (std::string);
+ bool bool_child (std::string) const;
+ boost::optional<bool> optional_bool_child (std::string) const;
template <class T>
- T numerical_child (std::string c)
+ T numerical_child (std::string c) const
{
std::string s = string_child (c);
boost::erase_all (s, " ");
}
template <class T>
- boost::optional<T> optional_numerical_child (std::string c)
+ boost::optional<T> optional_numerical_child (std::string c) const
{
boost::optional<std::string> s = optional_string_child (c);
if (!s) {
}
/** This will mark a child as to be ignored when calling done() */
- void ignore_child (std::string);
+ void ignore_child (std::string) const;
/** Check whether all children of this Node have been looked up
* or passed to ignore_child(). If not, an exception is thrown.
*/
- void done ();
+ void done () const;
/* These methods look for an attribute of this node, in the
* same way as the child methods do.
*/
- std::string string_attribute (std::string);
- boost::optional<std::string> optional_string_attribute (std::string);
+ std::string string_attribute (std::string) const;
+ boost::optional<std::string> optional_string_attribute (std::string) const;
- bool bool_attribute (std::string);
- boost::optional<bool> optional_bool_attribute (std::string);
+ bool bool_attribute (std::string) const;
+ boost::optional<bool> optional_bool_attribute (std::string) const;
template <class T>
- T numerical_attribute (std::string c)
+ T numerical_attribute (std::string c) const
{
std::string s = string_attribute (c);
boost::erase_all (s, " ");
}
template <class T>
- boost::optional<T> optional_numerical_attribute (std::string c)
+ boost::optional<T> optional_numerical_attribute (std::string c) const
{
boost::optional<std::string> s = optional_string_attribute (c);
if (!s) {
}
/** @return The content of this node */
- std::string content ();
+ std::string content () const;
- boost::shared_ptr<Node> node_child (std::string);
- boost::shared_ptr<Node> optional_node_child (std::string);
+ boost::shared_ptr<Node> node_child (std::string) const;
+ boost::shared_ptr<Node> optional_node_child (std::string) const;
- std::list<boost::shared_ptr<Node> > node_children (std::string);
+ std::list<boost::shared_ptr<Node> > node_children (std::string) const;
protected:
xmlpp::Node const * _node;
private:
- std::list<Glib::ustring> _taken;
+ mutable std::list<Glib::ustring> _taken;
};
class File : public Node