From 9a9d4e014c16be88d72914a9480343445bc785a5 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 30 Jul 2012 23:47:57 +0100 Subject: Various. --- src/xml.h | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) (limited to 'src/xml.h') diff --git a/src/xml.h b/src/xml.h index 5cfa4947..ff4b1e67 100644 --- a/src/xml.h +++ b/src/xml.h @@ -1,6 +1,80 @@ +#ifndef LIBDCP_XML_H +#define LIBDCP_XML_H -class XMLFile +#include +#include +#include +#include +#include "types.h" +#include "exceptions.h" + +namespace xmlpp { + class Node; + class DomParser; +} + +namespace libdcp { + +class XMLNode { public: - XMLFile (std::string file); + 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); + int int_node (std::string); + void ignore_node (std::string); + void done (); + + template + boost::shared_ptr sub_node (std::string name) { + return boost::shared_ptr (new T (xml_node (name))); + } + + template + boost::shared_ptr optional_sub_node (std::string name) { + std::list n = xml_nodes (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 > sub_nodes (std::string name) { + std::list n = xml_nodes (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; + } + + xmlpp::Node const * _node; + +private: + xmlpp::Node* xml_node (std::string); + std::list xml_nodes (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 -- cgit v1.2.3