GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GXmlDocument.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GXmlDocument.hpp - XML document node class definition *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2018 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 GXmlDocument.hpp
23  * @brief XML document node class interface definition
24  * @author Juergen Knodlseder
25  */
26 
27 #ifndef GXMLDOCUMENT_HPP
28 #define GXMLDOCUMENT_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GUrl.hpp"
33 #include "GFilename.hpp"
34 #include "GXmlNode.hpp"
35 #include "GXmlAttribute.hpp"
36 
37 
38 /***********************************************************************//**
39  * @class GXmlDocument
40  *
41  * @brief XML document node class
42  *
43  * This class implements the root node of an XML document. The root node is
44  * a Processing Instruction which contains the following attributes:
45  * - @p version
46  * - @p encoding
47  * - @p standalone
48  *
49  * All three attributes are systematically written.
50  ***************************************************************************/
51 class GXmlDocument : public GXmlNode {
52 
53 public:
54  // Constructors and destructors
55  GXmlDocument(void);
57  const std::string& version,
58  const std::string& encoding,
59  const std::string& standalone);
60  GXmlDocument(const GXmlDocument& node);
61  virtual ~GXmlDocument(void);
62 
63  // Operators
64  GXmlDocument& operator=(const GXmlDocument& node);
65 
66  // Implemented pure virtual base class methods
67  virtual void clear(void);
68  virtual GXmlDocument* clone(void) const;
69  virtual std::string classname(void) const;
70  virtual void write(GUrl& url, const int& indent = 0) const;
71  virtual NodeType type(void) const;
72  virtual std::string print(const GChatter& chatter = NORMAL,
73  const int& indent = 0) const;
74 
75  // Methods
76  const GFilename& filename(void) const;
77  std::string version(void) const;
78  std::string encoding(void) const;
79  std::string standalone(void) const;
80  void filename(const GFilename& filename);
81  void version(const std::string& version);
82  void encoding(const std::string& encoding);
83  void standalone(const std::string& standalone);
84 
85 protected:
86  // Protected methods
87  void init_members(void);
88  void copy_members(const GXmlDocument& node);
89  void free_members(void);
90 
91  // Protected data members
92  GFilename m_filename; //!< Name of XML file
93  GXmlAttribute m_version; //!< XML version ("1.0", "1.1")
94  GXmlAttribute m_encoding; //!< Encoding (e.g. "UTF-8")
95  GXmlAttribute m_standalone; //!< Standalone ("yes", "no")
96 };
97 
98 
99 /***********************************************************************//**
100  * @brief Return class name
101  *
102  * @return String containing the class name ("GXmlDocument").
103  ***************************************************************************/
104 inline
105 std::string GXmlDocument::classname(void) const
106 {
107  return ("GXmlDocument");
108 }
109 
110 
111 /***********************************************************************//**
112  * @brief Return filename
113  *
114  * @return Filename of XML document.
115  ***************************************************************************/
116 inline
118 {
119  return (m_filename);
120 }
121 
122 
123 /***********************************************************************//**
124  * @brief Return version
125  *
126  * @return Version string.
127  ***************************************************************************/
128 inline
129 std::string GXmlDocument::version(void) const
130 {
131  return (m_version.value());
132 }
133 
134 
135 /***********************************************************************//**
136  * @brief Return encoding
137  *
138  * @return Encoding string.
139  ***************************************************************************/
140 inline
141 std::string GXmlDocument::encoding(void) const
142 {
143  return (m_encoding.value());
144 }
145 
146 
147 /***********************************************************************//**
148  * @brief Return standalone
149  *
150  * @return Standalone value string.
151  ***************************************************************************/
152 inline
153 std::string GXmlDocument::standalone(void) const
154 {
155  return (m_standalone.value());
156 }
157 
158 
159 /***********************************************************************//**
160  * @brief Set filename
161  *
162  * @param[in] filename Filename of XML document.
163  ***************************************************************************/
164 inline
165 void GXmlDocument::filename(const GFilename& filename)
166 {
168  return;
169 }
170 
171 
172 /***********************************************************************//**
173  * @brief Set version
174  *
175  * @param[in] version Version string.
176  ***************************************************************************/
177 inline
178 void GXmlDocument::version(const std::string& version)
179 {
180  m_version.value(version);
181  return;
182 }
183 
184 
185 /***********************************************************************//**
186  * @brief Set encoding
187  *
188  * @param[in] encoding Encoding string.
189  ***************************************************************************/
190 inline
191 void GXmlDocument::encoding(const std::string& encoding)
192 {
193  m_encoding.value(encoding);
194  return;
195 }
196 
197 
198 /***********************************************************************//**
199  * @brief Set standalone
200  *
201  * @param[in] standalone Standalone value string.
202  ***************************************************************************/
203 inline
204 void GXmlDocument::standalone(const std::string& standalone)
205 {
206  m_standalone.value(standalone);
207  return;
208 }
209 
210 
211 /***********************************************************************//**
212  * @brief Return XML node type
213  *
214  * @return XML node type (NT_DOCUMENT).
215  ***************************************************************************/
216 inline
218 {
219  return (NT_DOCUMENT);
220 }
221 
222 #endif /* GXMLDOCUMENT_HPP */
Abstract XML node base class.
Definition: GXmlNode.hpp:57
virtual NodeType type(void) const
Return XML node type.
std::string standalone(void) const
Return standalone.
XML attribute class.
virtual void write(GUrl &url, const int &indent=0) const
Write XML document into URL.
virtual ~GXmlDocument(void)
Destructor.
GXmlAttribute m_version
XML version (&quot;1.0&quot;, &quot;1.1&quot;)
Abstract URL base class interface definition.
Abstract URL base class.
Definition: GUrl.hpp:44
Filename class.
Definition: GFilename.hpp:62
std::string version(void) const
Return version.
void copy_members(const GXmlDocument &node)
Copy class members.
virtual GXmlDocument * clone(void) const
Clone XML document.
GChatter
Definition: GTypemaps.hpp:33
XML document node class.
GFilename m_filename
Name of XML file.
GXmlDocument(void)
Void constructor.
virtual std::string classname(void) const
Return class name.
GXmlDocument & operator=(const GXmlDocument &node)
Assignment operator.
const std::string & value(void) const
Return attribute value.
GXmlAttribute m_standalone
Standalone (&quot;yes&quot;, &quot;no&quot;)
std::string encoding(void) const
Return encoding.
const GFilename & filename(void) const
Return filename.
GXmlAttribute m_encoding
Encoding (e.g. &quot;UTF-8&quot;)
void free_members(void)
Delete class members.
virtual std::string print(const GChatter &chatter=NORMAL, const int &indent=0) const
Print XML document.
Abstract XML node base class interface definition.
virtual void clear(void)
Clear XML document.
Filename class interface definition.
XML attribute class interface definition.
void init_members(void)
Initialise class members.