GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/XmlElement.h
Date: 2025-08-17 04:10:43
Exec Total Coverage
Lines: 3 3 100.0%
Branches: 1 2 50.0%

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