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 
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:
144 
149  CXMLDocument(const char *init);
150 
151 
158 
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
CXMLElement::set_child_text
void set_child_text(const std::string &value)
CXMLElement::get_children
std::vector< CXMLElement::Pointer > get_children(const char *name) const
CXMLElement::CXMLElement
CXMLElement(const CXMLElement &orig)=delete
NS_MIA_BEGIN
#define NS_MIA_BEGIN
conveniance define to start the mia namespace
Definition: defines.hh:33
CXMLElement::set_attribute
void set_attribute(const char *name, const std::string &value)
Set an attribute of the node.
CXMLElement::~CXMLElement
~CXMLElement()
CXMLElement::add_child
CXMLElement::Pointer add_child(const char *name)
add a new child element
CXMLDocument::write_to_string
std::string write_to_string(const char *encoding=NULL, bool formatted=true) const
CXMLElement::get_all_children
const std::vector< CXMLElement::Pointer > & get_all_children() const
NS_MIA_END
#define NS_MIA_END
conveniance define to end the mia namespace
Definition: defines.hh:36
CXMLElement::get_attribute
const std::string get_attribute(const std::string &name) const
CXMLElement
This class implements a facade for the xml Element.
Definition: xmlinterface.hh:50
CXMLDocument::create_root_node
CXMLElement::Pointer create_root_node(const char *name)
CXMLDocument
facate for an XML document
Definition: xmlinterface.hh:137
CXMLElement::get_content
const std::string & get_content() const
CXMLDocument::CXMLDocument
CXMLDocument(const char *init)
CXMLElement::get_name
const std::string & get_name() const
EXPORT_CORE
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
CXMLDocument::get_root_node
CXMLElement::Pointer get_root_node() const
CXMLElement::CXMLElement
CXMLElement(const char *name)
CXMLDocument::read_from_string
bool read_from_string(const char *init)
CXMLDocument::CXMLDocument
CXMLDocument()
defines.hh