GCC Code Coverage Report


Directory: src/gate/
File: src/gate/encode/cxx_xml.cpp
Date: 2025-12-12 23:40:09
Exec Total Coverage
Lines: 109 128 85.2%
Functions: 30 34 88.2%
Branches: 31 82 37.8%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28 #include "gate/encode/xml.hpp"
29 #include "gate/exceptions.hpp"
30
31 namespace gate
32 {
33 namespace enc
34 {
35
36 2 XmlNode::XmlNode()
37 {
38 2 gate_mem_clear(&this->impl, sizeof(this->impl));
39 2 }
40
41 3 XmlNode::XmlNode(enumint_t nodeType, String const& tag)
42 {
43 3 result_t result = gate_xml_node_create(&this->impl, nodeType, tag.c_impl(), NULL, NULL, NULL);
44
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 GATEXX_CHECK_ERROR(result);
45 3 }
46
47
48 1 XmlNode::XmlNode(gate_xml_node_t const* node)
49 {
50 1 result_t result = gate_xml_node_create(&this->impl, node->node_type, &node->tag,
51 &node->attributes, &node->child_nodes, &node->content);
52
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
53 1 }
54
55 1 XmlNode::XmlNode(XmlNode const& src)
56 {
57
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
1 if (NULL == gate_xml_node_duplicate(&this->impl, &src.impl))
58 {
59 GATEXX_RAISE_ERROR(results::OutOfMemory);
60 }
61 1 }
62
63 1 XmlNode& XmlNode::operator=(XmlNode const& src)
64 {
65
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (this != &src)
66 {
67 gate_xml_node_t new_node;
68
2/4
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
1 if (NULL == gate_xml_node_duplicate(&new_node, &src.impl))
69 {
70 GATEXX_RAISE_ERROR(results::OutOfMemory);
71 }
72
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_xml_node_destroy(&this->impl);
73
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 gate_mem_copy(&this->impl, &new_node, sizeof(new_node));
74 }
75 1 return *this;
76 }
77
78
79 14 XmlNode::~XmlNode() noexcept
80 {
81 7 gate_xml_node_destroy(&this->impl);
82 7 }
83
84 1 enumint_t XmlNode::getNodeType() const
85 {
86 1 return this->impl.node_type;
87 }
88
89 1 String XmlNode::getTag() const
90 {
91 1 return String::duplicate(this->impl.tag);
92 }
93
94 1 size_t XmlNode::getAttributeCount() const
95 {
96 1 return gate_xml_node_attribute_count(&this->impl);
97 }
98
99 1 String XmlNode::getAttribute(String const& name) const
100 {
101 1 gate_string_t value = GATE_STRING_INIT_EMPTY;
102
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 result_t result = gate_xml_node_attribute_by_name(&this->impl, name.c_impl(), &value);
103
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
104 2 return String::createFrom(value);
105 }
106 1 String XmlNode::getAttribute(String const& name, String const& altValue) const
107 {
108 1 gate_string_t value = GATE_STRING_INIT_EMPTY;
109
1/2
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 result_t result = gate_xml_node_attribute_by_name(&this->impl, name.c_impl(), &value);
110
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (GATE_FAILED(result))
111 {
112 1 return altValue;
113 }
114 else
115 {
116 return String::createFrom(value);
117 }
118 }
119
120
121 1 void XmlNode::getAttribute(size_t index, String& name, String& value) const
122 {
123 1 gate_string_t str_name = GATE_STRING_INIT_EMPTY;
124 1 gate_string_t str_value = GATE_STRING_INIT_EMPTY;
125
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_xml_node_attribute_by_index(&this->impl, index, &str_name, &str_value);
126
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
127 1 name = String::createFrom(str_name);
128 1 value = String::createFrom(str_value);
129 1 }
130
131 1 size_t XmlNode::getChildrenCount() const
132 {
133 1 return gate_xml_node_children_count(&this->impl);
134 }
135
136 2 XmlNode XmlNode::getChild(size_t index) const
137 {
138 2 XmlNode node;
139
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 result_t result = gate_xml_node_child(&this->impl, index, &node.impl);
140
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
2 GATEXX_CHECK_EXCEPTION(result);
141 2 return node;
142 }
143
144 1 String XmlNode::getContent() const
145 {
146 1 return String::duplicate(this->impl.content);
147 }
148
149 2 void XmlNode::store(Stream const& storeStream) const
150 {
151 2 result_t result = gate_xml_node_print(&this->impl, storeStream.c_impl(), 0);
152
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
153 2 }
154
155 2 String XmlNode::toString() const
156 {
157
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 StringStream ss;
158
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 this->store(ss);
159
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 return ss.toString();
160 }
161
162 3 gate_xml_node_t const* XmlNode::c_impl() const noexcept
163 {
164 3 return &this->impl;
165 }
166
167 3 gate_xml_node_t* XmlNode::c_impl() noexcept
168 {
169 3 return &this->impl;
170 }
171
172
173
174
175 1 XmlDoc::XmlDoc()
176 {
177 1 result_t result = gate_xml_doc_create(&this->impl, NULL);
178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
179 1 }
180
181 1 XmlDoc::XmlDoc(XmlNode const& documentElement)
182 {
183 1 result_t result = gate_xml_doc_create(&this->impl, documentElement.c_impl());
184
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(result);
185 1 }
186
187 1 XmlDoc::XmlDoc(Stream& loadStream)
188 {
189 1 result_t result = gate_xml_doc_load(&this->impl, loadStream.c_impl());
190
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
191 1 }
192
193 1 XmlDoc::XmlDoc(String const& loadText)
194 {
195 1 result_t result = gate_xml_doc_load_text(&this->impl, loadText.c_impl());
196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
197 1 }
198
199 8 XmlDoc::~XmlDoc() noexcept
200 {
201 4 gate_xml_doc_destroy(&this->impl);
202 4 }
203
204 1 gate_xml_doc_t* XmlDoc::c_impl() noexcept
205 {
206 1 return &this->impl;
207 }
208 1 gate_xml_doc_t const* XmlDoc::c_impl() const noexcept
209 {
210 1 return &this->impl;
211 }
212
213 1 void XmlDoc::store(Stream& saveStream, size_t indentSpaces)
214 {
215 1 result_t result = gate_xml_doc_store(&this->impl, saveStream.c_impl(), indentSpaces);
216
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_EXCEPTION(result);
217 1 }
218
219 1 String XmlDoc::toString(size_t indentSpaces)
220 {
221 1 gate_string_t text = GATE_STRING_INIT_EMPTY;
222
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_xml_doc_store_text(&this->impl, &text, indentSpaces);
223
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_ERROR(result);
224 2 return String::createFrom(text);
225 }
226
227 1 XmlNode XmlDoc::rootElement()
228 {
229 1 gate_xml_node_t const* ptr_node = NULL;
230
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t result = gate_xml_doc_root_element(&this->impl, &ptr_node);
231
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_EXCEPTION(result);
232
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
2 return XmlNode(ptr_node);
233 }
234
235 2 void XmlDoc::addNode(XmlNode& parentNode, XmlNode const& childNode)
236 {
237 2 result_t result = gate_xml_doc_add_node(&this->impl, parentNode.c_impl(), childNode.c_impl());
238
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(result);
239 2 }
240
241 void XmlDoc::removeNode(XmlNode& node, size_t index)
242 {
243 result_t result = gate_xml_doc_remove_node(&this->impl, node.c_impl(), index);
244 GATEXX_CHECK_EXCEPTION(result);
245 }
246
247 void XmlDoc::addAttribute(XmlNode& node, String const& name, String const& value)
248 {
249 result_t result = gate_xml_doc_add_attribute(&this->impl, node.c_impl(), name.c_impl(), value.c_impl());
250 GATEXX_CHECK_EXCEPTION(result);
251 }
252
253 void XmlDoc::removeAttribute(XmlNode& node, String const& name)
254 {
255 result_t result = gate_xml_doc_remove_attribute(&this->impl, node.c_impl(), name.c_impl());
256 GATEXX_CHECK_EXCEPTION(result);
257 }
258 void XmlDoc::setContent(XmlNode& node, String const& content)
259 {
260 result_t result = gate_xml_doc_set_node_content(&this->impl, node.c_impl(), content.c_impl());
261 GATEXX_CHECK_EXCEPTION(result);
262 }
263
264
265 } // end of namespace enc
266 } // end of namespace gate
267