2 * Copyright 2008 Aike J Sommer <dev@aikesommer.name>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 template <class ElementType
, typename SimpleType
>
25 XMLSimpleNodeHandler
<ElementType
, SimpleType
>::XMLSimpleNodeHandler(Getter getter
, Setter setter
) {
30 template <class ElementType
, typename SimpleType
>
31 void XMLSimpleNodeHandler
<ElementType
, SimpleType
>::beginSave(XMLType
* element
) {
36 template <class ElementType
, typename SimpleType
>
37 void XMLSimpleNodeHandler
<ElementType
, SimpleType
>::beginLoad(XMLType
* element
) {
41 template <class ElementType
, typename SimpleType
>
42 bool XMLSimpleNodeHandler
<ElementType
, SimpleType
>::hasMore(XMLType
* element
) {
47 template <class ElementType
, typename SimpleType
>
48 void XMLSimpleNodeHandler
<ElementType
, SimpleType
>::setNode(XMLType
* element
, QDomNode node
) {
49 QDomNode child
= node
.firstChild();
50 if (! child
.isNull()) {
51 ((ElementType
*)element
->*m_setter
)(toValue(child
.nodeValue()));
55 template <class ElementType
, typename SimpleType
>
56 QDomNode XMLSimpleNodeHandler
<ElementType
, SimpleType
>::node(XMLType
* element
, QDomDocument doc
, QString name
) {
58 QDomNode node
= doc
.createElement(name
);
59 node
.appendChild(doc
.createTextNode(toString(((ElementType
*)element
->*m_getter
)())));
63 template <class ElementType
, typename SimpleType
>
64 QString XMLSimpleNodeHandler
<ElementType
, SimpleType
>::str(XMLType
* element
) {
65 return toString(((ElementType
*)element
->*m_getter
)());
70 template <class ElementType
>
71 XMLStringNodeHandler
<ElementType
>::XMLStringNodeHandler(Getter getter
, Setter setter
) : XMLSimpleNodeHandler
<ElementType
, QString
>(getter
, setter
) {
74 template <class ElementType
>
75 QString XMLStringNodeHandler
<ElementType
>::toValue(QString str
) {
79 template <class ElementType
>
80 QString XMLStringNodeHandler
<ElementType
>::toString(QString str
) {
86 template <class ElementType
>
87 XMLIntNodeHandler
<ElementType
>::XMLIntNodeHandler(Getter getter
, Setter setter
) : XMLSimpleNodeHandler
<ElementType
, int>(getter
, setter
) {
90 template <class ElementType
>
91 int XMLIntNodeHandler
<ElementType
>::toValue(QString str
) {
95 template <class ElementType
>
96 QString XMLIntNodeHandler
<ElementType
>::toString(int i
) {
97 return QString::number(i
);
102 template <class ElementType
>
103 XMLUIntNodeHandler
<ElementType
>::XMLUIntNodeHandler(Getter getter
, Setter setter
) : XMLSimpleNodeHandler
<ElementType
, unsigned int>(getter
, setter
) {
106 template <class ElementType
>
107 unsigned int XMLUIntNodeHandler
<ElementType
>::toValue(QString str
) {
111 template <class ElementType
>
112 QString XMLUIntNodeHandler
<ElementType
>::toString(unsigned int i
) {
113 return QString::number(i
);
118 template <class ElementType
>
119 XMLDoubleNodeHandler
<ElementType
>::XMLDoubleNodeHandler(Getter getter
, Setter setter
) : XMLSimpleNodeHandler
<ElementType
, double>(getter
, setter
) {
122 template <class ElementType
>
123 double XMLDoubleNodeHandler
<ElementType
>::toValue(QString str
) {
124 return str
.toDouble();
127 template <class ElementType
>
128 QString XMLDoubleNodeHandler
<ElementType
>::toString(double i
) {
129 return QString::number(i
);
134 template <class ElementType
>
135 XMLBoolNodeHandler
<ElementType
>::XMLBoolNodeHandler(Getter getter
, Setter setter
) : XMLSimpleNodeHandler
<ElementType
, bool>(getter
, setter
) {
138 template <class ElementType
>
139 bool XMLBoolNodeHandler
<ElementType
>::toValue(QString str
) {
140 return str
== "true" || str
== "t" || str
== "on" || str
== "1";
143 template <class ElementType
>
144 QString XMLBoolNodeHandler
<ElementType
>::toString(bool b
) {
145 return b
? "true" : "false";
150 template <class ElementType
, class ComplexType
>
151 XMLComplexNodeHandler
<ElementType
, ComplexType
>::XMLComplexNodeHandler(XMLFactory
* factory
, Setter setter
) {
156 template <class ElementType
, typename ComplexType
>
157 void XMLComplexNodeHandler
<ElementType
, ComplexType
>::beginSave(XMLType
* element
) {
162 template <class ElementType
, typename ComplexType
>
163 void XMLComplexNodeHandler
<ElementType
, ComplexType
>::beginLoad(XMLType
* element
) {
167 template <class ElementType
, typename ComplexType
>
168 bool XMLComplexNodeHandler
<ElementType
, ComplexType
>::hasMore(XMLType
* element
) {
173 template <class ElementType
, typename ComplexType
>
174 void XMLComplexNodeHandler
<ElementType
, ComplexType
>::setNode(XMLType
* element
, QDomNode node
) {
175 ComplexType
* complex = (ComplexType
*) m_factory
->load(node
);
176 ((ElementType
*)element
->*m_setter
)(complex);
179 template <class ElementType
, typename ComplexType
>
180 QDomNode XMLComplexNodeHandler
<ElementType
, ComplexType
>::node(XMLType
* element
, QDomDocument doc
, QString name
) {
187 template <class ElementType
, typename ComplexType
>
188 QString XMLComplexNodeHandler
<ElementType
, ComplexType
>::str(XMLType
* element
) {
195 template <class ElementType
, class ComplexType
>
196 XMLComplexListNodeHandler
<ElementType
, ComplexType
>::XMLComplexListNodeHandler(XMLFactory
* factory
, ListGetter listGetter
) {
198 m_listGetter
= listGetter
;
201 template <class ElementType
, typename ComplexType
>
202 bool XMLComplexListNodeHandler
<ElementType
, ComplexType
>::hasMore(XMLType
* element
) {
203 return m_pos
< ((ElementType
*)element
->*m_listGetter
)().size();
206 template <class ElementType
, typename ComplexType
>
207 void XMLComplexListNodeHandler
<ElementType
, ComplexType
>::setNode(XMLType
* element
, QDomNode node
) {
208 ComplexType
* complex = (ComplexType
*) m_factory
->load(node
);
209 ((ElementType
*)element
->*m_listGetter
)().append(complex);
212 template <class ElementType
, typename ComplexType
>
213 QDomNode XMLComplexListNodeHandler
<ElementType
, ComplexType
>::node(XMLType
* element
, QDomDocument doc
, QString name
) {
214 ComplexType
* complex = ((ElementType
*)element
->*m_listGetter
)().at(m_pos
);
216 return m_factory
->save(complex, doc
, name
);
219 template <class ElementType
, typename ComplexType
>
220 void XMLComplexListNodeHandler
<ElementType
, ComplexType
>::beginSave(XMLType
* element
) {
225 template <class ElementType
, typename ComplexType
>
226 void XMLComplexListNodeHandler
<ElementType
, ComplexType
>::beginLoad(XMLType
* element
) {
227 ((ElementType
*)element
->*m_listGetter
)().clear();
230 template <class ElementType
, typename ComplexType
>
231 QString XMLComplexListNodeHandler
<ElementType
, ComplexType
>::str(XMLType
* element
) {