diff options
| author | Carl Hetherington <cth@carlh.net> | 2012-07-30 23:47:57 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2012-07-30 23:47:57 +0100 |
| commit | 9a9d4e014c16be88d72914a9480343445bc785a5 (patch) | |
| tree | 1857fcdd8963d51ac50f1467d9ae81d4d9be5f8e /src/xml.h | |
| parent | 34a25d89b16a33b5f619ae0eaaa03c17f93980af (diff) | |
Various.
Diffstat (limited to 'src/xml.h')
| -rw-r--r-- | src/xml.h | 78 |
1 files changed, 76 insertions, 2 deletions
@@ -1,6 +1,80 @@ +#ifndef LIBDCP_XML_H +#define LIBDCP_XML_H -class XMLFile +#include <string> +#include <list> +#include <glibmm.h> +#include <boost/shared_ptr.hpp> +#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 <class T> + boost::shared_ptr<T> sub_node (std::string name) { + return boost::shared_ptr<T> (new T (xml_node (name))); + } + + template <class T> + boost::shared_ptr<T> optional_sub_node (std::string name) { + std::list<xmlpp::Node*> n = xml_nodes (name); + if (n.size() > 1) { + throw XMLError ("duplicate XML tag"); + } else if (n.empty ()) { + return boost::shared_ptr<T> (); + } + + return boost::shared_ptr<T> (new T (n.front ())); + } + + template <class T> + std::list<boost::shared_ptr<T> > sub_nodes (std::string name) { + std::list<xmlpp::Node*> n = xml_nodes (name); + std::list<boost::shared_ptr<T> > r; + for (typename std::list<xmlpp::Node*>::iterator i = n.begin(); i != n.end(); ++i) { + r.push_back (boost::shared_ptr<T> (new T (*i))); + } + return r; + } + + xmlpp::Node const * _node; + +private: + xmlpp::Node* xml_node (std::string); + std::list<xmlpp::Node*> xml_nodes (std::string); + std::list<Glib::ustring> _taken; }; + +class XMLFile : public XMLNode +{ +public: + XMLFile (std::string file, std::string root_name); + virtual ~XMLFile (); + +private: + xmlpp::DomParser* _parser; +}; + +} + +#endif |
