My Project
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 {
51 public:
52  typedef std::shared_ptr<CXMLElement> Pointer;
53 
58  CXMLElement(const char *name);
59 
60  ~CXMLElement();
61 
62  // do not allow copying
63  CXMLElement(const CXMLElement& orig) = delete;
64  CXMLElement& operator = (const CXMLElement& orig) = delete;
65 
75  CXMLElement::Pointer add_child(const char *name);
76 
84  void set_attribute(const char *name, const std::string& value);
85 
90  void set_child_text(const std::string& value);
91 
93  const std::string& get_name() const;
94 
101  const std::string get_attribute(const std::string& name) const;
102 
103 
105 
106  const std::vector<CXMLElement::Pointer>& get_all_children() const;
107 
108 
115  std::vector<CXMLElement::Pointer> get_children(const char *name) const;
116 
118  const std::string& get_content() const;
119 
120 private:
121 
122  struct CXMLElementImpl *impl;
123  friend CXMLElementImpl;
124  friend class CXMLDocument;
125 };
126 
127 
137 {
138 public:
143  CXMLDocument();
144 
149  CXMLDocument(const char *init);
150 
151 
157  CXMLElement::Pointer create_root_node(const char *name);
158 
163  CXMLElement::Pointer get_root_node() const;
164 
170  bool read_from_string(const char *init);
171 
178  std::string write_to_string(const char *encoding = NULL, bool formatted = true) const;
179 
180 private:
181  friend class CXMLElement;
182  CXMLElement::Pointer m_root;
183 
184  std::string m_last_error;
185 };
186 
188 
189 #endif
CXMLElement::Pointer
std::shared_ptr< CXMLElement > Pointer
Definition: xmlinterface.hh:52
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
CXMLDocument
class EXPORT_CORE CXMLDocument
Definition: xmlinterface.hh:32
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
CXMLElement
This class implements a facade for the xml Element.
Definition: xmlinterface.hh:49
CXMLDocument
facate for an XML document
Definition: xmlinterface.hh:136
EXPORT_CORE
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
defines.hh