xmlinterface.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2017 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 #ifndef mia_core_xmlinterface_hh
23 #define mia_core_xmlinterface_hh
24 
25 #include <mia/core/defines.hh>
26 #include <memory>
27 #include <vector>
28 
29 
31 
33 
50 public:
51  typedef std::shared_ptr<CXMLElement> Pointer;
52 
57  CXMLElement(const char *name);
58 
59  ~CXMLElement();
60 
61  // do not allow copying
62  CXMLElement(const CXMLElement& orig) = delete;
63  CXMLElement& operator = (const CXMLElement& orig) = delete;
64 
74  CXMLElement::Pointer add_child(const char *name);
75 
83  void set_attribute(const char *name, const std::string& value);
84 
89  void set_child_text(const std::string& value);
90 
92  const std::string& get_name() const;
93 
100  const std::string get_attribute(const std::string& name) const;
101 
102 
104 
105  const std::vector<CXMLElement::Pointer>& get_all_children() const;
106 
107 
114  std::vector<CXMLElement::Pointer> get_children(const char *name) const;
115 
117  const std::string& get_content() const;
118 
119 private:
120 
121  struct CXMLElementImpl *impl;
122  friend CXMLElementImpl;
123  friend class CXMLDocument;
124 };
125 
126 
136 public:
141  CXMLDocument();
142 
147  CXMLDocument(const char *init);
148 
149 
155  CXMLElement::Pointer create_root_node(const char *name);
156 
161  CXMLElement::Pointer get_root_node() const;
162 
168  bool read_from_string(const char *init);
169 
176  std::string write_to_string(const char *encoding = NULL, bool formatted = true) const;
177 
178 private:
179  friend class CXMLElement;
180  CXMLElement::Pointer m_root;
181 
182  std::string m_last_error;
183 };
184 
186 
187 #endif
std::shared_ptr< CXMLElement > Pointer
Definition: xmlinterface.hh:51
class EXPORT_CORE CXMLDocument
Definition: xmlinterface.hh:32
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
facate for an XML document
This class implements a facade for the xml Element.
Definition: xmlinterface.hh:49
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36