author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 0 | 1918ee327afb |
permissions | -rw-r--r-- |
0 | 1 |
<!DOCTYPE xsl:stylesheet [ |
2 |
<!ENTITY endl " "> |
|
3 |
]> |
|
4 |
<xsl:stylesheet version="1.0" |
|
5 |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
|
6 |
xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
|
7 |
||
8 |
<xsl:output method="text"/> |
|
9 |
||
10 |
<xsl:include href="generate_shared.xsl"/> |
|
11 |
||
12 |
<!-- Implementation: constructor --> |
|
13 |
||
14 |
<xsl:template name="ctor-init-attributes"> |
|
15 |
<xsl:param name="node"/> |
|
16 |
<xsl:for-each select="$node/xs:attribute"> |
|
17 |
<xsl:variable name="camel-case-name"> |
|
18 |
<xsl:call-template name="camel-case"> |
|
19 |
<xsl:with-param name="text" select="@name"/> |
|
20 |
</xsl:call-template> |
|
21 |
</xsl:variable> |
|
22 |
<xsl:text> m_has_attr_</xsl:text> |
|
23 |
<xsl:value-of select="$camel-case-name"/> |
|
24 |
<xsl:text> = false;&endl;</xsl:text> |
|
25 |
<xsl:choose> |
|
26 |
<xsl:when test="@type = 'xs:integer'"> |
|
27 |
<xsl:text> m_attr_</xsl:text> |
|
28 |
<xsl:value-of select="$camel-case-name"/> |
|
29 |
<xsl:text> = 0;&endl;</xsl:text> |
|
30 |
</xsl:when> |
|
31 |
<xsl:when test="@type = 'xs:double'"> |
|
32 |
<xsl:text> m_attr_</xsl:text> |
|
33 |
<xsl:value-of select="$camel-case-name"/> |
|
34 |
<xsl:text> = 0.0;&endl;</xsl:text> |
|
35 |
</xsl:when> |
|
36 |
<xsl:when test="@type = 'xs:float'"> |
|
37 |
<xsl:text> m_attr_</xsl:text> |
|
38 |
<xsl:value-of select="$camel-case-name"/> |
|
39 |
<xsl:text> = 0.0;&endl;</xsl:text> |
|
40 |
</xsl:when> |
|
41 |
<xsl:when test="@type = 'xs:boolean'"> |
|
42 |
<xsl:text> m_attr_</xsl:text> |
|
43 |
<xsl:value-of select="$camel-case-name"/> |
|
44 |
<xsl:text> = false;&endl;</xsl:text> |
|
45 |
</xsl:when> |
|
46 |
</xsl:choose> |
|
47 |
</xsl:for-each> |
|
48 |
</xsl:template> |
|
49 |
||
50 |
<xsl:template name="ctor-init-child-elements"> |
|
51 |
<xsl:param name="node"/> |
|
52 |
<xsl:for-each select="$node/xs:element"> |
|
53 |
<xsl:variable name="array" select="@maxOccurs='unbounded'"/> |
|
54 |
<xsl:if test="not($array)"> |
|
55 |
<xsl:variable name="cpp-type"> |
|
56 |
<xsl:call-template name="xs-type-to-cpp-type"> |
|
57 |
<xsl:with-param name="xs-type" select="@type"/> |
|
58 |
<xsl:with-param name="array" select="$array"/> |
|
59 |
</xsl:call-template> |
|
60 |
</xsl:variable> |
|
61 |
<xsl:variable name="camel-case-name"> |
|
62 |
<xsl:call-template name="camel-case"> |
|
63 |
<xsl:with-param name="text" select="@name"/> |
|
64 |
</xsl:call-template> |
|
65 |
</xsl:variable> |
|
66 |
<xsl:choose> |
|
67 |
<xsl:when test="@type = 'xs:integer'"> |
|
68 |
<xsl:text> m_</xsl:text> |
|
69 |
<xsl:value-of select="$camel-case-name"/> |
|
70 |
<xsl:text> = 0;&endl;</xsl:text> |
|
71 |
</xsl:when> |
|
72 |
<xsl:when test="@type = 'xs:float'"> |
|
73 |
<xsl:text> m_</xsl:text> |
|
74 |
<xsl:value-of select="$camel-case-name"/> |
|
75 |
<xsl:text> = 0.0;&endl;</xsl:text> |
|
76 |
</xsl:when> |
|
77 |
<xsl:when test="@type = 'xs:boolean'"> |
|
78 |
<xsl:text> m_</xsl:text> |
|
79 |
<xsl:value-of select="$camel-case-name"/> |
|
80 |
<xsl:text> = false;&endl;</xsl:text> |
|
81 |
</xsl:when> |
|
82 |
<xsl:when test="@type = 'xs:string'"></xsl:when> |
|
83 |
<xsl:otherwise> |
|
84 |
<xsl:text> m_</xsl:text> |
|
85 |
<xsl:value-of select="$camel-case-name"/> |
|
86 |
<xsl:text> = 0;&endl;</xsl:text> |
|
87 |
</xsl:otherwise> |
|
88 |
</xsl:choose> |
|
89 |
</xsl:if> |
|
90 |
</xsl:for-each> |
|
91 |
</xsl:template> |
|
92 |
||
93 |
<xsl:template name="ctor-init-members"> |
|
94 |
<xsl:param name="node"/> |
|
95 |
||
96 |
<xsl:if test="boolean($node/xs:choice)"> |
|
97 |
<xsl:text> m_kind = Unknown;&endl;&endl;</xsl:text> |
|
98 |
</xsl:if> |
|
99 |
||
100 |
<xsl:if test="not($node/xs:choice)"> |
|
101 |
<xsl:text> m_children = 0;&endl;</xsl:text> |
|
102 |
</xsl:if> |
|
103 |
||
104 |
<xsl:call-template name="ctor-init-attributes"> |
|
105 |
<xsl:with-param name="node" select="."/> |
|
106 |
</xsl:call-template> |
|
107 |
||
108 |
<xsl:if test="$node[@mixed='true']"> |
|
109 |
<xsl:text> m_text = QLatin1String("");&endl;</xsl:text> |
|
110 |
</xsl:if> |
|
111 |
||
112 |
<xsl:for-each select="$node//xs:sequence | $node//xs:choice | $node//xs:all"> |
|
113 |
<xsl:call-template name="ctor-init-child-elements"> |
|
114 |
<xsl:with-param name="node" select="."/> |
|
115 |
</xsl:call-template> |
|
116 |
</xsl:for-each> |
|
117 |
</xsl:template> |
|
118 |
||
119 |
<xsl:template name="ctor-impl"> |
|
120 |
<xsl:param name="node"/> |
|
121 |
<xsl:variable name="name" select="concat('Dom', $node/@name)"/> |
|
122 |
||
123 |
<xsl:value-of select="$name"/> |
|
124 |
<xsl:text>::</xsl:text> |
|
125 |
<xsl:value-of select="$name"/> |
|
126 |
<xsl:text>()&endl;</xsl:text> |
|
127 |
<xsl:text>{&endl;</xsl:text> |
|
128 |
<xsl:call-template name="ctor-init-members"> |
|
129 |
<xsl:with-param name="node" select="$node"/> |
|
130 |
</xsl:call-template> |
|
131 |
<xsl:text>}&endl;&endl;</xsl:text> |
|
132 |
</xsl:template> |
|
133 |
||
134 |
<!-- Implementation: destructor --> |
|
135 |
||
136 |
<xsl:template name="dtor-delete-members"> |
|
137 |
<xsl:param name="node"/> |
|
138 |
||
139 |
<xsl:for-each select="$node/xs:element"> |
|
140 |
<xsl:variable name="camel-case-name"> |
|
141 |
<xsl:call-template name="camel-case"> |
|
142 |
<xsl:with-param name="text" select="@name"/> |
|
143 |
</xsl:call-template> |
|
144 |
</xsl:variable> |
|
145 |
<xsl:variable name="xs-type-cat"> |
|
146 |
<xsl:call-template name="xs-type-category"> |
|
147 |
<xsl:with-param name="xs-type" select="@type"/> |
|
148 |
</xsl:call-template> |
|
149 |
</xsl:variable> |
|
150 |
<xsl:choose> |
|
151 |
<xsl:when test="@maxOccurs='unbounded'"> |
|
152 |
<xsl:if test="$xs-type-cat = 'pointer'"> |
|
153 |
<xsl:text> qDeleteAll(m_</xsl:text> |
|
154 |
<xsl:value-of select="$camel-case-name"/> |
|
155 |
<xsl:text>);&endl;</xsl:text> |
|
156 |
</xsl:if> |
|
157 |
<xsl:text> m_</xsl:text> |
|
158 |
<xsl:value-of select="$camel-case-name"/> |
|
159 |
<xsl:text>.clear();&endl;</xsl:text> |
|
160 |
</xsl:when> |
|
161 |
<xsl:otherwise> |
|
162 |
<xsl:if test="$xs-type-cat = 'pointer'"> |
|
163 |
<xsl:text> delete m_</xsl:text> |
|
164 |
<xsl:value-of select="$camel-case-name"/> |
|
165 |
<xsl:text>;&endl;</xsl:text> |
|
166 |
</xsl:if> |
|
167 |
</xsl:otherwise> |
|
168 |
</xsl:choose> |
|
169 |
</xsl:for-each> |
|
170 |
</xsl:template> |
|
171 |
||
172 |
<xsl:template name="dtor-impl"> |
|
173 |
<xsl:param name="node"/> |
|
174 |
<xsl:variable name="name" select="concat('Dom', $node/@name)"/> |
|
175 |
||
176 |
<xsl:value-of select="$name"/> |
|
177 |
<xsl:text>::~</xsl:text> |
|
178 |
<xsl:value-of select="$name"/> |
|
179 |
<xsl:text>()&endl;</xsl:text> |
|
180 |
<xsl:text>{&endl;</xsl:text> |
|
181 |
||
182 |
<xsl:for-each select="$node//xs:sequence | $node//xs:choice | $node//xs:all"> |
|
183 |
<xsl:call-template name="dtor-delete-members"> |
|
184 |
<xsl:with-param name="node" select="."/> |
|
185 |
</xsl:call-template> |
|
186 |
</xsl:for-each> |
|
187 |
||
188 |
<xsl:text>}&endl;&endl;</xsl:text> |
|
189 |
</xsl:template> |
|
190 |
||
191 |
<!-- Implementation: clear() --> |
|
192 |
||
193 |
<xsl:template name="clear-impl"> |
|
194 |
<xsl:param name="node"/> |
|
195 |
<xsl:variable name="name" select="concat('Dom', $node/@name)"/> |
|
196 |
||
197 |
<xsl:text>void </xsl:text><xsl:value-of select="$name"/> |
|
198 |
<xsl:text>::clear(bool clear_all)&endl;</xsl:text> |
|
199 |
<xsl:text>{&endl;</xsl:text> |
|
200 |
||
201 |
<xsl:for-each select="$node//xs:sequence | $node//xs:choice | $node//xs:all"> |
|
202 |
<xsl:call-template name="dtor-delete-members"> |
|
203 |
<xsl:with-param name="node" select="."/> |
|
204 |
</xsl:call-template> |
|
205 |
</xsl:for-each> |
|
206 |
||
207 |
<xsl:text>&endl; if (clear_all) {&endl;</xsl:text> |
|
208 |
||
209 |
<xsl:choose> |
|
210 |
<xsl:when test="$node[@mixed='true']"> |
|
211 |
<xsl:text> m_text = QLatin1String("");&endl;</xsl:text> |
|
212 |
</xsl:when> |
|
213 |
<xsl:otherwise> |
|
214 |
<xsl:text> m_text.clear();&endl;</xsl:text> |
|
215 |
</xsl:otherwise> |
|
216 |
</xsl:choose> |
|
217 |
||
218 |
<xsl:call-template name="ctor-init-attributes"> |
|
219 |
<xsl:with-param name="node" select="."/> |
|
220 |
</xsl:call-template> |
|
221 |
<xsl:text> }&endl;&endl;</xsl:text> |
|
222 |
||
223 |
<xsl:if test="boolean($node/xs:choice)"> |
|
224 |
<xsl:text> m_kind = Unknown;&endl;&endl;</xsl:text> |
|
225 |
</xsl:if> |
|
226 |
||
227 |
<xsl:if test="not($node/xs:choice)"> |
|
228 |
<xsl:text> m_children = 0;&endl;</xsl:text> |
|
229 |
</xsl:if> |
|
230 |
||
231 |
<xsl:for-each select="$node//xs:sequence | $node//xs:choice | $node//xs:all"> |
|
232 |
<xsl:call-template name="ctor-init-child-elements"> |
|
233 |
<xsl:with-param name="node" select="."/> |
|
234 |
</xsl:call-template> |
|
235 |
</xsl:for-each> |
|
236 |
||
237 |
<xsl:text>}&endl;&endl;</xsl:text> |
|
238 |
||
239 |
</xsl:template> |
|
240 |
||
241 |
<!-- Format a string constant as QString(QLatin1Char('X')) or QLatin1String("foo"), respectively --> |
|
242 |
<xsl:template name="string-constant"> |
|
243 |
<xsl:param name="literal"/> |
|
244 |
<xsl:choose> |
|
245 |
<xsl:when test="string-length($literal) < 2"> |
|
246 |
<xsl:text>QString(QLatin1Char('</xsl:text> |
|
247 |
<xsl:value-of select="$literal"/> |
|
248 |
<xsl:text>'))</xsl:text> |
|
249 |
</xsl:when> |
|
250 |
<xsl:otherwise> |
|
251 |
<xsl:text>QLatin1String("</xsl:text> |
|
252 |
<xsl:value-of select="$literal"/> |
|
253 |
<xsl:text>")</xsl:text> |
|
254 |
</xsl:otherwise> |
|
255 |
</xsl:choose> |
|
256 |
</xsl:template> |
|
257 |
||
258 |
<!-- Implementation: read(QXmlStreamReader) --> |
|
259 |
||
260 |
<xsl:template name="read-impl-load-attributes"> |
|
261 |
<xsl:param name="node"/> |
|
262 |
||
263 |
<xsl:if test="$node/xs:attribute"> |
|
264 |
<xsl:text>&endl;</xsl:text> |
|
265 |
<xsl:text> foreach (const QXmlStreamAttribute &attribute, reader.attributes()) {&endl;</xsl:text> |
|
266 |
<xsl:text> QStringRef name = attribute.name();&endl;</xsl:text> |
|
267 |
||
268 |
<xsl:for-each select="$node/xs:attribute"> |
|
269 |
<xsl:variable name="camel-case-name"> |
|
270 |
<xsl:call-template name="camel-case"> |
|
271 |
<xsl:with-param name="text" select="@name"/> |
|
272 |
</xsl:call-template> |
|
273 |
</xsl:variable> |
|
274 |
<xsl:variable name="cap-name"> |
|
275 |
<xsl:call-template name="cap-first-char"> |
|
276 |
<xsl:with-param name="text" select="$camel-case-name"/> |
|
277 |
</xsl:call-template> |
|
278 |
</xsl:variable> |
|
279 |
<xsl:variable name="qstring-func"> |
|
280 |
<xsl:call-template name="xs-type-from-qstring-func"> |
|
281 |
<xsl:with-param name="xs-type" select="@type"/> |
|
282 |
<xsl:with-param name="val"> |
|
283 |
<xsl:text>attribute.value().toString()</xsl:text> |
|
284 |
</xsl:with-param> |
|
285 |
</xsl:call-template> |
|
286 |
</xsl:variable> |
|
287 |
||
288 |
<xsl:text> if (name == </xsl:text> |
|
289 |
<xsl:call-template name="string-constant"> |
|
290 |
<xsl:with-param name="literal" select="@name"/> |
|
291 |
</xsl:call-template> |
|
292 |
<xsl:text>) {&endl;</xsl:text> |
|
293 |
<xsl:text> setAttribute</xsl:text> |
|
294 |
<xsl:value-of select="$cap-name"/> |
|
295 |
<xsl:text>(</xsl:text> |
|
296 |
<xsl:value-of select="$qstring-func"/> |
|
297 |
<xsl:text>);&endl;</xsl:text> |
|
298 |
<xsl:text> continue;&endl;</xsl:text> |
|
299 |
<xsl:text> }&endl;</xsl:text> |
|
300 |
</xsl:for-each> |
|
301 |
||
302 |
<xsl:text> reader.raiseError(QLatin1String("Unexpected attribute ") + name.toString());&endl;</xsl:text> |
|
303 |
<xsl:text> }&endl;</xsl:text> |
|
304 |
</xsl:if> |
|
305 |
</xsl:template> |
|
306 |
||
307 |
<xsl:template name="read-impl-load-child-element"> |
|
308 |
<xsl:param name="node"/> |
|
309 |
||
310 |
<xsl:for-each select="$node/xs:element"> |
|
311 |
<xsl:variable name="camel-case-name"> |
|
312 |
<xsl:call-template name="camel-case"> |
|
313 |
<xsl:with-param name="text" select="@name"/> |
|
314 |
</xsl:call-template> |
|
315 |
</xsl:variable> |
|
316 |
||
317 |
<xsl:variable name="cap-name"> |
|
318 |
<xsl:call-template name="cap-first-char"> |
|
319 |
<xsl:with-param name="text" select="$camel-case-name"/> |
|
320 |
</xsl:call-template> |
|
321 |
</xsl:variable> |
|
322 |
<xsl:variable name="xs-type-cat"> |
|
323 |
<xsl:call-template name="xs-type-category"> |
|
324 |
<xsl:with-param name="xs-type" select="@type"/> |
|
325 |
</xsl:call-template> |
|
326 |
</xsl:variable> |
|
327 |
<xsl:variable name="lower-name"> |
|
328 |
<xsl:call-template name="lower-text"> |
|
329 |
<xsl:with-param name="text" select="@name"/> |
|
330 |
</xsl:call-template> |
|
331 |
</xsl:variable> |
|
332 |
<xsl:variable name="array" select="@maxOccurs = 'unbounded'"/> |
|
333 |
||
334 |
<xsl:text> if (tag == </xsl:text> |
|
335 |
<xsl:call-template name="string-constant"> |
|
336 |
<xsl:with-param name="literal" select="$lower-name"/> |
|
337 |
</xsl:call-template> |
|
338 |
<xsl:text>) {&endl;</xsl:text> |
|
339 |
||
340 |
<xsl:choose> |
|
341 |
<xsl:when test="not($array) and $xs-type-cat = 'value'"> |
|
342 |
<xsl:variable name="qstring-func"> |
|
343 |
<xsl:call-template name="xs-type-from-qstring-func"> |
|
344 |
<xsl:with-param name="xs-type" select="@type"/> |
|
345 |
<xsl:with-param name="val" select="'reader.readElementText()'"/> |
|
346 |
</xsl:call-template> |
|
347 |
</xsl:variable> |
|
348 |
||
349 |
<xsl:text> setElement</xsl:text> |
|
350 |
<xsl:value-of select="$cap-name"/> |
|
351 |
<xsl:text>(</xsl:text> |
|
352 |
<xsl:value-of select="$qstring-func"/> |
|
353 |
<xsl:text>);&endl;</xsl:text> |
|
354 |
</xsl:when> |
|
355 |
<xsl:when test="@maxOccurs='unbounded' and $xs-type-cat = 'value'"> |
|
356 |
<xsl:variable name="qstring-func"> |
|
357 |
<xsl:call-template name="xs-type-from-qstring-func"> |
|
358 |
<xsl:with-param name="xs-type" select="@type"/> |
|
359 |
<xsl:with-param name="val" select="'reader.readElementText()'"/> |
|
360 |
</xsl:call-template> |
|
361 |
</xsl:variable> |
|
362 |
||
363 |
<xsl:text> m_</xsl:text> |
|
364 |
<xsl:value-of select="$camel-case-name"/> |
|
365 |
<xsl:text>.append(</xsl:text> |
|
366 |
<xsl:value-of select="$qstring-func"/> |
|
367 |
<xsl:text>);&endl;</xsl:text> |
|
368 |
</xsl:when> |
|
369 |
<xsl:when test="not(@maxOccurs='unbounded') and $xs-type-cat = 'pointer'"> |
|
370 |
<xsl:text> Dom</xsl:text> |
|
371 |
<xsl:value-of select="@type"/> |
|
372 |
<xsl:text> *v = new Dom</xsl:text> |
|
373 |
<xsl:value-of select="@type"/> |
|
374 |
<xsl:text>();&endl;</xsl:text> |
|
375 |
<xsl:text> v->read(reader);&endl;</xsl:text> |
|
376 |
<xsl:text> setElement</xsl:text> |
|
377 |
<xsl:value-of select="$cap-name"/> |
|
378 |
<xsl:text>(v);&endl;</xsl:text> |
|
379 |
</xsl:when> |
|
380 |
<xsl:when test="@maxOccurs='unbounded' and $xs-type-cat = 'pointer'"> |
|
381 |
<xsl:text> Dom</xsl:text> |
|
382 |
<xsl:value-of select="@type"/> |
|
383 |
<xsl:text> *v = new Dom</xsl:text> |
|
384 |
<xsl:value-of select="@type"/> |
|
385 |
<xsl:text>();&endl;</xsl:text> |
|
386 |
<xsl:text> v->read(reader);&endl;</xsl:text> |
|
387 |
<xsl:text> m_</xsl:text> |
|
388 |
<xsl:value-of select="$camel-case-name"/> |
|
389 |
<xsl:text>.append(v);&endl;</xsl:text> |
|
390 |
</xsl:when> |
|
391 |
</xsl:choose> |
|
392 |
<xsl:text> continue;&endl;</xsl:text> |
|
393 |
<xsl:text> }&endl;</xsl:text> |
|
394 |
</xsl:for-each> |
|
395 |
</xsl:template> |
|
396 |
||
397 |
<xsl:template name="read-impl"> |
|
398 |
<xsl:param name="node"/> |
|
399 |
<xsl:variable name="name" select="concat('Dom', $node/@name)"/> |
|
400 |
||
401 |
<xsl:text>void </xsl:text> |
|
402 |
<xsl:value-of select="$name"/> |
|
403 |
<xsl:text>::read(QXmlStreamReader &reader)&endl;</xsl:text> |
|
404 |
||
405 |
<xsl:text>{&endl;</xsl:text> |
|
406 |
||
407 |
<xsl:call-template name="read-impl-load-attributes"> |
|
408 |
<xsl:with-param name="node" select="$node"/> |
|
409 |
</xsl:call-template> |
|
410 |
||
411 |
<xsl:text>&endl;</xsl:text> |
|
412 |
||
413 |
<xsl:text> for (bool finished = false; !finished && !reader.hasError();) {&endl;</xsl:text> |
|
414 |
<xsl:text> switch (reader.readNext()) {&endl;</xsl:text> |
|
415 |
<xsl:text> case QXmlStreamReader::StartElement : {&endl;</xsl:text> |
|
416 |
<xsl:text> const QString tag = reader.name().toString().toLower();&endl;</xsl:text> |
|
417 |
||
418 |
<xsl:for-each select="$node//xs:sequence | $node//xs:choice | $node//xs:all"> |
|
419 |
<xsl:call-template name="read-impl-load-child-element"> |
|
420 |
<xsl:with-param name="node" select="."/> |
|
421 |
</xsl:call-template> |
|
422 |
</xsl:for-each> |
|
423 |
||
424 |
<xsl:text> reader.raiseError(QLatin1String("Unexpected element ") + tag);&endl;</xsl:text> |
|
425 |
<xsl:text> }&endl;</xsl:text> |
|
426 |
<xsl:text> break;&endl;</xsl:text> |
|
427 |
<xsl:text> case QXmlStreamReader::EndElement :&endl;</xsl:text> |
|
428 |
<xsl:text> finished = true;&endl;</xsl:text> |
|
429 |
<xsl:text> break;&endl;</xsl:text> |
|
430 |
<xsl:text> case QXmlStreamReader::Characters :&endl;</xsl:text> |
|
431 |
<xsl:text> if (!reader.isWhitespace())&endl;</xsl:text> |
|
432 |
<xsl:text> m_text.append(reader.text().toString());&endl;</xsl:text> |
|
433 |
<xsl:text> break;&endl;</xsl:text> |
|
434 |
<xsl:text> default :&endl;</xsl:text> |
|
435 |
<xsl:text> break;&endl;</xsl:text> |
|
436 |
||
437 |
<xsl:text> }&endl;</xsl:text> |
|
438 |
<xsl:text> }&endl;</xsl:text> |
|
439 |
<xsl:text>}&endl;&endl;</xsl:text> |
|
440 |
</xsl:template> |
|
441 |
||
442 |
<!-- Implementation: read(QDomElement) --> |
|
443 |
||
444 |
<xsl:template name="read-impl-qdom-load-attributes"> |
|
445 |
<xsl:param name="node"/> |
|
446 |
||
447 |
<xsl:if test="$node/xs:attribute"> |
|
448 |
<xsl:text>&endl;</xsl:text> |
|
449 |
||
450 |
<xsl:for-each select="$node/xs:attribute"> |
|
451 |
<xsl:variable name="camel-case-name"> |
|
452 |
<xsl:call-template name="camel-case"> |
|
453 |
<xsl:with-param name="text" select="@name"/> |
|
454 |
</xsl:call-template> |
|
455 |
</xsl:variable> |
|
456 |
<xsl:variable name="cap-name"> |
|
457 |
<xsl:call-template name="cap-first-char"> |
|
458 |
<xsl:with-param name="text" select="$camel-case-name"/> |
|
459 |
</xsl:call-template> |
|
460 |
</xsl:variable> |
|
461 |
<xsl:variable name="qstring-func"> |
|
462 |
<xsl:call-template name="xs-type-from-qstring-func"> |
|
463 |
<xsl:with-param name="xs-type" select="@type"/> |
|
464 |
<xsl:with-param name="val"> |
|
465 |
<xsl:text>node.attribute(</xsl:text> |
|
466 |
<xsl:call-template name="string-constant"> |
|
467 |
<xsl:with-param name="literal" select="@name"/> |
|
468 |
</xsl:call-template> |
|
469 |
<xsl:text>)</xsl:text> |
|
470 |
</xsl:with-param> |
|
471 |
</xsl:call-template> |
|
472 |
</xsl:variable> |
|
473 |
||
474 |
<xsl:text> if (node.hasAttribute(</xsl:text> |
|
475 |
<xsl:call-template name="string-constant"> |
|
476 |
<xsl:with-param name="literal" select="@name"/> |
|
477 |
</xsl:call-template> |
|
478 |
<xsl:text>))&endl;</xsl:text> |
|
479 |
<xsl:text> setAttribute</xsl:text> |
|
480 |
<xsl:value-of select="$cap-name"/> |
|
481 |
<xsl:text>(</xsl:text> |
|
482 |
<xsl:value-of select="$qstring-func"/> |
|
483 |
<xsl:text>);&endl;</xsl:text> |
|
484 |
</xsl:for-each> |
|
485 |
</xsl:if> |
|
486 |
</xsl:template> |
|
487 |
||
488 |
<xsl:template name="read-impl-qdom-load-child-element"> |
|
489 |
<xsl:param name="node"/> |
|
490 |
||
491 |
<xsl:for-each select="$node/xs:element"> |
|
492 |
<xsl:variable name="camel-case-name"> |
|
493 |
<xsl:call-template name="camel-case"> |
|
494 |
<xsl:with-param name="text" select="@name"/> |
|
495 |
</xsl:call-template> |
|
496 |
</xsl:variable> |
|
497 |
<xsl:variable name="cap-name"> |
|
498 |
<xsl:call-template name="cap-first-char"> |
|
499 |
<xsl:with-param name="text" select="$camel-case-name"/> |
|
500 |
</xsl:call-template> |
|
501 |
</xsl:variable> |
|
502 |
<xsl:variable name="xs-type-cat"> |
|
503 |
<xsl:call-template name="xs-type-category"> |
|
504 |
<xsl:with-param name="xs-type" select="@type"/> |
|
505 |
</xsl:call-template> |
|
506 |
</xsl:variable> |
|
507 |
<xsl:variable name="lower-name"> |
|
508 |
<xsl:call-template name="lower-text"> |
|
509 |
<xsl:with-param name="text" select="@name"/> |
|
510 |
</xsl:call-template> |
|
511 |
</xsl:variable> |
|
512 |
<xsl:variable name="array" select="@maxOccurs = 'unbounded'"/> |
|
513 |
||
514 |
<xsl:text> if (tag == </xsl:text> |
|
515 |
<xsl:call-template name="string-constant"> |
|
516 |
<xsl:with-param name="literal" select="$lower-name"/> |
|
517 |
</xsl:call-template> |
|
518 |
<xsl:text>) {&endl;</xsl:text> |
|
519 |
||
520 |
<xsl:choose> |
|
521 |
<xsl:when test="not($array) and $xs-type-cat = 'value'"> |
|
522 |
<xsl:variable name="qstring-func"> |
|
523 |
<xsl:call-template name="xs-type-from-qstring-func"> |
|
524 |
<xsl:with-param name="xs-type" select="@type"/> |
|
525 |
<xsl:with-param name="val" select="'e.text()'"/> |
|
526 |
</xsl:call-template> |
|
527 |
</xsl:variable> |
|
528 |
||
529 |
<xsl:text> setElement</xsl:text> |
|
530 |
<xsl:value-of select="$cap-name"/> |
|
531 |
<xsl:text>(</xsl:text> |
|
532 |
<xsl:value-of select="$qstring-func"/> |
|
533 |
<xsl:text>);&endl;</xsl:text> |
|
534 |
</xsl:when> |
|
535 |
<xsl:when test="@maxOccurs='unbounded' and $xs-type-cat = 'value'"> |
|
536 |
<xsl:variable name="qstring-func"> |
|
537 |
<xsl:call-template name="xs-type-from-qstring-func"> |
|
538 |
<xsl:with-param name="xs-type" select="@type"/> |
|
539 |
<xsl:with-param name="val" select="'e.text()'"/> |
|
540 |
</xsl:call-template> |
|
541 |
</xsl:variable> |
|
542 |
||
543 |
<xsl:text> m_</xsl:text> |
|
544 |
<xsl:value-of select="$camel-case-name"/> |
|
545 |
<xsl:text>.append(</xsl:text> |
|
546 |
<xsl:value-of select="$qstring-func"/> |
|
547 |
<xsl:text>);&endl;</xsl:text> |
|
548 |
</xsl:when> |
|
549 |
<xsl:when test="not(@maxOccurs='unbounded') and $xs-type-cat = 'pointer'"> |
|
550 |
<xsl:text> Dom</xsl:text> |
|
551 |
<xsl:value-of select="@type"/> |
|
552 |
<xsl:text> *v = new Dom</xsl:text> |
|
553 |
<xsl:value-of select="@type"/> |
|
554 |
<xsl:text>();&endl;</xsl:text> |
|
555 |
<xsl:text> v->read(e);&endl;</xsl:text> |
|
556 |
<xsl:text> setElement</xsl:text> |
|
557 |
<xsl:value-of select="$cap-name"/> |
|
558 |
<xsl:text>(v);&endl;</xsl:text> |
|
559 |
</xsl:when> |
|
560 |
<xsl:when test="@maxOccurs='unbounded' and $xs-type-cat = 'pointer'"> |
|
561 |
<xsl:text> Dom</xsl:text> |
|
562 |
<xsl:value-of select="@type"/> |
|
563 |
<xsl:text> *v = new Dom</xsl:text> |
|
564 |
<xsl:value-of select="@type"/> |
|
565 |
<xsl:text>();&endl;</xsl:text> |
|
566 |
<xsl:text> v->read(e);&endl;</xsl:text> |
|
567 |
<xsl:text> m_</xsl:text> |
|
568 |
<xsl:value-of select="$camel-case-name"/> |
|
569 |
<xsl:text>.append(v);&endl;</xsl:text> |
|
570 |
</xsl:when> |
|
571 |
</xsl:choose> |
|
572 |
<xsl:text> continue;&endl;</xsl:text> |
|
573 |
<xsl:text> }&endl;</xsl:text> |
|
574 |
</xsl:for-each> |
|
575 |
</xsl:template> |
|
576 |
||
577 |
<xsl:template name="read-impl-qdom"> |
|
578 |
<xsl:param name="node"/> |
|
579 |
<xsl:variable name="name" select="concat('Dom', $node/@name)"/> |
|
580 |
||
581 |
<xsl:text>#ifdef QUILOADER_QDOM_READ&endl;</xsl:text> |
|
582 |
||
583 |
<xsl:text>void </xsl:text> |
|
584 |
<xsl:value-of select="$name"/> |
|
585 |
<xsl:text>::read(const QDomElement &node)&endl;</xsl:text> |
|
586 |
||
587 |
<xsl:text>{</xsl:text> |
|
588 |
||
589 |
<xsl:call-template name="read-impl-qdom-load-attributes"> |
|
590 |
<xsl:with-param name="node" select="$node"/> |
|
591 |
</xsl:call-template> |
|
592 |
||
593 |
<xsl:text>&endl;</xsl:text> |
|
594 |
||
595 |
<xsl:text> for (QDomNode n = node.firstChild(); !n.isNull(); n = n.nextSibling()) {&endl;</xsl:text> |
|
596 |
<xsl:text> if (!n.isElement())&endl;</xsl:text> |
|
597 |
<xsl:text> continue;&endl;</xsl:text> |
|
598 |
<xsl:text> QDomElement e = n.toElement();&endl;</xsl:text> |
|
599 |
<xsl:text> QString tag = e.tagName().toLower();&endl;</xsl:text> |
|
600 |
||
601 |
<xsl:for-each select="$node//xs:sequence | $node//xs:choice | $node//xs:all"> |
|
602 |
<xsl:call-template name="read-impl-qdom-load-child-element"> |
|
603 |
<xsl:with-param name="node" select="."/> |
|
604 |
</xsl:call-template> |
|
605 |
</xsl:for-each> |
|
606 |
||
607 |
<xsl:text> }&endl;</xsl:text> |
|
608 |
||
609 |
<xsl:choose> |
|
610 |
<xsl:when test="$node[@mixed='true']"> |
|
611 |
<xsl:text> m_text = QLatin1String("");&endl;</xsl:text> |
|
612 |
</xsl:when> |
|
613 |
<xsl:otherwise> |
|
614 |
<xsl:text> m_text.clear();&endl;</xsl:text> |
|
615 |
</xsl:otherwise> |
|
616 |
</xsl:choose> |
|
617 |
||
618 |
<xsl:text> for (QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling()) {&endl;</xsl:text> |
|
619 |
<xsl:text> if (child.isText())&endl;</xsl:text> |
|
620 |
<xsl:text> m_text.append(child.nodeValue());&endl;</xsl:text> |
|
621 |
<xsl:text> }&endl;</xsl:text> |
|
622 |
||
623 |
<xsl:text>}&endl;</xsl:text> |
|
624 |
<xsl:text>#endif&endl;</xsl:text> |
|
625 |
<xsl:text>&endl;</xsl:text> |
|
626 |
</xsl:template> |
|
627 |
<!-- Implementation: write() --> |
|
628 |
||
629 |
<xsl:template name="write-impl-save-attributes"> |
|
630 |
<xsl:param name="node"/> |
|
631 |
||
632 |
<xsl:for-each select="$node/xs:attribute"> |
|
633 |
<xsl:variable name="camel-case-name"> |
|
634 |
<xsl:call-template name="camel-case"> |
|
635 |
<xsl:with-param name="text" select="@name"/> |
|
636 |
</xsl:call-template> |
|
637 |
</xsl:variable> |
|
638 |
<xsl:variable name="cap-name"> |
|
639 |
<xsl:call-template name="cap-first-char"> |
|
640 |
<xsl:with-param name="text" select="$camel-case-name"/> |
|
641 |
</xsl:call-template> |
|
642 |
</xsl:variable> |
|
643 |
<xsl:variable name="lower-name"> |
|
644 |
<xsl:call-template name="lower-text"> |
|
645 |
<xsl:with-param name="text" select="@name"/> |
|
646 |
</xsl:call-template> |
|
647 |
</xsl:variable> |
|
648 |
||
649 |
<xsl:text> if (hasAttribute</xsl:text> |
|
650 |
<xsl:value-of select="$cap-name"/> |
|
651 |
<xsl:text>())&endl;</xsl:text> |
|
652 |
<xsl:text> writer.writeAttribute(</xsl:text> |
|
653 |
<xsl:call-template name="string-constant"> |
|
654 |
<xsl:with-param name="literal" select="$lower-name"/> |
|
655 |
</xsl:call-template> |
|
656 |
||
657 |
<xsl:text>, </xsl:text> |
|
658 |
||
659 |
<xsl:call-template name="xs-type-to-qstring-func"> |
|
660 |
<xsl:with-param name="xs-type" select="@type"/> |
|
661 |
<xsl:with-param name="val" select="concat('attribute', $cap-name, '()')"/> |
|
662 |
</xsl:call-template> |
|
663 |
||
664 |
<xsl:text>);&endl;&endl;</xsl:text> |
|
665 |
</xsl:for-each> |
|
666 |
</xsl:template> |
|
667 |
||
668 |
<xsl:template name="write-impl-save-choice-child-element"> |
|
669 |
<xsl:param name="node"/> |
|
670 |
<xsl:variable name="have-kind" select="name($node) = 'xs:choice'"/> |
|
671 |
||
672 |
<xsl:text> switch (kind()) {&endl;</xsl:text> |
|
673 |
||
674 |
<xsl:for-each select="$node/xs:element"> |
|
675 |
<xsl:variable name="camel-case-name"> |
|
676 |
<xsl:call-template name="camel-case"> |
|
677 |
<xsl:with-param name="text" select="@name"/> |
|
678 |
</xsl:call-template> |
|
679 |
</xsl:variable> |
|
680 |
<xsl:variable name="cap-name"> |
|
681 |
<xsl:call-template name="cap-first-char"> |
|
682 |
<xsl:with-param name="text" select="$camel-case-name"/> |
|
683 |
</xsl:call-template> |
|
684 |
</xsl:variable> |
|
685 |
<xsl:variable name="lower-name"> |
|
686 |
<xsl:call-template name="lower-text"> |
|
687 |
<xsl:with-param name="text" select="@name"/> |
|
688 |
</xsl:call-template> |
|
689 |
</xsl:variable> |
|
690 |
<xsl:variable name="xs-type-cat"> |
|
691 |
<xsl:call-template name="xs-type-category"> |
|
692 |
<xsl:with-param name="xs-type" select="@type"/> |
|
693 |
</xsl:call-template> |
|
694 |
</xsl:variable> |
|
695 |
||
696 |
<xsl:text> case </xsl:text> |
|
697 |
<xsl:value-of select="$cap-name"/> |
|
698 |
<xsl:text>: {&endl;</xsl:text> |
|
699 |
<xsl:choose> |
|
700 |
<xsl:when test="$xs-type-cat = 'value'"> |
|
701 |
<xsl:variable name="qstring-func"> |
|
702 |
<xsl:call-template name="xs-type-to-qstring-func"> |
|
703 |
<xsl:with-param name="xs-type" select="@type"/> |
|
704 |
<xsl:with-param name="val" select="concat('element', $cap-name, '()')"/> |
|
705 |
</xsl:call-template> |
|
706 |
</xsl:variable> |
|
707 |
||
708 |
<xsl:text> writer.writeTextElement(</xsl:text> |
|
709 |
<xsl:call-template name="string-constant"> |
|
710 |
<xsl:with-param name="literal" select="$camel-case-name"/> |
|
711 |
</xsl:call-template> |
|
712 |
<xsl:text>, </xsl:text> |
|
713 |
<xsl:value-of select="$qstring-func"/> |
|
714 |
<xsl:text>);&endl;</xsl:text> |
|
715 |
</xsl:when> |
|
716 |
<xsl:when test="$xs-type-cat = 'pointer'"> |
|
717 |
<xsl:variable name="cpp-return-type"> |
|
718 |
<xsl:call-template name="xs-type-to-cpp-return-type"> |
|
719 |
<xsl:with-param name="xs-type" select="@type"/> |
|
720 |
</xsl:call-template> |
|
721 |
</xsl:variable> |
|
722 |
||
723 |
<xsl:text> </xsl:text> |
|
724 |
<xsl:value-of select="$cpp-return-type"/> |
|
725 |
<xsl:text> v = element</xsl:text> |
|
726 |
<xsl:value-of select="$cap-name"/> |
|
727 |
<xsl:text>();&endl;</xsl:text> |
|
728 |
<xsl:text> if (v != 0) {&endl;</xsl:text> |
|
729 |
<xsl:text> v->write(writer, </xsl:text> |
|
730 |
<xsl:call-template name="string-constant"> |
|
731 |
<xsl:with-param name="literal" select="$lower-name"/> |
|
732 |
</xsl:call-template> |
|
733 |
<xsl:text>);&endl;</xsl:text> |
|
734 |
<xsl:text> }&endl;</xsl:text> |
|
735 |
</xsl:when> |
|
736 |
</xsl:choose> |
|
737 |
<xsl:text> break;&endl;</xsl:text> |
|
738 |
<xsl:text> }&endl;</xsl:text> |
|
739 |
</xsl:for-each> |
|
740 |
||
741 |
<xsl:text> default:&endl;</xsl:text> |
|
742 |
<xsl:text> break;&endl;</xsl:text> |
|
743 |
<xsl:text> }&endl;</xsl:text> |
|
744 |
</xsl:template> |
|
745 |
||
746 |
<xsl:template name="write-impl-save-sequence-child-element"> |
|
747 |
<xsl:param name="node"/> |
|
748 |
<xsl:variable name="name" select="concat('Dom', $node/@name)"/> |
|
749 |
<xsl:for-each select="$node/xs:element"> |
|
750 |
<xsl:variable name="camel-case-name"> |
|
751 |
<xsl:call-template name="camel-case"> |
|
752 |
<xsl:with-param name="text" select="@name"/> |
|
753 |
</xsl:call-template> |
|
754 |
</xsl:variable> |
|
755 |
<xsl:variable name="cap-name"> |
|
756 |
<xsl:call-template name="cap-first-char"> |
|
757 |
<xsl:with-param name="text" select="$camel-case-name"/> |
|
758 |
</xsl:call-template> |
|
759 |
</xsl:variable> |
|
760 |
<xsl:variable name="lower-name"> |
|
761 |
<xsl:call-template name="lower-text"> |
|
762 |
<xsl:with-param name="text" select="@name"/> |
|
763 |
</xsl:call-template> |
|
764 |
</xsl:variable> |
|
765 |
<xsl:variable name="xs-type-cat"> |
|
766 |
<xsl:call-template name="xs-type-category"> |
|
767 |
<xsl:with-param name="xs-type" select="@type"/> |
|
768 |
</xsl:call-template> |
|
769 |
</xsl:variable> |
|
770 |
<xsl:variable name="cpp-return-type"> |
|
771 |
<xsl:call-template name="xs-type-to-cpp-return-type"> |
|
772 |
<xsl:with-param name="xs-type" select="@type"/> |
|
773 |
</xsl:call-template> |
|
774 |
</xsl:variable> |
|
775 |
||
776 |
<xsl:choose> |
|
777 |
<xsl:when test="@maxOccurs='unbounded'"> |
|
778 |
<xsl:text> for (int i = 0; i < m_</xsl:text> |
|
779 |
<xsl:value-of select="$camel-case-name"/> |
|
780 |
<xsl:text>.size(); ++i) {&endl;</xsl:text> |
|
781 |
<xsl:text> </xsl:text> |
|
782 |
<xsl:value-of select="$cpp-return-type"/> |
|
783 |
<xsl:text> v = m_</xsl:text> |
|
784 |
<xsl:value-of select="$camel-case-name"/> |
|
785 |
<xsl:text>[i];&endl;</xsl:text> |
|
786 |
<xsl:choose> |
|
787 |
<xsl:when test="$xs-type-cat = 'pointer'"> |
|
788 |
<xsl:text> v->write(writer, </xsl:text> |
|
789 |
<xsl:call-template name="string-constant"> |
|
790 |
<xsl:with-param name="literal" select="$lower-name"/> |
|
791 |
</xsl:call-template> |
|
792 |
<xsl:text>);&endl;</xsl:text> |
|
793 |
</xsl:when> |
|
794 |
<xsl:otherwise> |
|
795 |
<xsl:variable name="qstring-func"> |
|
796 |
<xsl:call-template name="xs-type-to-qstring-func"> |
|
797 |
<xsl:with-param name="xs-type" select="@type"/> |
|
798 |
<xsl:with-param name="val" select="'v'"/> |
|
799 |
</xsl:call-template> |
|
800 |
</xsl:variable> |
|
801 |
||
802 |
<xsl:text> writer.writeTextElement(</xsl:text> |
|
803 |
<xsl:call-template name="string-constant"> |
|
804 |
<xsl:with-param name="literal" select="$lower-name"/> |
|
805 |
</xsl:call-template> |
|
806 |
<xsl:text>, </xsl:text> |
|
807 |
<xsl:value-of select="$qstring-func"/> |
|
808 |
<xsl:text>);&endl;</xsl:text> |
|
809 |
</xsl:otherwise> |
|
810 |
</xsl:choose> |
|
811 |
<xsl:text> }&endl;</xsl:text> |
|
812 |
</xsl:when> |
|
813 |
<xsl:otherwise> |
|
814 |
<xsl:text> if (m_children & </xsl:text> |
|
815 |
<xsl:value-of select="$cap-name"/> |
|
816 |
<xsl:text>) {&endl;</xsl:text> |
|
817 |
<xsl:choose> |
|
818 |
<xsl:when test="$xs-type-cat = 'pointer'"> |
|
819 |
<xsl:text> m_</xsl:text> |
|
820 |
<xsl:value-of select="$camel-case-name"/> |
|
821 |
<xsl:text>->write(writer, </xsl:text> |
|
822 |
<xsl:call-template name="string-constant"> |
|
823 |
<xsl:with-param name="literal" select="$lower-name"/> |
|
824 |
</xsl:call-template> |
|
825 |
<xsl:text>);&endl;</xsl:text> |
|
826 |
</xsl:when> |
|
827 |
<xsl:otherwise> |
|
828 |
<xsl:variable name="qstring-func"> |
|
829 |
<xsl:call-template name="xs-type-to-qstring-func"> |
|
830 |
<xsl:with-param name="xs-type" select="@type"/> |
|
831 |
<xsl:with-param name="val" select="concat('m_', $camel-case-name)"/> |
|
832 |
</xsl:call-template> |
|
833 |
</xsl:variable> |
|
834 |
<xsl:text> writer.writeTextElement(</xsl:text> |
|
835 |
<xsl:call-template name="string-constant"> |
|
836 |
<xsl:with-param name="literal" select="$lower-name"/> |
|
837 |
</xsl:call-template> |
|
838 |
<xsl:text>, </xsl:text> |
|
839 |
<xsl:value-of select="$qstring-func"/> |
|
840 |
<xsl:text>);&endl;</xsl:text> |
|
841 |
</xsl:otherwise> |
|
842 |
</xsl:choose> |
|
843 |
<xsl:text> }&endl;&endl;</xsl:text> |
|
844 |
</xsl:otherwise> |
|
845 |
</xsl:choose> |
|
846 |
</xsl:for-each> |
|
847 |
</xsl:template> |
|
848 |
||
849 |
<xsl:template name="write-impl"> |
|
850 |
<xsl:param name="node"/> |
|
851 |
<xsl:variable name="name" select="concat('Dom', $node/@name)"/> |
|
852 |
<xsl:variable name="lower-name"> |
|
853 |
<xsl:call-template name="lower-text"> |
|
854 |
<xsl:with-param name="text" select="@name"/> |
|
855 |
</xsl:call-template> |
|
856 |
</xsl:variable> |
|
857 |
||
858 |
<xsl:text>void </xsl:text> |
|
859 |
<xsl:value-of select="$name"/> |
|
860 |
<xsl:text>::write(QXmlStreamWriter &writer, const QString &tagName) const&endl;</xsl:text> |
|
861 |
<xsl:text>{&endl;</xsl:text> |
|
862 |
||
863 |
<xsl:text> writer.writeStartElement(tagName.isEmpty() ? QString::fromUtf8("</xsl:text> |
|
864 |
<xsl:value-of select="$lower-name"/> |
|
865 |
<xsl:text>") : tagName.toLower());&endl;&endl;</xsl:text> |
|
866 |
||
867 |
<xsl:call-template name="write-impl-save-attributes"> |
|
868 |
<xsl:with-param name="node" select="$node"/> |
|
869 |
</xsl:call-template> |
|
870 |
||
871 |
<xsl:for-each select="$node//xs:choice"> |
|
872 |
<xsl:call-template name="write-impl-save-choice-child-element"> |
|
873 |
<xsl:with-param name="node" select="."/> |
|
874 |
</xsl:call-template> |
|
875 |
</xsl:for-each> |
|
876 |
||
877 |
<xsl:for-each select="$node//xs:sequence | $node//xs:all"> |
|
878 |
<xsl:call-template name="write-impl-save-sequence-child-element"> |
|
879 |
<xsl:with-param name="node" select="."/> |
|
880 |
</xsl:call-template> |
|
881 |
</xsl:for-each> |
|
882 |
||
883 |
<xsl:text> if (!m_text.isEmpty())&endl;</xsl:text> |
|
884 |
<xsl:text> writer.writeCharacters(m_text);&endl;&endl;</xsl:text> |
|
885 |
||
886 |
<xsl:text> writer.writeEndElement();&endl;</xsl:text> |
|
887 |
<xsl:text>}&endl;&endl;</xsl:text> |
|
888 |
</xsl:template> |
|
889 |
||
890 |
<!-- Implementation: child element setters --> |
|
891 |
||
892 |
<xsl:template name="child-setter-impl-helper"> |
|
893 |
<xsl:param name="node"/> |
|
894 |
<xsl:param name="name"/> |
|
895 |
<xsl:variable name="make-kind-enum" select="name($node)='xs:choice'"/> |
|
896 |
<xsl:variable name="isChoice" select="name($node)='xs:choice'"/> |
|
897 |
||
898 |
<xsl:for-each select="$node/xs:element"> |
|
899 |
<xsl:variable name="array" select="@maxOccurs = 'unbounded'"/> |
|
900 |
<xsl:variable name="camel-case-name"> |
|
901 |
<xsl:call-template name="camel-case"> |
|
902 |
<xsl:with-param name="text" select="@name"/> |
|
903 |
</xsl:call-template> |
|
904 |
</xsl:variable> |
|
905 |
<xsl:variable name="cap-name"> |
|
906 |
<xsl:call-template name="cap-first-char"> |
|
907 |
<xsl:with-param name="text" select="$camel-case-name"/> |
|
908 |
</xsl:call-template> |
|
909 |
</xsl:variable> |
|
910 |
<xsl:variable name="return-cpp-type"> |
|
911 |
<xsl:call-template name="xs-type-to-cpp-return-type"> |
|
912 |
<xsl:with-param name="xs-type" select="@type"/> |
|
913 |
<xsl:with-param name="array" select="$array"/> |
|
914 |
</xsl:call-template> |
|
915 |
</xsl:variable> |
|
916 |
<xsl:variable name="argument-cpp-type"> |
|
917 |
<xsl:call-template name="xs-type-to-cpp-argument-type"> |
|
918 |
<xsl:with-param name="xs-type" select="@type"/> |
|
919 |
<xsl:with-param name="array" select="$array"/> |
|
920 |
</xsl:call-template> |
|
921 |
</xsl:variable> |
|
922 |
<xsl:variable name="xs-type-cat"> |
|
923 |
<xsl:call-template name="xs-type-category"> |
|
924 |
<xsl:with-param name="xs-type" select="@type"/> |
|
925 |
<xsl:with-param name="array" select="$array"/> |
|
926 |
</xsl:call-template> |
|
927 |
</xsl:variable> |
|
928 |
||
929 |
<xsl:if test="$xs-type-cat = 'pointer'"> |
|
930 |
<xsl:value-of select="$return-cpp-type"/> |
|
931 |
<xsl:text> </xsl:text> |
|
932 |
<xsl:value-of select="$name"/> |
|
933 |
<xsl:text>::takeElement</xsl:text> |
|
934 |
<xsl:value-of select="$cap-name"/> |
|
935 |
<xsl:text>() &endl;{&endl;</xsl:text> |
|
936 |
<xsl:text> </xsl:text> |
|
937 |
<xsl:value-of select="$return-cpp-type"/> |
|
938 |
<xsl:text> a = m_</xsl:text> |
|
939 |
<xsl:value-of select="$camel-case-name"/> |
|
940 |
<xsl:text>;&endl;</xsl:text> |
|
941 |
<xsl:text> m_</xsl:text> |
|
942 |
<xsl:value-of select="$camel-case-name"/> |
|
943 |
<xsl:text> = 0;&endl;</xsl:text> |
|
944 |
<xsl:if test="not($isChoice)"> |
|
945 |
<xsl:text> m_children ^= </xsl:text> |
|
946 |
<xsl:value-of select="$cap-name"/> |
|
947 |
<xsl:text>;&endl;</xsl:text> |
|
948 |
</xsl:if> |
|
949 |
<xsl:text> return a;&endl;</xsl:text> |
|
950 |
<xsl:text>}&endl;&endl;</xsl:text> |
|
951 |
</xsl:if> |
|
952 |
||
953 |
<xsl:text>void </xsl:text> |
|
954 |
<xsl:value-of select="$name"/> |
|
955 |
<xsl:text>::setElement</xsl:text> |
|
956 |
<xsl:value-of select="$cap-name"/> |
|
957 |
<xsl:text>(</xsl:text> |
|
958 |
<xsl:value-of select="$argument-cpp-type"/> |
|
959 |
<xsl:text> a)&endl;</xsl:text> |
|
960 |
<xsl:text>{&endl;</xsl:text> |
|
961 |
<xsl:choose> |
|
962 |
<xsl:when test="$make-kind-enum"> |
|
963 |
<xsl:text> clear(false);&endl;</xsl:text> |
|
964 |
<xsl:text> m_kind = </xsl:text> |
|
965 |
<xsl:value-of select="$cap-name"/> |
|
966 |
<xsl:text>;&endl;</xsl:text> |
|
967 |
</xsl:when> |
|
968 |
<xsl:when test="$xs-type-cat = 'pointer'"> |
|
969 |
<xsl:text> delete </xsl:text> |
|
970 |
<xsl:text>m_</xsl:text> |
|
971 |
<xsl:value-of select="$camel-case-name"/> |
|
972 |
<xsl:text>;&endl;</xsl:text> |
|
973 |
</xsl:when> |
|
974 |
</xsl:choose> |
|
975 |
<xsl:if test="not($isChoice)"> |
|
976 |
<xsl:text> m_children |= </xsl:text> |
|
977 |
<xsl:value-of select="$cap-name"/> |
|
978 |
<xsl:text>;&endl;</xsl:text> |
|
979 |
</xsl:if> |
|
980 |
<xsl:text> m_</xsl:text> |
|
981 |
<xsl:value-of select="$camel-case-name"/> |
|
982 |
<xsl:text> = a;&endl;</xsl:text> |
|
983 |
<xsl:text>}&endl;&endl;</xsl:text> |
|
984 |
</xsl:for-each> |
|
985 |
</xsl:template> |
|
986 |
||
987 |
<xsl:template name="child-setter-impl"> |
|
988 |
<xsl:param name="node"/> |
|
989 |
<xsl:variable name="name" select="concat('Dom', $node/@name)"/> |
|
990 |
||
991 |
<xsl:for-each select="$node/xs:sequence | $node/xs:choice | $node/xs:all"> |
|
992 |
<xsl:call-template name="child-setter-impl-helper"> |
|
993 |
<xsl:with-param name="node" select="."/> |
|
994 |
<xsl:with-param name="name" select="$name"/> |
|
995 |
</xsl:call-template> |
|
996 |
</xsl:for-each> |
|
997 |
</xsl:template> |
|
998 |
||
999 |
<xsl:template name="child-clear-impl"> |
|
1000 |
<xsl:param name="node"/> |
|
1001 |
||
1002 |
<xsl:variable name="name" select="concat('Dom', @name)"/> |
|
1003 |
<xsl:for-each select="$node/xs:sequence | $node/xs:choice | $node/xs:all"> |
|
1004 |
<xsl:variable name="isChoice" select="name()='xs:choice'"/> |
|
1005 |
<xsl:variable name="make-child-enum" select="boolean(xs:sequence) and not(@maxOccurs='unbounded')"/> |
|
1006 |
||
1007 |
<xsl:for-each select="xs:element"> |
|
1008 |
<xsl:if test="not($isChoice) and not(@maxOccurs='unbounded')"> |
|
1009 |
<xsl:variable name="camel-case-name"> |
|
1010 |
<xsl:call-template name="camel-case"> |
|
1011 |
<xsl:with-param name="text" select="@name"/> |
|
1012 |
</xsl:call-template> |
|
1013 |
</xsl:variable> |
|
1014 |
<xsl:variable name="cap-name"> |
|
1015 |
<xsl:call-template name="cap-first-char"> |
|
1016 |
<xsl:with-param name="text" select="$camel-case-name"/> |
|
1017 |
</xsl:call-template> |
|
1018 |
</xsl:variable> |
|
1019 |
<xsl:variable name="xs-type-cat"> |
|
1020 |
<xsl:call-template name="xs-type-category"> |
|
1021 |
<xsl:with-param name="xs-type" select="@type"/> |
|
1022 |
<xsl:with-param name="array" select="@maxOccurs='unbounded'"/> |
|
1023 |
</xsl:call-template> |
|
1024 |
</xsl:variable> |
|
1025 |
||
1026 |
<xsl:text>void </xsl:text> |
|
1027 |
<xsl:value-of select="$name"/> |
|
1028 |
<xsl:text>::clearElement</xsl:text> |
|
1029 |
<xsl:value-of select="$cap-name"/> |
|
1030 |
<xsl:text>()&endl;</xsl:text> |
|
1031 |
<xsl:text>{&endl;</xsl:text> |
|
1032 |
<xsl:if test="$xs-type-cat = 'pointer'"> |
|
1033 |
<xsl:text> delete m_</xsl:text> |
|
1034 |
<xsl:value-of select="$camel-case-name"/> |
|
1035 |
<xsl:text>;&endl;</xsl:text> |
|
1036 |
<xsl:text> m_</xsl:text> |
|
1037 |
<xsl:value-of select="$camel-case-name"/> |
|
1038 |
<xsl:text> = 0;&endl;</xsl:text> |
|
1039 |
</xsl:if> |
|
1040 |
<xsl:text> m_children &= ~</xsl:text> |
|
1041 |
<xsl:value-of select="$cap-name"/> |
|
1042 |
<xsl:text>;&endl;</xsl:text> |
|
1043 |
<xsl:text>}&endl;&endl;</xsl:text> |
|
1044 |
</xsl:if> |
|
1045 |
</xsl:for-each> |
|
1046 |
</xsl:for-each> |
|
1047 |
</xsl:template> |
|
1048 |
||
1049 |
||
1050 |
<!-- Implementation --> |
|
1051 |
||
1052 |
<xsl:template name="class-implementation"> |
|
1053 |
<xsl:param name="node"/> |
|
1054 |
||
1055 |
<xsl:call-template name="clear-impl"> |
|
1056 |
<xsl:with-param name="node" select="$node"/> |
|
1057 |
</xsl:call-template> |
|
1058 |
||
1059 |
<xsl:call-template name="ctor-impl"> |
|
1060 |
<xsl:with-param name="node" select="$node"/> |
|
1061 |
</xsl:call-template> |
|
1062 |
||
1063 |
<xsl:call-template name="dtor-impl"> |
|
1064 |
<xsl:with-param name="node" select="$node"/> |
|
1065 |
</xsl:call-template> |
|
1066 |
||
1067 |
<xsl:call-template name="read-impl"> |
|
1068 |
<xsl:with-param name="node" select="$node"/> |
|
1069 |
</xsl:call-template> |
|
1070 |
||
1071 |
<xsl:call-template name="read-impl-qdom"> |
|
1072 |
<xsl:with-param name="node" select="$node"/> |
|
1073 |
</xsl:call-template> |
|
1074 |
||
1075 |
<xsl:call-template name="write-impl"> |
|
1076 |
<xsl:with-param name="node" select="$node"/> |
|
1077 |
</xsl:call-template> |
|
1078 |
||
1079 |
<xsl:call-template name="child-setter-impl"> |
|
1080 |
<xsl:with-param name="node" select="$node"/> |
|
1081 |
</xsl:call-template> |
|
1082 |
||
1083 |
<xsl:call-template name="child-clear-impl"> |
|
1084 |
<xsl:with-param name="node" select="$node"/> |
|
1085 |
</xsl:call-template> |
|
1086 |
||
1087 |
</xsl:template> |
|
1088 |
||
1089 |
<!-- Root --> |
|
1090 |
||
1091 |
<xsl:template match="xs:schema"> |
|
1092 |
||
1093 |
<xsl:text>/**************************************************************************** |
|
1094 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1095 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 1096 |
** All rights reserved. |
1097 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
1098 |
** |
|
1099 |
** This file is part of the tools applications of the Qt Toolkit. |
|
1100 |
** |
|
1101 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
1102 |
** No Commercial Usage |
|
1103 |
** This file contains pre-release code and may not be distributed. |
|
1104 |
** You may use this file in accordance with the terms and conditions |
|
1105 |
** contained in the Technology Preview License Agreement accompanying |
|
1106 |
** this package. |
|
1107 |
** |
|
1108 |
** GNU Lesser General Public License Usage |
|
1109 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
1110 |
** General Public License version 2.1 as published by the Free Software |
|
1111 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
1112 |
** packaging of this file. Please review the following information to |
|
1113 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
1114 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
1115 |
** |
|
1116 |
** In addition, as a special exception, Nokia gives you certain additional |
|
1117 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
1118 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
1119 |
** |
|
1120 |
** If you have questions regarding the use of this file, please contact |
|
1121 |
** Nokia at qt-info@nokia.com. |
|
1122 |
** |
|
1123 |
** |
|
1124 |
** |
|
1125 |
** |
|
1126 |
** |
|
1127 |
** |
|
1128 |
** |
|
1129 |
** |
|
1130 |
** $QT_END_LICENSE$ |
|
1131 |
** |
|
1132 |
****************************************************************************/ |
|
1133 |
</xsl:text> |
|
1134 |
<xsl:text>#include "ui4_p.h"&endl;</xsl:text> |
|
1135 |
<xsl:text>&endl;</xsl:text> |
|
1136 |
<xsl:text>#ifdef QUILOADER_QDOM_READ&endl;</xsl:text> |
|
1137 |
<xsl:text>#include <QtXml/QDomElement>&endl;</xsl:text> |
|
1138 |
<xsl:text>#endif&endl;</xsl:text> |
|
1139 |
<xsl:text>&endl;</xsl:text> |
|
1140 |
<xsl:text>QT_BEGIN_NAMESPACE&endl;</xsl:text> |
|
1141 |
||
1142 |
<xsl:text>#ifdef QFORMINTERNAL_NAMESPACE&endl;</xsl:text> |
|
1143 |
<xsl:text>using namespace QFormInternal;&endl;</xsl:text> |
|
1144 |
<xsl:text>#endif&endl;</xsl:text> |
|
1145 |
<xsl:text>&endl;</xsl:text> |
|
1146 |
||
1147 |
<xsl:text>/*******************************************************************************&endl;</xsl:text> |
|
1148 |
<xsl:text>** Implementations&endl;</xsl:text> |
|
1149 |
<xsl:text>*/&endl;&endl;</xsl:text> |
|
1150 |
||
1151 |
<xsl:for-each select="xs:complexType"> |
|
1152 |
<xsl:call-template name="class-implementation"> |
|
1153 |
<xsl:with-param name="node" select="."/> |
|
1154 |
</xsl:call-template> |
|
1155 |
</xsl:for-each> |
|
1156 |
<xsl:text>QT_END_NAMESPACE&endl;</xsl:text> |
|
1157 |
||
1158 |
<xsl:text>&endl;</xsl:text> |
|
1159 |
</xsl:template> |
|
1160 |
||
1161 |
</xsl:stylesheet> |