blob: 736a0dd80edc912d597eb969bf0630aba49920d1 [file] [log] [blame]
Emeric Vigier2f625822012-08-06 11:09:52 -04001/*
2 *
3 * D-Bus++ - C++ bindings for D-Bus
4 *
5 * Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com>
6 *
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24
25#ifndef __DBUSXX_XML_H
26#define __DBUSXX_XML_H
27
28#ifdef HAVE_CONFIG_H
29#include "config.h"
30#endif
31
32#include <exception>
33#include <string>
34#include <vector>
35#include <map>
36#include <iostream>
37#include <sstream>
38
39namespace DBus
40{
41
42namespace Xml
43{
44
45class Error : public std::exception
46{
47public:
48
49 Error(const char *error, int line, int column);
50
51 ~Error() throw()
52 {}
53
54 const char *what() const throw()
55 {
56 return _error.c_str();
57 }
58
59private:
60
61 std::string _error;
62};
63
64class Node;
65
66class Nodes : public std::vector<Node *>
67{
68public:
69
70 Nodes operator[](const std::string &key);
71
72 Nodes select(const std::string &attr, const std::string &value);
73};
74
75class Node
76{
77public:
78
79 typedef std::map<std::string, std::string> Attributes;
80
81 typedef std::vector<Node> Children;
82
83 std::string name;
84 std::string cdata;
85 Children children;
86
87 Node(std::string &n, Attributes &a)
88 : name(n), _attrs(a)
89 {}
90
91 Node(const char *n, const char **a = NULL);
92
93 Nodes operator[](const std::string &key);
94
95 std::string get(const std::string &attribute);
96
97 void set(const std::string &attribute, std::string value);
98
99 std::string to_xml() const;
100
101 Node &add(Node child)
102 {
103 children.push_back(child);
104 return children.back();
105 }
106
107private:
108
109 void _raw_xml(std::string &xml, int &depth) const;
110
111 Attributes _attrs;
112};
113
114class Document
115{
116public:
117
118 struct Expat;
119
120 Node *root;
121
122 Document();
123
124 Document(const std::string &xml);
125
126 ~Document();
127
128 void from_xml(const std::string &xml);
129
130 std::string to_xml() const;
131
132private:
133
134 int _depth;
135};
136
137} /* namespace Xml */
138
139} /* namespace DBus */
140
141std::istream &operator >> (std::istream &, DBus::Xml::Document &);
142std::ostream &operator << (std::ostream &, DBus::Xml::Document &);
143
144#endif//__DBUSXX_XML_H