Use int64 in a few places.
[libdcp.git] / src / xml.h
1 #ifndef LIBDCP_XML_H
2 #define LIBDCP_XML_H
3
4 #include <string>
5 #include <list>
6 #include <glibmm.h>
7 #include <boost/shared_ptr.hpp>
8 #include "types.h"
9 #include "exceptions.h"
10
11 namespace xmlpp {
12         class Node;
13         class DomParser;
14 }
15
16 namespace libdcp {
17
18 class XMLNode
19 {
20 public:
21         XMLNode ();
22         XMLNode (xmlpp::Node const * node);
23
24 protected:
25         std::string string_node (std::string);
26         std::string optional_string_node (std::string);
27         ContentKind kind_node (std::string);
28         Fraction fraction_node (std::string);
29         int64_t int64_node (std::string);
30         void ignore_node (std::string);
31         void done ();
32
33         template <class T>
34         boost::shared_ptr<T> sub_node (std::string name) {
35                 return boost::shared_ptr<T> (new T (xml_node (name)));
36         }
37
38         template <class T>
39         boost::shared_ptr<T> optional_sub_node (std::string name) {
40                 std::list<xmlpp::Node*> n = xml_nodes (name);
41                 if (n.size() > 1) {
42                         throw XMLError ("duplicate XML tag");
43                 } else if (n.empty ()) {
44                         return boost::shared_ptr<T> ();
45                 }
46                 
47                 return boost::shared_ptr<T> (new T (n.front ()));
48         }
49         
50         template <class T>
51         std::list<boost::shared_ptr<T> > sub_nodes (std::string name, std::string sub) {
52                 XMLNode p (xml_node (name));
53                 std::list<xmlpp::Node*> n = p.xml_nodes (sub);
54                 std::list<boost::shared_ptr<T> > r;
55                 for (typename std::list<xmlpp::Node*>::iterator i = n.begin(); i != n.end(); ++i) {
56                         r.push_back (boost::shared_ptr<T> (new T (*i)));
57                 }
58                 return r;
59         }
60
61         xmlpp::Node const * _node;
62
63 private:
64         xmlpp::Node* xml_node (std::string);
65         std::list<xmlpp::Node*> xml_nodes (std::string);
66         std::list<Glib::ustring> _taken;
67 };
68
69 class XMLFile : public XMLNode
70 {
71 public:
72         XMLFile (std::string file, std::string root_name);
73         virtual ~XMLFile ();
74
75 private:
76         xmlpp::DomParser* _parser;
77 };
78
79 }
80
81 #endif