8 #include <boost/shared_ptr.hpp>
9 #include <boost/optional.hpp>
11 #include "exceptions.h"
21 /** @brief A helper class for XML nodes */
26 XMLNode (xmlpp::Node const * node);
28 std::string string_child (std::string);
29 std::string optional_string_child (std::string);
30 ContentKind kind_child (std::string);
31 Fraction fraction_child (std::string);
32 int64_t int64_child (std::string);
33 int64_t optional_int64_child (std::string);
34 float float_child (std::string);
35 void ignore_child (std::string);
38 Time time_attribute (std::string);
39 float float_attribute (std::string);
40 std::string string_attribute (std::string);
41 std::string optional_string_attribute (std::string);
42 int64_t int64_attribute (std::string);
43 int64_t optional_int64_attribute (std::string);
44 boost::optional<bool> optional_bool_attribute (std::string);
45 boost::optional<Color> optional_color_attribute (std::string);
47 std::string content ();
50 boost::shared_ptr<T> type_child (std::string name) {
51 return boost::shared_ptr<T> (new T (node_child (name)));
55 boost::shared_ptr<T> optional_type_child (std::string name) {
56 std::list<xmlpp::Node*> n = node_children (name);
58 throw XMLError ("duplicate XML tag");
59 } else if (n.empty ()) {
60 return boost::shared_ptr<T> ();
63 return boost::shared_ptr<T> (new T (n.front ()));
67 std::list<boost::shared_ptr<T> > type_children (std::string name) {
68 std::list<xmlpp::Node*> n = node_children (name);
69 std::list<boost::shared_ptr<T> > r;
70 for (typename std::list<xmlpp::Node*>::iterator i = n.begin(); i != n.end(); ++i) {
71 r.push_back (boost::shared_ptr<T> (new T (*i)));
77 std::list<boost::shared_ptr<T> > type_grand_children (std::string name, std::string sub) {
78 XMLNode p (node_child (name));
79 return p.type_children<T> (sub);
82 xmlpp::Node const * _node;
85 xmlpp::Node* node_child (std::string);
86 std::list<xmlpp::Node*> node_children (std::string);
87 std::list<Glib::ustring> _taken;
90 /** @brief A helper class for XML files */
91 class XMLFile : public XMLNode
94 XMLFile (std::string file, std::string root_name);
98 xmlpp::DomParser* _parser;