1 |
/* |
---|
2 |
* Parts Copyright (C) 2005-2008 by Pieter Palmers |
---|
3 |
* |
---|
4 |
* This file is part of FFADO |
---|
5 |
* FFADO = Free FireWire (pro-)audio drivers for Linux |
---|
6 |
* |
---|
7 |
* FFADO is based upon FreeBoB. |
---|
8 |
* |
---|
9 |
* This program is free software: you can redistribute it and/or modify |
---|
10 |
* it under the terms of the GNU General Public License as published by |
---|
11 |
* the Free Software Foundation, either version 2 of the License, or |
---|
12 |
* (at your option) version 3 of the License. |
---|
13 |
* |
---|
14 |
* This program is distributed in the hope that it will be useful, |
---|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 |
* GNU General Public License for more details. |
---|
18 |
* |
---|
19 |
* You should have received a copy of the GNU General Public License |
---|
20 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
21 |
* |
---|
22 |
*/ |
---|
23 |
|
---|
24 |
/* |
---|
25 |
* |
---|
26 |
* D-Bus++ - C++ bindings for D-Bus |
---|
27 |
* |
---|
28 |
* Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com> |
---|
29 |
* |
---|
30 |
* |
---|
31 |
* This library is free software; you can redistribute it and/or |
---|
32 |
* modify it under the terms of the GNU Lesser General Public |
---|
33 |
* License as published by the Free Software Foundation; either |
---|
34 |
* version 2.1 of the License, or (at your option) any later version. |
---|
35 |
* |
---|
36 |
* This library is distributed in the hope that it will be useful, |
---|
37 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
38 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
39 |
* Lesser General Public License for more details. |
---|
40 |
* |
---|
41 |
* You should have received a copy of the GNU Lesser General Public |
---|
42 |
* License along with this library; if not, write to the Free Software |
---|
43 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
44 |
* |
---|
45 |
*/ |
---|
46 |
|
---|
47 |
|
---|
48 |
#ifndef __FFADO_UTIL_SERIALIZE_EXPAT_XML_H__ |
---|
49 |
#define __FFADO_UTIL_SERIALIZE_EXPAT_XML_H__ |
---|
50 |
|
---|
51 |
#include <exception> |
---|
52 |
#include <string> |
---|
53 |
#include <vector> |
---|
54 |
#include <map> |
---|
55 |
#include <iostream> |
---|
56 |
#include <sstream> |
---|
57 |
|
---|
58 |
#include "debugmodule/debugmodule.h" |
---|
59 |
|
---|
60 |
namespace Util { |
---|
61 |
|
---|
62 |
namespace Xml { |
---|
63 |
|
---|
64 |
class Error : public std::exception |
---|
65 |
{ |
---|
66 |
public: |
---|
67 |
|
---|
68 |
Error( const char* error, int line, int column ); |
---|
69 |
|
---|
70 |
~Error() throw() |
---|
71 |
{} |
---|
72 |
|
---|
73 |
const char* what() const throw() |
---|
74 |
{ |
---|
75 |
return _error.c_str(); |
---|
76 |
} |
---|
77 |
|
---|
78 |
private: |
---|
79 |
|
---|
80 |
std::string _error; |
---|
81 |
}; |
---|
82 |
|
---|
83 |
class Node; |
---|
84 |
|
---|
85 |
class Nodes : public std::vector<Node*> |
---|
86 |
{ |
---|
87 |
public: |
---|
88 |
|
---|
89 |
Nodes operator[]( const std::string& key ); |
---|
90 |
|
---|
91 |
Nodes select( const std::string& attr, const std::string& value ); |
---|
92 |
}; |
---|
93 |
|
---|
94 |
class Node |
---|
95 |
{ |
---|
96 |
public: |
---|
97 |
|
---|
98 |
typedef std::map<std::string, std::string> Attributes; |
---|
99 |
|
---|
100 |
typedef std::vector<Node> Children; |
---|
101 |
|
---|
102 |
std::string name; |
---|
103 |
std::string cdata; |
---|
104 |
Children children; |
---|
105 |
|
---|
106 |
Node( std::string& n, Attributes& a ) |
---|
107 |
: name(n), _attrs(a) |
---|
108 |
{} |
---|
109 |
|
---|
110 |
Node( const char* n, const char** a = NULL ); |
---|
111 |
|
---|
112 |
Nodes operator[]( const std::string& key ); |
---|
113 |
|
---|
114 |
std::string get( const std::string& attribute ); |
---|
115 |
|
---|
116 |
void set( const std::string& attribute, std::string value ); |
---|
117 |
|
---|
118 |
std::string to_xml() const; |
---|
119 |
|
---|
120 |
Node& add( Node child ) |
---|
121 |
{ |
---|
122 |
children.push_back(child); |
---|
123 |
return children.back(); |
---|
124 |
} |
---|
125 |
|
---|
126 |
Nodes find(const std::string &path); |
---|
127 |
|
---|
128 |
bool has_child_text() {return cdata.size() !=0;}; |
---|
129 |
std::string get_child_text() {return cdata;}; |
---|
130 |
void set_child_text(std::string t) {cdata=t;}; |
---|
131 |
|
---|
132 |
private: |
---|
133 |
|
---|
134 |
void _raw_xml( std::string& xml, int& depth ) const; |
---|
135 |
|
---|
136 |
Attributes _attrs; |
---|
137 |
DECLARE_DEBUG_MODULE; |
---|
138 |
}; |
---|
139 |
|
---|
140 |
class Document |
---|
141 |
{ |
---|
142 |
public: |
---|
143 |
|
---|
144 |
struct Expat; |
---|
145 |
|
---|
146 |
Node* root; |
---|
147 |
|
---|
148 |
Document(); |
---|
149 |
|
---|
150 |
Document( const std::string& xml ); |
---|
151 |
|
---|
152 |
~Document(); |
---|
153 |
|
---|
154 |
void from_xml( const std::string& xml ); |
---|
155 |
|
---|
156 |
std::string to_xml() const; |
---|
157 |
|
---|
158 |
void create_root_node( const char *); |
---|
159 |
Xml::Node* get_root_node() {return root;}; |
---|
160 |
|
---|
161 |
void write_to_file_formatted( const std::string ); |
---|
162 |
void load_from_file( const std::string ); |
---|
163 |
|
---|
164 |
private: |
---|
165 |
|
---|
166 |
int _depth; |
---|
167 |
DECLARE_DEBUG_MODULE; |
---|
168 |
}; |
---|
169 |
|
---|
170 |
} /* namespace Xml */ |
---|
171 |
|
---|
172 |
} /* namespace Util */ |
---|
173 |
|
---|
174 |
std::istream& operator >> ( std::istream&, Util::Xml::Document& ); |
---|
175 |
std::ostream& operator << ( std::ostream&, Util::Xml::Document& ); |
---|
176 |
|
---|
177 |
#endif//__FFADO_UTIL_SERIALIZE_EXPAT_XML_H__ |
---|