blob: 9b6000131587b218f09564509d5cc31516be6db2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#ifndef LIBDCP_XML_H
#define LIBDCP_XML_H
#include <string>
#include <list>
#include <stdint.h>
#include <glibmm.h>
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#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_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);
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<bool> optional_bool_attribute (std::string);
boost::optional<Color> optional_color_attribute (std::string);
std::string content ();
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;
}
template <class T>
std::list<boost::shared_ptr<T> > sub_nodes (std::string name, std::string sub) {
XMLNode p (xml_node (name));
return p.sub_nodes<T> (sub);
}
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
|