FotoSHOCK
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
NVPtype.hpp
1 /*
2  * Copyright 2011, 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 NVPTYPE_H
20 #define NVPTYPE_H
21 
22 #include "TypeSerializer.hpp"
23 
24 namespace FotoSHOCKcore {
25 
26 class GraphManager;
27 
29 
46 template <typename T>
47 class NVPtype {
48  public:
49  friend class XmlNode;
50 
51  NVPtype(const char* name, T value, std::size_t /*length*/ = 1) : m_name(BAD_CAST name) {
52  m_content = TypeSerializer<T>::serialize(value);
53  }
54 
55  ~NVPtype()
56  {}
57  protected:
58  const xmlChar* m_name;
59  // text node (ie. node creted using xmlNewText())
60  xmlNodePtr m_content;
61 };
62 
64 
67 template <typename T>
68 class NVPtype<T*> {
69  public:
70  friend class XmlNode;
71 
72  NVPtype(const char* name, T* value, std::size_t length) : m_name(BAD_CAST name) {
73  if (length > 0) {
74  // TODO: use TypeSerializer<T>::serialize(value) to store value of each element of the array
75  }
76  else {
77  m_content = NULL;
78  }
79  }
80 
81  ~NVPtype()
82  {}
83  protected:
84  const xmlChar* m_name;
85  xmlNodePtr m_content;
86 };
87 
88 /*
89  * SPECIALIZATIONS OF NVPtype FOR COMMON TYPES
90  */
91 
93 
96 template <>
97 class NVPtype<const char*> {
98  public:
99  friend class XmlNode;
100 
101  NVPtype(const char* name, const char* value, std::size_t /*length*/) : m_name(BAD_CAST name) {
102  m_content = TypeSerializer<const char*>::serialize(value);
103  }
104 
105  ~NVPtype()
106  {}
107  protected:
108  const xmlChar* m_name;
109  xmlNodePtr m_content;
110 };
111 
113 
123 inline NVPtype<int*> nvp(const char* name) {
124  return NVPtype<int*>(name, (int*)0, 0);
125 }
126 
128 
136 template <typename T>
137 NVPtype<T> nvp(const char* name, T value) {
138  return NVPtype<T>(name, value, 1);
139 }
140 
142 
153 template <typename T>
154 NVPtype<T*> nvp(const char* name, T* value, std::size_t size) {
155  return NVPtype<T*>(name, value, size);
156 }
157 
158 }
159 
160 #endif // NVPTYPE_H