FotoSHOCK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
XmlNode.hpp
1 /*
2  * Copyright 2012 Lukas Jirkovsky
3  *
4  * This file is part of FotoSHOCKcore.
5  *
6  * FotoSHOCKcore is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, version 3 of the License.
9  *
10  * FotoSHOCKcore is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with FotoSHOCKcore. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef XMLNODE_H
20 #define XMLNODE_H
21 
22 #include "NVPtype.hpp"
23 
24 namespace FotoSHOCKcore {
25 
26 class XmlSerializer;
27 
28 class XmlNode {
29  public:
30  template <typename T>
31  XmlNode(const XmlNode& parent, const NVPtype<T>& nvp) : m_node(xmlNewNode(NULL, nvp.m_name)) {
32  xmlAddChild(parent.m_node, m_node);
33  xmlAddChild(m_node, nvp.m_content);
34  }
35 
36  template <typename T>
37  XmlNode(const xmlNodePtr parent, const NVPtype<T>& nvp) : m_node(xmlNewNode(NULL, nvp.m_name)) {
38  xmlAddChild(parent, m_node);
39  xmlAddChild(m_node, nvp.m_content);
40  }
41 
43  explicit XmlNode(const xmlNodePtr node) : m_node(node)
44  {}
45 
47  template <typename T>
48  void insertProp(const NVPtype<T>& nvp) {
49  xmlNewProp(m_node, nvp.m_name, nvp.m_content->content);
50  }
51 
52  xmlNodePtr node() const {
53  return m_node;
54  }
55  private:
56  const xmlNodePtr m_node;
57 };
58 
59 }
60 
61 #endif