X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fxml.h;h=acace8461e2be49c5a597e66f4f78e9b24c80059;hb=ea1e0300d6b0d4e3dbdcaaeb20affb5c3ae49214;hp=e5667b8f10a16db269e128dabe75a763f304ab91;hpb=2cd9086c95686117ffbce92188d50d525ed488bb;p=libdcp.git diff --git a/src/xml.h b/src/xml.h index e5667b8f..acace846 100644 --- a/src/xml.h +++ b/src/xml.h @@ -6,8 +6,10 @@ #include #include #include +#include #include "types.h" #include "exceptions.h" +#include "dcp_time.h" namespace xmlpp { class Node; @@ -22,25 +24,35 @@ public: XMLNode (); XMLNode (xmlpp::Node const * node); -protected: - std::string string_node (std::string); - std::string optional_string_node (std::string); - ContentKind kind_node (std::string); - Fraction fraction_node (std::string); - int64_t int64_node (std::string); - int64_t optional_int64_node (std::string); - float float_node (std::string); - void ignore_node (std::string); + 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 sub_node (std::string name) { - return boost::shared_ptr (new T (xml_node (name))); + boost::shared_ptr type_child (std::string name) { + return boost::shared_ptr (new T (node_child (name))); } template - boost::shared_ptr optional_sub_node (std::string name) { - std::list n = xml_nodes (name); + 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 ()) { @@ -51,9 +63,8 @@ protected: } template - std::list > sub_nodes (std::string name, std::string sub) { - XMLNode p (xml_node (name)); - std::list n = p.xml_nodes (sub); + 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))); @@ -61,11 +72,17 @@ protected: 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* xml_node (std::string); - std::list xml_nodes (std::string); + xmlpp::Node* node_child (std::string); + std::list node_children (std::string); std::list _taken; };