Line |
Branch |
Exec |
Source |
1 |
|
|
/***************************************************************************** |
2 |
|
|
* |
3 |
|
|
* $Id$ |
4 |
|
|
* |
5 |
|
|
* This is a minimal implementation of the XML dialect as used by |
6 |
|
|
* the MSR protocol. |
7 |
|
|
* |
8 |
|
|
* Copyright 2010 Richard Hacker (lerichi at gmx dot net) |
9 |
|
|
* |
10 |
|
|
* This file is part of the pdserv library. |
11 |
|
|
* |
12 |
|
|
* The pdserv library is free software: you can redistribute it and/or modify |
13 |
|
|
* it under the terms of the GNU Lesser General Public License as published |
14 |
|
|
* by the Free Software Foundation, either version 3 of the License, or (at |
15 |
|
|
* your option) any later version. |
16 |
|
|
* |
17 |
|
|
* The pdserv library is distributed in the hope that it will be useful, but |
18 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
19 |
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
20 |
|
|
* License for more details. |
21 |
|
|
* |
22 |
|
|
* You should have received a copy of the GNU Lesser General Public License |
23 |
|
|
* along with the pdserv library. If not, see <http://www.gnu.org/licenses/>. |
24 |
|
|
* |
25 |
|
|
*****************************************************************************/ |
26 |
|
|
|
27 |
|
|
#ifndef XMLDOC_H |
28 |
|
|
#define XMLDOC_H |
29 |
|
|
|
30 |
|
|
#include <sstream> |
31 |
|
|
#include <string> |
32 |
|
|
|
33 |
|
|
namespace PdServ { |
34 |
|
|
class Variable; |
35 |
|
|
} |
36 |
|
|
|
37 |
|
|
namespace MsrProto { |
38 |
|
|
|
39 |
|
|
class Variable; |
40 |
|
|
class Parameter; |
41 |
|
|
class Channel; |
42 |
|
|
|
43 |
|
|
class XmlElement { |
44 |
|
|
public: |
45 |
|
|
XmlElement(const char *name, std::ostream &os, |
46 |
|
|
size_t level, std::string *id); |
47 |
|
|
XmlElement(const XmlElement& other): |
48 |
|
|
level(other.level), id(other.id), os(other.os), name(other.name) { |
49 |
|
|
} |
50 |
|
|
|
51 |
|
|
/** Destructor. |
52 |
|
|
* Children are destroyed if they were not released beforehand */ |
53 |
|
|
~XmlElement(); |
54 |
|
|
|
55 |
|
|
XmlElement createChild(const char *name); |
56 |
|
|
|
57 |
|
|
const size_t level; |
58 |
|
|
std::string* const id; |
59 |
|
|
|
60 |
|
|
class Attribute { |
61 |
|
|
public: |
62 |
|
|
Attribute(XmlElement&, const char *name); |
63 |
|
|
~Attribute(); |
64 |
|
|
|
65 |
|
|
/** Set string attribute, checking for characters |
66 |
|
|
* that need to be escaped */ |
67 |
|
|
void setEscaped( const char *value); |
68 |
|
|
|
69 |
|
|
void csv(const Variable* var, const char *buf, |
70 |
|
|
size_t nblocks, size_t precision); |
71 |
|
|
void base64( const void *data, size_t len) const; |
72 |
|
|
void hexDec( const void *data, size_t len) const; |
73 |
|
|
|
74 |
|
|
|
75 |
|
|
std::ostream& operator<<(const struct timespec &t); |
76 |
|
|
|
77 |
|
|
/** Various variations of numerical attributes */ |
78 |
|
|
std::ostream& operator<<(const char *s); |
79 |
|
|
template <typename T> |
80 |
|
|
std::ostream& operator<<(T const& val); |
81 |
|
|
|
82 |
|
|
private: |
83 |
|
|
std::ostream& os; |
84 |
|
|
|
85 |
|
|
}; |
86 |
|
|
|
87 |
|
|
private: |
88 |
|
|
std::ostream& os; |
89 |
|
|
|
90 |
|
|
const char * const name; |
91 |
|
|
bool printed; |
92 |
|
|
}; |
93 |
|
|
|
94 |
|
|
template <typename T> |
95 |
|
✗ |
std::ostream& XmlElement::Attribute::operator<<(T const& val) |
96 |
|
|
{ |
97 |
|
✗ |
os << val; |
98 |
|
✗ |
return os; |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
#endif // XMLDOC_H |
104 |
|
|
|