Merged with trunk R1141
[ardour.git] / libs / pbd / pbd / xml++.h
1 /* xml++.h
2  * libxml++ and this file are copyright (C) 2000 by Ari Johnson, and
3  * are covered by the GNU Lesser General Public License, which should be
4  * included with libxml++ as the file COPYING.
5  */
6
7 #include <string>
8 #include <list>
9 #include <map>
10 #include <cstdio>
11 #include <cstdarg>
12
13 #include <libxml/parser.h>
14 #include <libxml/tree.h>
15
16 #ifndef __XML_H
17 #define __XML_H
18
19 using std::string;
20 using std::map;
21 using std::list;
22
23 class XMLTree;
24 class XMLNode;
25 class XMLProperty;
26
27 typedef list<XMLNode *> XMLNodeList;
28 typedef XMLNodeList::iterator XMLNodeIterator;
29 typedef XMLNodeList::const_iterator XMLNodeConstIterator;
30 typedef list<XMLProperty*> XMLPropertyList;
31 typedef XMLPropertyList::iterator XMLPropertyIterator;
32 typedef XMLPropertyList::const_iterator XMLPropertyConstIterator;
33 typedef map<string, XMLProperty*> XMLPropertyMap;
34
35 class XMLTree {
36 private:
37   string _filename;
38   XMLNode *_root;
39   int _compression;
40
41 public:
42   XMLTree();
43   XMLTree(const string &fn);
44   XMLTree(const XMLTree *);
45   ~XMLTree();
46
47   XMLNode *root() const { return _root; };
48   XMLNode *set_root(XMLNode *n) { return _root = n; };
49
50   const string & filename() const { return _filename; };
51   const string & set_filename(const string &fn) { return _filename = fn; };
52
53   int compression() const { return _compression; };
54   int set_compression(int);
55
56   bool read();
57   bool read(const string &fn) { set_filename(fn); return read(); };
58   bool read_buffer(const string &);
59
60   bool write() const;
61   bool write(const string &fn) { set_filename(fn); return write(); };
62
63   void debug (FILE*) const;
64
65   const string & write_buffer() const;
66 };
67
68 class XMLNode {
69 private:
70   string _name;
71   bool _is_content;
72   string _content;
73   XMLNodeList _children;
74   XMLPropertyList _proplist;
75   XMLPropertyMap _propmap;
76
77 public:
78   XMLNode(const string &);
79   XMLNode(const string &, const string &);
80   XMLNode(const XMLNode&);
81   ~XMLNode();
82
83   const string name() const { return _name; };
84
85   bool is_content() const { return _is_content; };
86   const string & content() const { return _content; };
87   const string & set_content (const string &);
88   XMLNode *add_content(const string & = string());
89
90   const XMLNodeList & children (const string& str = string()) const;
91   XMLNode *add_child (const char *);
92   XMLNode *add_child_copy (const XMLNode&);
93   XMLNode *child (const char*) const;
94   void add_child_nocopy (XMLNode&);
95
96   const XMLPropertyList & properties() const { return _proplist; };
97   XMLProperty *property(const char * );
98   const XMLProperty *property(const char * n) const
99         { return ((XMLNode *) this)->property(n); };
100   XMLProperty *add_property(const char *, const string &);
101   XMLProperty *add_property(const char *, const char * = "");
102
103   void remove_property(const string &);
104
105   /** Remove all nodes with the name passed to remove_nodes */
106   void remove_nodes(const string &);
107   /** Remove and delete all nodes with the name passed to remove_nodes */
108   void remove_nodes_and_delete(const string &);
109 };
110
111 class XMLProperty {
112 private:
113   string _name;
114   string _value;
115
116 public:
117   XMLProperty(const string &n, const string &v = string());
118   ~XMLProperty();
119
120   const string & name() const { return _name; };
121   const string & value() const { return _value; };
122   const string & set_value(const string &v) { return _value = v; };
123 };
124
125 #endif /* __XML_H */
126