GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/XmlElement.h
Date: 2023-11-12 04:06:57
Exec Total Coverage
Lines: 3 3 100.0%
Branches: 1 2 50.0%

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 <ostream>
31 #include <string>
32
33 namespace MsrProto {
34
35 class Variable;
36
37 class XmlElement {
38 public:
39 XmlElement(const char *name, std::ostream &os,
40 size_t level, std::string *id);
41 XmlElement(const XmlElement& other):
42 level(other.level), id(other.id), os(other.os), name(other.name) {
43 }
44
45 /** Destructor.
46 * Children are destroyed if they were not released beforehand */
47 ~XmlElement();
48
49 XmlElement createChild(const char *name);
50
51 const size_t level;
52 std::string* const id;
53
54 class Attribute {
55 public:
56 Attribute(XmlElement&, const char *name);
57 ~Attribute();
58
59 /** Set string attribute, checking for characters
60 * that need to be escaped */
61 void setEscaped( const std::string& value);
62
63 void csv(const Variable* var, const char *buf,
64 size_t nblocks, std::streamsize precision);
65 void base64( const void *data, size_t len) const;
66 void hexDec( const void *data, size_t len) const;
67
68
69 std::ostream& operator<<(const struct timespec &t);
70
71 /** Various variations of numerical attributes */
72 std::ostream& operator<<(const char *s);
73 template <typename T>
74 std::ostream& operator<<(T const& val);
75
76 private:
77 std::ostream& os;
78
79 };
80
81 private:
82 std::ostream& os;
83
84 const char * const name;
85 bool printed;
86 };
87
88 template <typename T>
89 1966 std::ostream& XmlElement::Attribute::operator<<(T const& val)
90 {
91
1/2
✗ Branch 5 not taken.
✓ Branch 6 taken 22 times.
1966 os << val;
92 1966 return os;
93 }
94
95 }
96
97 #endif // XMLDOC_H
98