GammaLib 2.0.0
Loading...
Searching...
No Matches
GXmlText.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GXmlText.cpp - XML text node class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2010-2014 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GXmlText.cpp
23 * @brief XML text node class implementation
24 * @author Juergen Knoedlseder
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include "GXmlText.hpp"
32#include "GTools.hpp"
33
34/* __ Method name definitions ____________________________________________ */
35
36/* __ Macros _____________________________________________________________ */
37
38/* __ Coding definitions _________________________________________________ */
39
40/* __ Debug definitions __________________________________________________ */
41
42
43/*==========================================================================
44 = =
45 = Constructors/destructors =
46 = =
47 ==========================================================================*/
48
49/***********************************************************************//**
50 * @brief Void constructor
51 ***************************************************************************/
53{
54 // Initialise members
56
57 // Return
58 return;
59}
60
61
62/***********************************************************************//**
63 * @brief Copy constructor
64 *
65 * @param[in] node XML text.
66 ***************************************************************************/
68{
69 // Initialise members
71
72 // Copy members
73 copy_members(node);
74
75 // Return
76 return;
77}
78
79
80/***********************************************************************//**
81 * @brief Text constructor
82 *
83 * @param[in] text Text string.
84 *
85 * Construct object by attributing a text string. Predefined entities
86 * (e.g. &quot;) are automatically converted into normal characters.
87 ***************************************************************************/
88GXmlText::GXmlText(const std::string& text) : GXmlNode()
89{
90 // Initialise members
92
93 // Set text
95
96 // Return
97 return;
98}
99
100
101/***********************************************************************//**
102 * @brief Destructor
103 ***************************************************************************/
105{
106 // Free members
107 free_members();
108
109 // Return
110 return;
111}
112
113
114/*==========================================================================
115 = =
116 = Operators =
117 = =
118 ==========================================================================*/
119
120/***********************************************************************//**
121 * @brief Assignment operator
122 *
123 * @param[in] node XML text.
124 * @return XML text.
125 ***************************************************************************/
127{
128 // Execute only if object is not identical
129 if (this != &node) {
130
131 // Copy base class members
132 this->GXmlNode::operator=(node);
133
134 // Free members
135 free_members();
136
137 // Initialise members
138 init_members();
139
140 // Copy members
141 copy_members(node);
142
143 } // endif: object was not identical
144
145 // Return
146 return *this;
147}
148
149
150/*==========================================================================
151 = =
152 = Public methods =
153 = =
154 ==========================================================================*/
155
156 /***********************************************************************//**
157 * @brief Clear XML text
158 *
159 * Resets the XML text to a clean initial state.
160 ***************************************************************************/
162{
163 // Free class members (base and derived classes, derived class first)
164 free_members();
166
167 // Initialise members
169 init_members();
170
171 // Return
172 return;
173}
174
175
176/***********************************************************************//**
177 * @brief Clone XML text
178 *
179 * @return Pointer to deep copy of XML text.
180 ***************************************************************************/
182{
183 // Clone XML text
184 return new GXmlText(*this);
185}
186
187
188/***********************************************************************//**
189 * @brief Write XML text into URL
190 *
191 * @param[in] url Unified Resource Locator.
192 * @param[in] indent Text indentation (parameter ignored).
193 *
194 * Writes the text into the URL. Special characters are automatically
195 * transformed into predefined entities (e.g. &quot;).
196 ***************************************************************************/
197void GXmlText::write(GUrl& url, const int& indent) const
198{
199 // Write text
200 url.printf("%s", gammalib::str2xml(m_text).c_str());
201
202 // Return
203 return;
204}
205
206
207/***********************************************************************//**
208 * @brief Print XML text
209 *
210 * @param[in] chatter Chattiness (defaults to NORMAL).
211 * @param[in] indent Text indentation (default to 0).
212 * @return String containing XML text.
213 ***************************************************************************/
214std::string GXmlText::print(const GChatter& chatter,
215 const int& indent) const
216{
217 // Initialise result string
218 std::string result;
219
220 // Continue only if chatter is not silent
221 if (chatter != SILENT) {
222
223 // Initialise result string
224 result = gammalib::fill(" ", indent);
225
226 // Append text to string
227 result.append("GXmlText::"+m_text);
228
229 } // endif: chatter was not silent
230
231 // Return
232 return result;
233}
234
235
236/*==========================================================================
237 = =
238 = Private methods =
239 = =
240 ==========================================================================*/
241
242/***********************************************************************//**
243 * @brief Initialise class members
244 ***************************************************************************/
246{
247 // Initialise members
248 m_text.clear();
249
250 // Return
251 return;
252}
253
254
255/***********************************************************************//**
256 * @brief Copy class members
257 *
258 * @param[in] node XML text.
259 ***************************************************************************/
261{
262 // Copy attributes
263 m_text = node.m_text;
264
265 // Return
266 return;
267}
268
269
270/***********************************************************************//**
271 * @brief Delete class members
272 ***************************************************************************/
274{
275 // Return
276 return;
277}
278
Gammalib tools definition.
GChatter
Definition GTypemaps.hpp:33
@ SILENT
Definition GTypemaps.hpp:34
XML text node class interface definition.
Abstract URL base class.
Definition GUrl.hpp:44
virtual void printf(const char *format,...)=0
Abstract XML node base class.
Definition GXmlNode.hpp:57
GXmlNode & operator=(const GXmlNode &node)
Assignment operator.
Definition GXmlNode.cpp:118
void free_members(void)
Delete class members.
Definition GXmlNode.cpp:921
void init_members(void)
Initialise class members.
Definition GXmlNode.cpp:880
XML text node class.
Definition GXmlText.hpp:43
virtual void clear(void)
Clear XML text.
Definition GXmlText.cpp:161
virtual ~GXmlText(void)
Destructor.
Definition GXmlText.cpp:104
void init_members(void)
Initialise class members.
Definition GXmlText.cpp:245
virtual void write(GUrl &url, const int &indent=0) const
Write XML text into URL.
Definition GXmlText.cpp:197
GXmlText(void)
Void constructor.
Definition GXmlText.cpp:52
virtual GXmlText * clone(void) const
Clone XML text.
Definition GXmlText.cpp:181
std::string m_text
Text.
Definition GXmlText.hpp:75
void free_members(void)
Delete class members.
Definition GXmlText.cpp:273
virtual std::string print(const GChatter &chatter=NORMAL, const int &indent=0) const
Print XML text.
Definition GXmlText.cpp:214
void copy_members(const GXmlText &node)
Copy class members.
Definition GXmlText.cpp:260
GXmlText & operator=(const GXmlText &node)
Assignment operator.
Definition GXmlText.cpp:126
const std::string & text(void) const
Return text.
Definition GXmlText.hpp:97
std::string xml2str(const std::string &arg)
Convert XML character references in string to characters.
Definition GTools.cpp:1416
std::string str2xml(const std::string &arg)
Convert special characters in string to XML character references.
Definition GTools.cpp:1549
std::string fill(const std::string &s, const int &n)
Fill string with n strings of same type.
Definition GTools.cpp:1044