#ifndef LIBDCP_XML_H #define LIBDCP_XML_H #include #include #include #include #include #include #include "types.h" #include "exceptions.h" #include "dcp_time.h" namespace xmlpp { class Node; class DomParser; } namespace libdcp { class XMLNode { public: XMLNode (); XMLNode (xmlpp::Node const * node); protected: std::string string_child (std::string); std::string optional_string_child (std::string); ContentKind kind_child (std::string); Fraction fraction_child (std::string); int64_t int64_child (std::string); int64_t optional_int64_child (std::string); float float_child (std::string); void ignore_child (std::string); void done (); Time time_attribute (std::string); float float_attribute (std::string); std::string string_attribute (std::string); std::string optional_string_attribute (std::string); int64_t int64_attribute (std::string); int64_t optional_int64_attribute (std::string); boost::optional optional_bool_attribute (std::string); boost::optional optional_color_attribute (std::string); std::string content (); template boost::shared_ptr type_child (std::string name) { return boost::shared_ptr (new T (node_child (name))); } template boost::shared_ptr optional_type_child (std::string name) { std::list n = node_children (name); if (n.size() > 1) { throw XMLError ("duplicate XML tag"); } else if (n.empty ()) { return boost::shared_ptr (); } return boost::shared_ptr (new T (n.front ())); } template std::list > type_children (std::string name) { std::list n = node_children (name); std::list > r; for (typename std::list::iterator i = n.begin(); i != n.end(); ++i) { r.push_back (boost::shared_ptr (new T (*i))); } return r; } template std::list > type_grand_children (std::string name, std::string sub) { XMLNode p (node_child (name)); return p.type_children (sub); } xmlpp::Node const * _node; private: xmlpp::Node* node_child (std::string); std::list node_children (std::string); std::list _taken; }; class XMLFile : public XMLNode { public: XMLFile (std::string file, std::string root_name); virtual ~XMLFile (); private: xmlpp::DomParser* _parser; }; } #endif