VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/include/COMWrappers.xsl@ 6909

Last change on this file since 6909 was 6907, checked in by vboxsync, 17 years ago

FE/Qt: COMWrappers: Added typedef XXXVector where XXX is the class name, for convenience.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 66.8 KB
Line 
1<?xml version="1.0"?>
2
3<!--
4/*
5 * A template to generate wrapper classes for [XP]COM interfaces (defined
6 * in XIDL) to use them in the main Qt-based GUI in platform-independent
7 * script-like manner.
8 *
9 * The generated header requires COMDefs.h and must be included from there.
10 */
11
12/*
13 Copyright (C) 2006-2007 innotek GmbH
14
15 This file is part of VirtualBox Open Source Edition (OSE), as
16 available from http://www.virtualbox.org. This file is free software;
17 you can redistribute it and/or modify it under the terms of the GNU
18 General Public License (GPL) as published by the Free Software
19 Foundation, in version 2 as it comes in the "COPYING" file of the
20 VirtualBox OSE distribution. VirtualBox OSE is distributed in the
21 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
22 */
23-->
24
25<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
26<xsl:output method="text"/>
27
28<xsl:strip-space elements="*"/>
29
30
31<!--
32// helper definitions
33/////////////////////////////////////////////////////////////////////////////
34-->
35
36<!--
37 * capitalizes the first letter
38-->
39<xsl:template name="capitalize">
40 <xsl:param name="str" select="."/>
41 <xsl:value-of select="
42 concat(
43 translate(substring($str,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ'),
44 substring($str,2)
45 )
46 "/>
47</xsl:template>
48
49<!--
50 * uncapitalizes the first letter only if the second one is not capital
51 * otherwise leaves the string unchanged
52-->
53<xsl:template name="uncapitalize">
54 <xsl:param name="str" select="."/>
55 <xsl:choose>
56 <xsl:when test="not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ', substring($str,2,1)))">
57 <xsl:value-of select="
58 concat(
59 translate(substring($str,1,1),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),
60 substring($str,2)
61 )
62 "/>
63 </xsl:when>
64 <xsl:otherwise>
65 <xsl:value-of select="string($str)"/>
66 </xsl:otherwise>
67 </xsl:choose>
68</xsl:template>
69
70<!--
71 * translates the string to uppercase
72-->
73<xsl:template name="uppercase">
74 <xsl:param name="str" select="."/>
75 <xsl:value-of select="
76 translate($str,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')
77 "/>
78</xsl:template>
79
80
81<!--
82// templates
83/////////////////////////////////////////////////////////////////////////////
84-->
85
86
87<!--
88 * shut down all implicit templates
89-->
90<xsl:template match="*"/>
91<xsl:template match="*|/" mode="declare"/>
92<xsl:template match="*|/" mode="define"/>
93<xsl:template match="*|/" mode="end"/>
94<xsl:template match="*|/" mode="begin"/>
95
96
97<!--
98 * header
99-->
100<xsl:template match="/idl">
101
102<xsl:text>
103/*
104 * DO NOT EDIT! This is a generated file.
105 *
106 * Qt-based wrapper classes for VirualBox Main API (COM interfaces)
107 * generated from XIDL (XML interface definition).
108 *
109 * Source : src/VBox/Main/idl/VirtualBox.xidl
110 * Generator : src/VBox/Frontends/VirtualBox/include/COMWrappers.xsl
111 *
112 * Note: this header must be included from COMDefs.h, never directly.
113 */
114</xsl:text>
115
116 <!-- all enum declarations as a single class -->
117<xsl:text>
118// all enums
119
120class CEnums
121{
122public:
123
124</xsl:text>
125 <xsl:for-each select="*/enum">
126 <xsl:text> enum </xsl:text>
127 <xsl:value-of select="@name"/>
128 <xsl:text>&#x0A; {&#x0A;</xsl:text>
129 <xsl:for-each select="const">
130 <xsl:text> </xsl:text>
131 <xsl:value-of select="@name"/>
132 <xsl:text> = ::</xsl:text>
133 <xsl:value-of select="parent::node()/@name"/>
134 <xsl:text>_</xsl:text>
135 <xsl:value-of select="@name"/>
136 <xsl:text>,&#x0A;</xsl:text>
137 </xsl:for-each>
138 <xsl:text> </xsl:text>
139 <xsl:value-of select="@name"/>
140 <xsl:text>_COUNT&#x0A;</xsl:text>
141 <xsl:text> };&#x0A;&#x0A;</xsl:text>
142 </xsl:for-each>
143 <xsl:text>};&#x0A;&#x0A;</xsl:text>
144
145 <xsl:apply-templates/>
146
147</xsl:template>
148
149
150<!--
151 * encloses |if| element's contents (unconditionally expanded by
152 * <apply-templates mode="define"/>) with #ifdef / #endif.
153 *
154 * @note this can produce an empty #if/#endif block if |if|'s children
155 * expand to nothing (such as |cpp|). I see no need to handle this situation
156 * specially.
157-->
158<xsl:template match="if" mode="define">
159 <xsl:if test="(@target='xpidl') or (@target='midl')">
160 <xsl:apply-templates select="." mode="begin"/>
161 <xsl:apply-templates mode="define"/>
162 <xsl:apply-templates select="." mode="end"/>
163 <xsl:text>&#x0A;</xsl:text>
164 </xsl:if>
165</xsl:template>
166
167
168<!--
169 * encloses |if| element's contents (unconditionally expanded by
170 * <apply-templates mode="declare"/>) with #ifdef / #endif.
171 *
172 * @note this can produce an empty #if/#endif block if |if|'s children
173 * expand to nothing (such as |cpp|). I see no need to handle this situation
174 * specially.
175-->
176<xsl:template match="if" mode="declare">
177 <xsl:if test="(@target='xpidl') or (@target='midl')">
178 <xsl:apply-templates select="." mode="begin"/>
179 <xsl:apply-templates mode="declare"/>
180 <xsl:apply-templates select="." mode="end"/>
181 <xsl:text>&#x0A;</xsl:text>
182 </xsl:if>
183</xsl:template>
184
185
186<!--
187 * |<if target="...">| element): begin and end.
188-->
189<xsl:template match="if" mode="begin">
190 <xsl:if test="@target='xpidl'">
191 <xsl:text>#if !defined (Q_WS_WIN32)&#x0A;</xsl:text>
192 </xsl:if>
193 <xsl:if test="@target='midl'">
194 <xsl:text>#if defined (Q_WS_WIN32)&#x0A;</xsl:text>
195 </xsl:if>
196</xsl:template>
197<xsl:template match="if" mode="end">
198 <xsl:if test="(@target='xpidl') or (@target='midl')">
199 <xsl:text>#endif&#x0A;</xsl:text>
200 </xsl:if>
201</xsl:template>
202
203
204<!--
205 * cpp_quote
206-->
207<xsl:template match="cpp"/>
208
209
210<!--
211 * #ifdef statement (@if attribute): begin and end
212-->
213<xsl:template match="@if" mode="begin">
214 <xsl:text>#if </xsl:text>
215 <xsl:value-of select="."/>
216 <xsl:text>&#x0A;</xsl:text>
217</xsl:template>
218<xsl:template match="@if" mode="end">
219 <xsl:text>#endif&#x0A;</xsl:text>
220</xsl:template>
221
222
223<!--
224 * libraries
225-->
226<xsl:template match="library">
227 <!-- forward declarations -->
228 <xsl:text>// forward declarations&#x0A;&#x0A;</xsl:text>
229 <xsl:for-each select="interface | collection | enumerator">
230 <xsl:text>class C</xsl:text>
231 <xsl:value-of select="substring(@name,2)"/>
232 <xsl:text>;&#x0A;</xsl:text>
233 </xsl:for-each>
234 <xsl:text>&#x0A;</xsl:text>
235 <!-- array typedefs -->
236 <xsl:text>// array typedefs&#x0A;&#x0A;</xsl:text>
237 <xsl:for-each select="interface[not(@internal='yes')]">
238 <xsl:if test="
239 (//attribute[@safearray='yes' and not(@internal='yes') and @type=current()/@name])
240 or
241 (//param[@safearray='yes' and not(../@internal='yes') and @type=current()/@name])
242 ">
243 <xsl:text>typedef QValueVector &lt;C</xsl:text>
244 <xsl:value-of select="substring(@name,2)"/>
245 <xsl:text>&gt; C</xsl:text>
246 <xsl:value-of select="substring(@name,2)"/>
247 <xsl:text>Vector;&#x0A;</xsl:text>
248 </xsl:if>
249 </xsl:for-each>
250 <xsl:text>&#x0A;</xsl:text>
251 <!-- wrapper declarations -->
252 <xsl:text>// wrapper declarations&#x0A;&#x0A;</xsl:text>
253 <xsl:apply-templates select="
254 if |
255 interface[not(@internal='yes')] |
256 collection[not(@internal='yes')] |
257 enumerator[not(@internal='yes')]
258 "
259 mode="declare"
260 />
261 <!-- wrapper definitions -->
262 <xsl:text>// wrapper definitions&#x0A;&#x0A;</xsl:text>
263 <xsl:apply-templates select="
264 if |
265 interface[not(@internal='yes')] |
266 collection[not(@internal='yes')] |
267 enumerator[not(@internal='yes')]
268 "
269 mode="define"
270 />
271</xsl:template>
272
273
274<!--
275 * interface declarations
276-->
277<xsl:template match="interface | collection | enumerator" mode="declare">
278
279 <xsl:text>// </xsl:text>
280 <xsl:value-of select="@name"/>
281 <xsl:text> wrapper&#x0A;&#x0A;class C</xsl:text>
282 <xsl:value-of select="substring(@name,2)"/>
283 <xsl:text> : public CInterface &lt;</xsl:text>
284 <xsl:value-of select="@name"/>
285 <!-- use the correct base if supportsErrorInfo -->
286 <xsl:call-template name="tryComposeFetchErrorInfo">
287 <xsl:with-param name="mode" select="'getBaseClassName'"/>
288 </xsl:call-template>
289 <xsl:text>&gt;&#x0A;{&#x0A;public:&#x0A;&#x0A;</xsl:text>
290
291 <!-- generate the Base typedef-->
292 <xsl:text> typedef CInterface &lt;</xsl:text>
293 <xsl:value-of select="@name"/>
294 <!-- Use the correct base if supportsErrorInfo -->
295 <xsl:call-template name="tryComposeFetchErrorInfo">
296 <xsl:with-param name="mode" select="'getBaseClassName'"/>
297 </xsl:call-template>
298 <xsl:text>&gt; Base;&#x0A;&#x0A;</xsl:text>
299
300 <xsl:if test="name()='collection'">
301 <xsl:text> // collection stuff&#x0A;&#x0A;</xsl:text>
302 <xsl:text> ULONG GetCount () const;&#x0A;</xsl:text>
303 <xsl:text> </xsl:text>
304 <xsl:apply-templates select="@type"/>
305 <xsl:text> GetItemAt (ULONG index) const;&#x0A;</xsl:text>
306 <xsl:text> </xsl:text>
307 <xsl:apply-templates select="@enumerator"/>
308 <xsl:text> Enumerate () const;&#x0A;&#x0A;</xsl:text>
309 </xsl:if>
310
311 <xsl:if test="name()='enumerator'">
312 <xsl:text> // enumerator stuff&#x0A;&#x0A;</xsl:text>
313 <xsl:text> BOOL HasMore () const;&#x0A;</xsl:text>
314 <xsl:text> </xsl:text>
315 <xsl:apply-templates select="@type"/>
316 <xsl:text> GetNext () const;&#x0A;&#x0A;</xsl:text>
317 <xsl:text> // friend wrappers&#x0A;&#x0A;</xsl:text>
318 <xsl:text> friend class CUnknown;&#x0A;</xsl:text>
319 <xsl:variable name="name" select="@name"/>
320 <xsl:variable name="parent" select=".."/>
321 <!-- for definitions inside <if> -->
322 <xsl:if test="name(..)='if'">
323 <xsl:for-each select="
324 preceding-sibling::collection | following-sibling::collection |
325 ../preceding-sibling::if[@target=$parent/@target]/collection |
326 ../following-sibling::if[@target=$parent/@target]/collection
327 ">
328 <xsl:if test="@enumerator=$name">
329 <xsl:text> friend class C</xsl:text>
330 <xsl:value-of select="substring(@name,2)"/>
331 <xsl:text>;&#x0A;</xsl:text>
332 </xsl:if>
333 </xsl:for-each>
334 </xsl:if>
335 <!-- for definitions outside <if> (i.e. inside <library>) -->
336 <xsl:if test="name(..)!='if'">
337 <xsl:for-each select="
338 preceding-sibling::collection | following-sibling::collection
339 ">
340 <xsl:if test="@enumerator=$name">
341 <xsl:text> friend class C</xsl:text>
342 <xsl:value-of select="substring(@name,2)"/>
343 <xsl:text>;&#x0A;</xsl:text>
344 </xsl:if>
345 </xsl:for-each>
346 </xsl:if>
347 </xsl:if>
348
349 <xsl:if test="name()='interface' or name()='collection'">
350 <xsl:call-template name="declareMembers"/>
351 </xsl:if>
352
353 <xsl:text>};&#x0A;&#x0A;</xsl:text>
354
355</xsl:template>
356
357<xsl:template name="declareMembers">
358
359 <xsl:text> // constructors and assignments taking CUnknown and </xsl:text>
360 <xsl:text>raw iface pointer&#x0A;&#x0A;</xsl:text>
361 <!-- default constructor -->
362 <xsl:text> C</xsl:text>
363 <xsl:value-of select="substring(@name,2)"/>
364 <xsl:text> () : Base () {}&#x0A;</xsl:text>
365 <!-- constructor taking CUnknown -->
366 <xsl:text> C</xsl:text>
367 <xsl:value-of select="substring(@name,2)"/>
368 <xsl:text> (const CUnknown &amp; that) : Base (that) {}&#x0A;</xsl:text>
369 <!-- constructor taking raw iface pointer -->
370 <xsl:text> C</xsl:text>
371 <xsl:value-of select="substring(@name,2)"/>
372 <xsl:text> (</xsl:text>
373 <xsl:value-of select="@name"/>
374 <xsl:text> *i) : Base (i) {}&#x0A;</xsl:text>
375 <!-- assignment taking CUnknown -->
376 <xsl:text> C</xsl:text>
377 <xsl:value-of select="substring(@name,2)"/>
378 <xsl:text> &amp; operator = (const CUnknown &amp; that)&#x0A; {&#x0A; return (C</xsl:text>
379 <xsl:value-of select="substring(@name,2)"/>
380 <xsl:text> &amp;) Base::operator = (that);&#x0A; }&#x0A;&#x0A;</xsl:text>
381
382 <xsl:text> // attributes (properties)&#x0A;&#x0A;</xsl:text>
383 <xsl:apply-templates select=".//attribute[not(@internal='yes')]" mode="declare"/>
384 <xsl:if test=".//attribute[not(@internal='yes')]">
385 <xsl:text>&#x0A;</xsl:text>
386 </xsl:if>
387
388 <xsl:text> // methods&#x0A;&#x0A;</xsl:text>
389 <xsl:apply-templates select=".//method[not(@internal='yes')]" mode="declare"/>
390 <xsl:if test=".//method[not(@internal='yes')]">
391 <xsl:text>&#x0A;</xsl:text>
392 </xsl:if>
393
394 <xsl:text> // friend wrappers&#x0A;&#x0A;</xsl:text>
395 <xsl:text> friend class CUnknown;&#x0A;</xsl:text>
396 <xsl:variable name="name" select="@name"/>
397 <xsl:variable name="parent" select=".."/>
398 <!-- for definitions inside <if> -->
399 <xsl:if test="name(..)='if'">
400 <xsl:for-each select="
401 preceding-sibling::*[self::interface or self::collection or self::enumerator] |
402 following-sibling::*[self::interface or self::collection or self::enumerator] |
403 ../preceding-sibling::*[self::interface or self::collection or self::enumerator] |
404 ../following-sibling::*[self::interface or self::collection or self::enumerator] |
405 ../preceding-sibling::if[@target=$parent/@target]/*[self::interface or self::collection or self::enumerator] |
406 ../following-sibling::if[@target=$parent/@target]/*[self::interface or self::collection or self::enumerator]
407 ">
408 <xsl:if test="
409 ((name()='interface' or name()='collection')
410 and
411 ((name(..)!='if' and (if[@target=$parent/@target]/method/param[@type=$name]
412 or
413 if[@target=$parent/@target]/attribute[@type=$name]))
414 or
415 (.//method/param[@type=$name] or attribute[@type=$name])))
416 or
417 (name(..)='if' and (name()='collection' or name()='enumerator') and @type=$name)
418 ">
419 <xsl:text> friend class C</xsl:text>
420 <xsl:value-of select="substring(@name,2)"/>
421 <xsl:text>;&#x0A;</xsl:text>
422 </xsl:if>
423 </xsl:for-each>
424 </xsl:if>
425 <!-- for definitions outside <if> (i.e. inside <library>) -->
426 <xsl:if test="name(..)!='if'">
427 <xsl:for-each select="
428 preceding-sibling::*[self::interface or self::collection or self::enumerator] |
429 following-sibling::*[self::interface or self::collection or self::enumerator] |
430 preceding-sibling::if/*[self::interface or self::collection or self::enumerator] |
431 following-sibling::if/*[self::interface or self::collection or self::enumerator]
432 ">
433 <xsl:if test="
434 ((name()='interface' or name()='collection')
435 and
436 (.//method/param[@type=$name] or attribute[@type=$name]))
437 or
438 ((name()='collection' or name()='enumerator') and @type=$name)
439 ">
440 <xsl:text> friend class C</xsl:text>
441 <xsl:value-of select="substring(@name,2)"/>
442 <xsl:text>;&#x0A;</xsl:text>
443 </xsl:if>
444 </xsl:for-each>
445 </xsl:if>
446
447</xsl:template>
448
449<!-- attribute declarations -->
450<xsl:template match="interface//attribute | collection//attribute" mode="declare">
451 <xsl:if test="@array">
452 <xsl:message terminate="yes">
453 <xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/>
454 <xsl:text>'array' attributes are not supported, use 'safearray="yes"' instead.</xsl:text>
455 </xsl:message>
456 </xsl:if>
457 <xsl:apply-templates select="parent::node()" mode="begin"/>
458 <xsl:apply-templates select="@if" mode="begin"/>
459 <xsl:call-template name="composeMethod">
460 <xsl:with-param name="return" select="."/>
461 </xsl:call-template>
462 <xsl:if test="not(@readonly='yes')">
463 <xsl:call-template name="composeMethod">
464 <xsl:with-param name="return" select="''"/>
465 </xsl:call-template>
466 </xsl:if>
467 <xsl:apply-templates select="@if" mode="end"/>
468 <xsl:apply-templates select="parent::node()" mode="end"/>
469</xsl:template>
470
471<!-- method declarations -->
472<xsl:template match="interface//method | collection//method" mode="declare">
473 <xsl:apply-templates select="parent::node()" mode="begin"/>
474 <xsl:apply-templates select="@if" mode="begin"/>
475 <xsl:call-template name="composeMethod"/>
476 <xsl:apply-templates select="@if" mode="end"/>
477 <xsl:apply-templates select="parent::node()" mode="end"/>
478</xsl:template>
479
480
481<!--
482 * interface definitions
483-->
484<xsl:template match="interface | collection | enumerator" mode="define">
485
486 <xsl:text>// </xsl:text>
487 <xsl:value-of select="@name"/>
488 <xsl:text> wrapper&#x0A;&#x0A;</xsl:text>
489
490 <xsl:if test="name()='collection'">
491 <!-- GetCount -->
492 <xsl:text>inline ULONG C</xsl:text>
493 <xsl:value-of select="substring(@name,2)"/>
494 <xsl:text>::GetCount () const&#x0A;{&#x0A;</xsl:text>
495 <xsl:text> ULONG count = 0;&#x0A;</xsl:text>
496 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
497 <xsl:text> if (!mIface)&#x0A; return count;&#x0A;</xsl:text>
498 <xsl:text> mRC = mIface->COMGETTER(Count) (&amp;count);&#x0A;</xsl:text>
499 <xsl:call-template name="tryComposeFetchErrorInfo"/>
500 <xsl:text> return count;&#x0A;</xsl:text>
501 <xsl:text>}&#x0A;&#x0A;</xsl:text>
502 <!-- GetItemAt -->
503 <xsl:text>inline </xsl:text>
504 <xsl:apply-templates select="@type"/>
505 <xsl:text> C</xsl:text>
506 <xsl:value-of select="substring(@name,2)"/>
507 <xsl:text>::GetItemAt (ULONG index) const&#x0A;{&#x0A;</xsl:text>
508 <xsl:text> </xsl:text><xsl:apply-templates select="@type"/>
509 <xsl:text> item;&#x0A;</xsl:text>
510 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
511 <xsl:text> if (!mIface)&#x0A; return item;&#x0A;</xsl:text>
512 <xsl:text> mRC = mIface->GetItemAt (index, &amp;item.mIface);&#x0A;</xsl:text>
513 <xsl:call-template name="tryComposeFetchErrorInfo"/>
514 <xsl:text> return item;&#x0A;</xsl:text>
515 <xsl:text>}&#x0A;&#x0A;</xsl:text>
516 <!-- Enumerate -->
517 <xsl:text>inline </xsl:text>
518 <xsl:apply-templates select="@enumerator"/>
519 <xsl:text> C</xsl:text>
520 <xsl:value-of select="substring(@name,2)"/>
521 <xsl:text>::Enumerate () const&#x0A;{&#x0A;</xsl:text>
522 <xsl:text> </xsl:text><xsl:apply-templates select="@enumerator"/>
523 <xsl:text> enumerator;&#x0A;</xsl:text>
524 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
525 <xsl:text> if (!mIface)&#x0A; return enumerator;&#x0A;</xsl:text>
526 <xsl:text> mRC = mIface->Enumerate (&amp;enumerator.mIface);&#x0A;</xsl:text>
527 <xsl:call-template name="tryComposeFetchErrorInfo"/>
528 <xsl:text> return enumerator;&#x0A;</xsl:text>
529 <xsl:text>}&#x0A;&#x0A;</xsl:text>
530 </xsl:if>
531
532 <xsl:if test="name()='enumerator'">
533 <!-- HasMore -->
534 <xsl:text>inline BOOL C</xsl:text>
535 <xsl:value-of select="substring(@name,2)"/>
536 <xsl:text>::HasMore () const&#x0A;{&#x0A;</xsl:text>
537 <xsl:text> BOOL more = FALSE;&#x0A;</xsl:text>
538 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
539 <xsl:text> if (!mIface)&#x0A; return more;&#x0A;</xsl:text>
540 <xsl:text> mRC = mIface->HasMore (&amp;more);&#x0A;</xsl:text>
541 <xsl:call-template name="tryComposeFetchErrorInfo"/>
542 <xsl:text> return more;&#x0A;</xsl:text>
543 <xsl:text>}&#x0A;&#x0A;</xsl:text>
544 <!-- GetNext -->
545 <xsl:text>inline </xsl:text>
546 <xsl:apply-templates select="@type"/>
547 <xsl:text> C</xsl:text>
548 <xsl:value-of select="substring(@name,2)"/>
549 <xsl:text>::GetNext () const&#x0A;{&#x0A;</xsl:text>
550 <xsl:text> </xsl:text><xsl:apply-templates select="@type"/>
551 <xsl:text> next;&#x0A;</xsl:text>
552 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
553 <xsl:text> if (!mIface)&#x0A; return next;&#x0A;</xsl:text>
554 <xsl:text> mRC = mIface->GetNext (&amp;next.mIface);&#x0A;</xsl:text>
555 <xsl:call-template name="tryComposeFetchErrorInfo"/>
556 <xsl:text> return next;&#x0A;</xsl:text>
557 <xsl:text>}&#x0A;&#x0A;</xsl:text>
558 </xsl:if>
559
560 <xsl:if test="name()='interface' or name()='collection'">
561 <xsl:call-template name="defineMembers"/>
562 </xsl:if>
563
564</xsl:template>
565
566<xsl:template name="defineMembers">
567 <xsl:apply-templates select=".//attribute[not(@internal='yes')]" mode="define"/>
568 <xsl:apply-templates select=".//method[not(@internal='yes')]" mode="define"/>
569</xsl:template>
570
571<!-- attribute definitions -->
572<xsl:template match="interface//attribute | collection//attribute" mode="define">
573 <xsl:apply-templates select="parent::node()" mode="begin"/>
574 <xsl:apply-templates select="@if" mode="begin"/>
575 <xsl:call-template name="composeMethod">
576 <xsl:with-param name="return" select="."/>
577 <xsl:with-param name="define" select="'yes'"/>
578 </xsl:call-template>
579 <xsl:if test="not(@readonly='yes')">
580 <xsl:call-template name="composeMethod">
581 <xsl:with-param name="return" select="''"/>
582 <xsl:with-param name="define" select="'yes'"/>
583 </xsl:call-template>
584 </xsl:if>
585 <xsl:apply-templates select="@if" mode="end"/>
586 <xsl:apply-templates select="parent::node()" mode="end"/>
587 <xsl:text>&#x0A;</xsl:text>
588</xsl:template>
589
590<!-- method definitions -->
591<xsl:template match="interface//method | collection//method" mode="define">
592 <xsl:apply-templates select="parent::node()" mode="begin"/>
593 <xsl:apply-templates select="@if" mode="begin"/>
594 <xsl:call-template name="composeMethod">
595 <xsl:with-param name="define" select="'yes'"/>
596 </xsl:call-template>
597 <xsl:apply-templates select="@if" mode="end"/>
598 <xsl:apply-templates select="parent::node()" mode="end"/>
599 <xsl:text>&#x0A;</xsl:text>
600</xsl:template>
601
602
603<!--
604 * co-classes
605-->
606<xsl:template match="module/class"/>
607
608
609<!--
610 * enums
611-->
612<xsl:template match="enum"/>
613
614
615<!--
616 * base template to produce interface methods
617 *
618 * @param return
619 * - in <attribute> context, must be '.' for getters and
620 * '' for setters
621 * - in <method> context, must not be specified (the default value
622 * will apply)
623 * @param define
624 * 'yes' to procuce inlined definition outside the class
625 * declaration, or
626 * empty string to produce method declaration only (w/o body)
627-->
628<xsl:template name="composeMethod">
629 <xsl:param name="return" select="param[@dir='return']"/>
630 <xsl:param name="define" select="''"/>
631 <xsl:variable name="namespace" select="(ancestor::interface | ancestor::collection)[1]"/>
632 <xsl:choose>
633 <!-- no return value -->
634 <xsl:when test="not($return)">
635 <xsl:choose>
636 <xsl:when test="$define">
637 <xsl:text>inline </xsl:text>
638 </xsl:when>
639 <xsl:otherwise>
640 <xsl:text> </xsl:text>
641 </xsl:otherwise>
642 </xsl:choose>
643 <xsl:text>void </xsl:text>
644 <xsl:if test="$define">
645 <xsl:text>C</xsl:text>
646 <xsl:value-of select="substring($namespace/@name,2)"/>
647 <xsl:text>::</xsl:text>
648 </xsl:if>
649 <xsl:call-template name="composeMethodDecl">
650 <xsl:with-param name="isSetter" select="'yes'"/>
651 </xsl:call-template>
652 <xsl:if test="$define">
653 <xsl:text>&#x0A;{&#x0A;</xsl:text>
654 <!-- iface assertion -->
655 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
656 <xsl:text> if (!mIface)&#x0A; return;&#x0A;</xsl:text>
657 <!-- method call -->
658 <xsl:call-template name="composeMethodCall">
659 <xsl:with-param name="isSetter" select="'yes'"/>
660 </xsl:call-template>
661 <xsl:text>}&#x0A;</xsl:text>
662 </xsl:if>
663 <xsl:if test="not($define)">
664 <xsl:text>;&#x0A;</xsl:text>
665 </xsl:if>
666 </xsl:when>
667 <!-- has a return value -->
668 <xsl:when test="count($return) = 1">
669 <xsl:choose>
670 <xsl:when test="$define">
671 <xsl:text>inline </xsl:text>
672 </xsl:when>
673 <xsl:otherwise>
674 <xsl:text> </xsl:text>
675 </xsl:otherwise>
676 </xsl:choose>
677 <xsl:apply-templates select="$return/@type"/>
678 <xsl:text> </xsl:text>
679 <xsl:if test="$define">
680 <xsl:text>C</xsl:text>
681 <xsl:value-of select="substring($namespace/@name,2)"/>
682 <xsl:text>::</xsl:text>
683 </xsl:if>
684 <xsl:call-template name="composeMethodDecl"/>
685 <xsl:if test="$define">
686 <xsl:text>&#x0A;{&#x0A; </xsl:text>
687 <xsl:apply-templates select="$return/@type"/>
688 <xsl:text> a</xsl:text>
689 <xsl:call-template name="capitalize">
690 <xsl:with-param name="str" select="$return/@name"/>
691 </xsl:call-template>
692 <xsl:apply-templates select="$return/@type" mode="initializer"/>
693 <xsl:text>;&#x0A;</xsl:text>
694 <!-- iface assertion -->
695 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
696 <xsl:text> if (!mIface)&#x0A; return a</xsl:text>
697 <xsl:call-template name="capitalize">
698 <xsl:with-param name="str" select="$return/@name"/>
699 </xsl:call-template>
700 <xsl:text>;&#x0A;</xsl:text>
701 <!-- method call -->
702 <xsl:call-template name="composeMethodCall"/>
703 <!-- return statement -->
704 <xsl:text> return a</xsl:text>
705 <xsl:call-template name="capitalize">
706 <xsl:with-param name="str" select="$return/@name"/>
707 </xsl:call-template>
708 <xsl:text>;&#x0A;}&#x0A;</xsl:text>
709 </xsl:if>
710 <xsl:if test="not($define)">
711 <xsl:text>;&#x0A;</xsl:text>
712 </xsl:if>
713 </xsl:when>
714 <!-- otherwise error -->
715 <xsl:otherwise>
716 <xsl:message terminate="yes">
717 <xsl:text>More than one return value in method: </xsl:text>
718 <xsl:value-of select="$namespace/@name"/>
719 <xsl:text>::</xsl:text>
720 <xsl:value-of select="@name"/>
721 </xsl:message>
722 </xsl:otherwise>
723 </xsl:choose>
724</xsl:template>
725
726<xsl:template name="composeMethodDecl">
727 <xsl:param name="isSetter" select="''"/>
728 <xsl:choose>
729 <!-- attribute method call -->
730 <xsl:when test="name()='attribute'">
731 <xsl:choose>
732 <xsl:when test="$isSetter">
733 <!-- name -->
734 <xsl:text>Set</xsl:text>
735 <xsl:call-template name="capitalize">
736 <xsl:with-param name="str" select="@name"/>
737 </xsl:call-template>
738 <xsl:text> (</xsl:text>
739 <!-- parameter -->
740 <xsl:apply-templates select="@type" mode="param"/>
741 <xsl:text> a</xsl:text>
742 <xsl:call-template name="capitalize">
743 <xsl:with-param name="str" select="@name"/>
744 </xsl:call-template>
745 <xsl:text>)</xsl:text>
746 </xsl:when>
747 <xsl:otherwise>
748 <!-- name -->
749 <xsl:text>Get</xsl:text>
750 <xsl:call-template name="capitalize">
751 <xsl:with-param name="str" select="@name"/>
752 </xsl:call-template>
753 <xsl:text> (</xsl:text>
754 <!-- const method -->
755 <xsl:text>) const</xsl:text>
756 </xsl:otherwise>
757 </xsl:choose>
758 </xsl:when>
759 <!-- regular method call -->
760 <xsl:when test="name()='method'">
761 <!-- name -->
762 <xsl:call-template name="capitalize">
763 <xsl:with-param name="str" select="@name"/>
764 </xsl:call-template>
765 <xsl:text> (</xsl:text>
766 <!-- parameters -->
767 <xsl:for-each select="param[@dir!='return']">
768 <xsl:apply-templates select="@type" mode="param"/>
769 <xsl:text> a</xsl:text>
770 <xsl:call-template name="capitalize">
771 <xsl:with-param name="str" select="@name"/>
772 </xsl:call-template>
773 <xsl:if test="position() != last()">
774 <xsl:text>, </xsl:text>
775 </xsl:if>
776 </xsl:for-each>
777 <xsl:text>)</xsl:text>
778 <!-- const method -->
779 <xsl:if test="@const='yes'"> const</xsl:if>
780 </xsl:when>
781 </xsl:choose>
782</xsl:template>
783
784<xsl:template name="composeMethodCall">
785 <xsl:param name="isSetter" select="''"/>
786 <!-- apply 'pre-call' hooks -->
787 <xsl:choose>
788 <xsl:when test="name()='attribute'">
789 <xsl:call-template name="hooks">
790 <xsl:with-param name="when" select="'pre-call'"/>
791 <xsl:with-param name="isSetter" select="$isSetter"/>
792 </xsl:call-template>
793 </xsl:when>
794 <xsl:when test="name()='method'">
795 <xsl:for-each select="param">
796 <xsl:call-template name="hooks">
797 <xsl:with-param name="when" select="'pre-call'"/>
798 </xsl:call-template>
799 </xsl:for-each>
800 </xsl:when>
801 </xsl:choose>
802 <!-- start the call -->
803 <xsl:text> mRC = mIface-></xsl:text>
804 <xsl:choose>
805 <!-- attribute method call -->
806 <xsl:when test="name()='attribute'">
807 <!-- method name -->
808 <xsl:choose>
809 <xsl:when test="$isSetter">
810 <xsl:text>COMSETTER(</xsl:text>
811 </xsl:when>
812 <xsl:otherwise>
813 <xsl:text>COMGETTER(</xsl:text>
814 </xsl:otherwise>
815 </xsl:choose>
816 <xsl:call-template name="capitalize">
817 <xsl:with-param name="str" select="@name"/>
818 </xsl:call-template>
819 <xsl:text>) (</xsl:text>
820 <!-- parameter -->
821 <xsl:call-template name="composeMethodCallParam">
822 <xsl:with-param name="isIn" select="$isSetter"/>
823 <xsl:with-param name="isOut" select="not($isSetter)"/>
824 </xsl:call-template>
825 </xsl:when>
826 <!-- regular method call -->
827 <xsl:when test="name()='method'">
828 <!-- method name -->
829 <xsl:call-template name="capitalize">
830 <xsl:with-param name="str" select="@name"/>
831 </xsl:call-template>
832 <xsl:text> (</xsl:text>
833 <!-- parameters -->
834 <xsl:for-each select="param">
835 <xsl:call-template name="composeMethodCallParam"/>
836 <xsl:if test="position() != last()">
837 <xsl:text>, </xsl:text>
838 </xsl:if>
839 </xsl:for-each>
840 </xsl:when>
841 </xsl:choose>
842 <xsl:text>);&#x0A;</xsl:text>
843 <!-- apply 'post-call' hooks -->
844 <xsl:choose>
845 <xsl:when test="name()='attribute'">
846 <xsl:call-template name="hooks">
847 <xsl:with-param name="when" select="'post-call'"/>
848 <xsl:with-param name="isSetter" select="$isSetter"/>
849 </xsl:call-template>
850 </xsl:when>
851 <xsl:when test="name()='method'">
852 <xsl:for-each select="param">
853 <xsl:call-template name="hooks">
854 <xsl:with-param name="when" select="'post-call'"/>
855 </xsl:call-template>
856 </xsl:for-each>
857 </xsl:when>
858 </xsl:choose>
859 <!-- -->
860 <xsl:call-template name="tryComposeFetchErrorInfo"/>
861</xsl:template>
862
863<!--
864 * Composes a 'fetch error info' call or returns the name of the
865 * appropriate base class name that provides error info functionality
866 * (depending on the mode parameter). Does nothing if the current
867 * entity (interface, collection or enumerator) does not support error info.
868 *
869 * @param mode
870 * - 'getBaseClassName': expands to the base class name
871 * - any other value: composes a 'fetch error info' method call
872-->
873<xsl:template name="tryComposeFetchErrorInfo">
874 <xsl:param name="mode" select="''"/>
875 <xsl:variable name="ifaceSupportsErrorInfo" select="
876 (ancestor-or-self::interface |
877 ancestor-or-self::collection |
878 ancestor-or-self::enumerator)[1]/@supportsErrorInfo
879 "/>
880 <xsl:variable name="librarySupportsErrorInfo" select="ancestor::library/@supportsErrorInfo"/>
881 <xsl:choose>
882 <xsl:when test="$ifaceSupportsErrorInfo">
883 <xsl:call-template name="composeFetchErrorInfo">
884 <xsl:with-param name="supports" select="string($ifaceSupportsErrorInfo)"/>
885 <xsl:with-param name="mode" select="$mode"/>
886 </xsl:call-template>
887 </xsl:when>
888 <xsl:when test="$librarySupportsErrorInfo">
889 <xsl:call-template name="composeFetchErrorInfo">
890 <xsl:with-param name="supports" select="string($librarySupportsErrorInfo)"/>
891 <xsl:with-param name="mode" select="$mode"/>
892 </xsl:call-template>
893 </xsl:when>
894 </xsl:choose>
895</xsl:template>
896
897<xsl:template name="composeFetchErrorInfo">
898 <xsl:param name="supports" select="''"/>
899 <xsl:param name="mode" select="''"/>
900 <xsl:choose>
901 <xsl:when test="$mode='getBaseClassName'">
902 <xsl:if test="$supports='strict' or $supports='yes'">
903 <xsl:text>, COMBaseWithEI</xsl:text>
904 </xsl:if>
905 </xsl:when>
906 <xsl:otherwise>
907 <xsl:if test="$supports='strict' or $supports='yes'">
908 <xsl:text> if (FAILED (mRC))&#x0A; {&#x0A;</xsl:text>
909 <xsl:text> fetchErrorInfo (mIface, &amp;COM_IIDOF (Base::Iface));&#x0A;</xsl:text>
910 <xsl:if test="$supports='strict'">
911 <xsl:text> AssertMsg (errInfo.isFullAvailable(), </xsl:text>
912 <xsl:text>("for RC=0x%08X\n", mRC));&#x0A;</xsl:text>
913 </xsl:if>
914 <xsl:text> }&#x0A;</xsl:text>
915 </xsl:if>
916 </xsl:otherwise>
917 </xsl:choose>
918</xsl:template>
919
920<xsl:template name="composeMethodCallParam">
921
922 <xsl:param name="isIn" select="@dir='in'"/>
923 <xsl:param name="isOut" select="@dir='out' or @dir='return'"/>
924
925 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
926
927 <xsl:choose>
928 <!-- safearrays -->
929 <xsl:when test="@safearray='yes'">
930 <xsl:choose>
931 <xsl:when test="$isIn">
932 <xsl:text>ComSafeArrayAsInParam (</xsl:text>
933 <xsl:value-of select="@name"/>
934 <xsl:text>)</xsl:text>
935 </xsl:when>
936 <xsl:when test="$isOut">
937 <xsl:text>ComSafeArrayAsOutParam (</xsl:text>
938 <xsl:value-of select="@name"/>
939 <xsl:text>)</xsl:text>
940 </xsl:when>
941 </xsl:choose>
942 </xsl:when>
943 <!-- string types -->
944 <xsl:when test="@type = 'wstring'">
945 <xsl:choose>
946 <xsl:when test="$isIn">
947 <xsl:text>BSTRIn (a</xsl:text>
948 <xsl:call-template name="capitalize">
949 <xsl:with-param name="str" select="@name"/>
950 </xsl:call-template>
951 <xsl:text>)</xsl:text>
952 </xsl:when>
953 <xsl:when test="$isOut">
954 <xsl:text>BSTROut (a</xsl:text>
955 <xsl:call-template name="capitalize">
956 <xsl:with-param name="str" select="@name"/>
957 </xsl:call-template>
958 <xsl:text>)</xsl:text>
959 </xsl:when>
960 </xsl:choose>
961 </xsl:when>
962 <!-- uuid type -->
963 <xsl:when test="@type = 'uuid'">
964 <xsl:choose>
965 <xsl:when test="$isIn">
966 <xsl:text>GUIDIn (a</xsl:text>
967 <xsl:call-template name="capitalize">
968 <xsl:with-param name="str" select="@name"/>
969 </xsl:call-template>
970 <xsl:text>)</xsl:text>
971 </xsl:when>
972 <xsl:when test="$isOut">
973 <xsl:text>GUIDOut (a</xsl:text>
974 <xsl:call-template name="capitalize">
975 <xsl:with-param name="str" select="@name"/>
976 </xsl:call-template>
977 <xsl:text>)</xsl:text>
978 </xsl:when>
979 </xsl:choose>
980 </xsl:when>
981 <!-- enum types -->
982 <xsl:when test="
983 (ancestor::library/enum[@name=current()/@type]) or
984 (ancestor::library/if[@target=$self_target]/enum[@name=current()/@type])
985 ">
986 <xsl:choose>
987 <xsl:when test="$isIn">
988 <xsl:text>(</xsl:text>
989 <xsl:value-of select="@type"/>
990 <xsl:text>_T) a</xsl:text>
991 <xsl:call-template name="capitalize">
992 <xsl:with-param name="str" select="@name"/>
993 </xsl:call-template>
994 </xsl:when>
995 <xsl:when test="$isOut">
996 <xsl:text>ENUMOut &lt;CEnums::</xsl:text>
997 <xsl:value-of select="@type"/>
998 <xsl:text>, </xsl:text>
999 <xsl:value-of select="@type"/>
1000 <xsl:text>_T&gt; (a</xsl:text>
1001 <xsl:call-template name="capitalize">
1002 <xsl:with-param name="str" select="@name"/>
1003 </xsl:call-template>
1004 <xsl:text>)</xsl:text>
1005 </xsl:when>
1006 </xsl:choose>
1007 </xsl:when>
1008 <!-- interface types -->
1009 <xsl:when test="
1010 @type='$unknown' or
1011 ((ancestor::library/enumerator[@name=current()/@type]) or
1012 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()/@type])
1013 ) or
1014 ((ancestor::library/interface[@name=current()/@type]) or
1015 (ancestor::library/if[@target=$self_target]/interface[@name=current()/@type])
1016 ) or
1017 ((ancestor::library/collection[@name=current()/@type]) or
1018 (ancestor::library/if[@target=$self_target]/collection[@name=current()/@type])
1019 )
1020 ">
1021 <xsl:choose>
1022 <xsl:when test="$isIn">
1023 <xsl:text>a</xsl:text>
1024 <xsl:call-template name="capitalize">
1025 <xsl:with-param name="str" select="@name"/>
1026 </xsl:call-template>
1027 <xsl:choose>
1028 <xsl:when test="@type='$unknown'">
1029 <xsl:text>.iface()</xsl:text>
1030 </xsl:when>
1031 <xsl:otherwise>
1032 <xsl:text>.mIface</xsl:text>
1033 </xsl:otherwise>
1034 </xsl:choose>
1035 </xsl:when>
1036 <xsl:when test="$isOut">
1037 <xsl:text>&amp;a</xsl:text>
1038 <xsl:call-template name="capitalize">
1039 <xsl:with-param name="str" select="@name"/>
1040 </xsl:call-template>
1041 <xsl:choose>
1042 <xsl:when test="@type='$unknown'">
1043 <xsl:text>.ifaceRef()</xsl:text>
1044 </xsl:when>
1045 <xsl:otherwise>
1046 <xsl:text>.mIface</xsl:text>
1047 </xsl:otherwise>
1048 </xsl:choose>
1049 </xsl:when>
1050 </xsl:choose>
1051 </xsl:when>
1052 <!-- currently unsupported types -->
1053 <xsl:when test="@type = 'string'">
1054 <xsl:message terminate="yes">
1055 <xsl:text>Parameter type </xsl:text>
1056 <xsl:value-of select="@type"/>
1057 <xsl:text>is not currently supported</xsl:text>
1058 </xsl:message>
1059 </xsl:when>
1060 <!-- assuming scalar types -->
1061 <xsl:otherwise>
1062 <xsl:choose>
1063 <xsl:when test="$isIn">
1064 <xsl:text>a</xsl:text>
1065 <xsl:call-template name="capitalize">
1066 <xsl:with-param name="str" select="@name"/>
1067 </xsl:call-template>
1068 </xsl:when>
1069 <xsl:when test="$isOut">
1070 <xsl:text>&amp;a</xsl:text>
1071 <xsl:call-template name="capitalize">
1072 <xsl:with-param name="str" select="@name"/>
1073 </xsl:call-template>
1074 </xsl:when>
1075 </xsl:choose>
1076 </xsl:otherwise>
1077 </xsl:choose>
1078</xsl:template>
1079
1080
1081<!--
1082 * attribute/parameter type conversion (returns plain Qt type name)
1083-->
1084<xsl:template match="
1085 attribute/@type | param/@type |
1086 enumerator/@type | collection/@type | collection/@enumerator
1087">
1088 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1089
1090 <xsl:if test="../@array and ../@safearray='yes'">
1091 <xsl:message terminate="yes">
1092 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1093 <xsl:text>either 'array' or 'safearray="yes"' attribute is allowed, but not both!</xsl:text>
1094 </xsl:message>
1095 </xsl:if>
1096
1097 <xsl:if test="../@array and ((name(..)='param' and ../@dir='return') or (name(..)='attribute'))">
1098 <xsl:message terminate="yes">
1099 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1100 <xsl:text>return 'array' parameters and 'array' attributes are not supported, use 'safearray="yes"' instead.</xsl:text>
1101 </xsl:message>
1102 </xsl:if>
1103
1104 <xsl:choose>
1105 <!-- modifiers (ignored for 'enumeration' attributes)-->
1106 <xsl:when test="name(current())='type' and ../@mod">
1107 <xsl:if test="../@safearray">
1108 <xsl:message terminate="yes">
1109 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1110 <xsl:text>either 'safearray' or 'mod' attribute is allowed, but not both!</xsl:text>
1111 </xsl:message>
1112 </xsl:if>
1113 <xsl:if test="../@array">
1114 <xsl:message terminate="yes">
1115 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1116 <xsl:text>either 'array' or 'mod' attribute is allowed, but not both!</xsl:text>
1117 </xsl:message>
1118 </xsl:if>
1119 <xsl:choose>
1120 <xsl:when test="../@mod='ptr'">
1121 <xsl:choose>
1122 <!-- standard types -->
1123 <!--xsl:when test=".='result'">??</xsl:when-->
1124 <xsl:when test=".='boolean'">BOOL *</xsl:when>
1125 <xsl:when test=".='octet'">BYTE *</xsl:when>
1126 <xsl:when test=".='short'">SHORT *</xsl:when>
1127 <xsl:when test=".='unsigned short'">USHORT *</xsl:when>
1128 <xsl:when test=".='long'">LONG *</xsl:when>
1129 <xsl:when test=".='long long'">LONG64 *</xsl:when>
1130 <xsl:when test=".='unsigned long'">ULONG *</xsl:when>
1131 <xsl:when test=".='unsigned long long'">ULONG64 *</xsl:when>
1132 <xsl:when test=".='char'">CHAR *</xsl:when>
1133 <!--<xsl:when test=".='string'">??</xsl:when-->
1134 <xsl:when test=".='wchar'">OLECHAR *</xsl:when>
1135 <!--<xsl:when test=".='wstring'">??</xsl:when-->
1136 <xsl:otherwise>
1137 <xsl:message terminate="yes">
1138 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1139 <xsl:text>attribute 'mod=</xsl:text>
1140 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
1141 <xsl:text>' cannot be used with type </xsl:text>
1142 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
1143 </xsl:message>
1144 </xsl:otherwise>
1145 </xsl:choose>
1146 </xsl:when>
1147 <xsl:otherwise>
1148 <xsl:message terminate="yes">
1149 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1150 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
1151 <xsl:text>of attribute 'mod' is invalid!</xsl:text>
1152 </xsl:message>
1153 </xsl:otherwise>
1154 </xsl:choose>
1155 </xsl:when>
1156 <!-- no modifiers -->
1157 <xsl:otherwise>
1158 <xsl:if test="../@safearray">
1159 <xsl:text>QValueVector &lt;</xsl:text>
1160 </xsl:if>
1161 <xsl:choose>
1162 <!-- standard types -->
1163 <xsl:when test=".='result'">HRESULT</xsl:when>
1164 <xsl:when test=".='boolean'">BOOL</xsl:when>
1165 <xsl:when test=".='octet'">BYTE</xsl:when>
1166 <xsl:when test=".='short'">SHORT</xsl:when>
1167 <xsl:when test=".='unsigned short'">USHORT</xsl:when>
1168 <xsl:when test=".='long'">LONG</xsl:when>
1169 <xsl:when test=".='long long'">LONG64</xsl:when>
1170 <xsl:when test=".='unsigned long'">ULONG</xsl:when>
1171 <xsl:when test=".='unsigned long long'">ULONG64</xsl:when>
1172 <xsl:when test=".='char'">CHAR</xsl:when>
1173 <xsl:when test=".='string'">CHAR *</xsl:when>
1174 <xsl:when test=".='wchar'">OLECHAR</xsl:when>
1175 <xsl:when test=".='wstring'">QString</xsl:when>
1176 <!-- UUID type -->
1177 <xsl:when test=".='uuid'">QUuid</xsl:when>
1178 <!-- system interface types -->
1179 <xsl:when test=".='$unknown'">CUnknown</xsl:when>
1180 <xsl:otherwise>
1181 <xsl:choose>
1182 <!-- enum types -->
1183 <xsl:when test="
1184 (ancestor::library/enum[@name=current()]) or
1185 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
1186 ">
1187 <xsl:value-of select="concat('CEnums::',string(.))"/>
1188 </xsl:when>
1189 <!-- custom interface types -->
1190 <xsl:when test="
1191 (name(current())='enumerator' and
1192 ((ancestor::library/enumerator[@name=current()]) or
1193 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()]))
1194 ) or
1195 ((ancestor::library/interface[@name=current()]) or
1196 (ancestor::library/if[@target=$self_target]/interface[@name=current()])
1197 ) or
1198 ((ancestor::library/collection[@name=current()]) or
1199 (ancestor::library/if[@target=$self_target]/collection[@name=current()])
1200 )
1201 ">
1202 <xsl:value-of select="concat('C',substring(.,2))"/>
1203 </xsl:when>
1204 <!-- other types -->
1205 <xsl:otherwise>
1206 <xsl:message terminate="yes">
1207 <xsl:text>Unknown parameter type: </xsl:text>
1208 <xsl:value-of select="."/>
1209 </xsl:message>
1210 </xsl:otherwise>
1211 </xsl:choose>
1212 </xsl:otherwise>
1213 </xsl:choose>
1214 <xsl:if test="../@safearray">
1215 <xsl:text>&gt;</xsl:text>
1216 </xsl:if>
1217 </xsl:otherwise>
1218 </xsl:choose>
1219</xsl:template>
1220
1221
1222<!--
1223 * generates a null initializer for all scalar types (such as bool or long)
1224 * and enum types in the form of ' = <null_initializer>', or nothing for other
1225 * types.
1226-->
1227<xsl:template match="
1228 attribute/@type | param/@type |
1229 enumerator/@type | collection/@type | collection/@enumerator
1230" mode="initializer">
1231
1232 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1233
1234 <xsl:choose>
1235 <!-- safearrays don't need initializers -->
1236 <xsl:when test="../@safearray">
1237 </xsl:when>
1238 <!-- modifiers (ignored for 'enumeration' attributes)-->
1239 <xsl:when test="name(current())='type' and ../@mod">
1240 <xsl:choose>
1241 <xsl:when test="../@mod='ptr'">
1242 <xsl:choose>
1243 <!-- standard types -->
1244 <!--xsl:when test=".='result'">??</xsl:when-->
1245 <xsl:when test=".='boolean'"> = NULL</xsl:when>
1246 <xsl:when test=".='octet'"> = NULL</xsl:when>
1247 <xsl:when test=".='short'"> = NULL</xsl:when>
1248 <xsl:when test=".='unsigned short'"> = NULL</xsl:when>
1249 <xsl:when test=".='long'"> = NULL</xsl:when>
1250 <xsl:when test=".='long long'"> = NULL</xsl:when>
1251 <xsl:when test=".='unsigned long'"> = NULL</xsl:when>
1252 <xsl:when test=".='unsigned long long'"> = NULL</xsl:when>
1253 <xsl:when test=".='char'"> = NULL</xsl:when>
1254 <!--<xsl:when test=".='string'">??</xsl:when-->
1255 <xsl:when test=".='wchar'"> = NULL</xsl:when>
1256 <!--<xsl:when test=".='wstring'">??</xsl:when-->
1257 <xsl:otherwise>
1258 <xsl:message terminate="yes">
1259 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1260 <xsl:text>attribute 'mod=</xsl:text>
1261 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
1262 <xsl:text>' cannot be used with type </xsl:text>
1263 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
1264 </xsl:message>
1265 </xsl:otherwise>
1266 </xsl:choose>
1267 </xsl:when>
1268 <xsl:otherwise>
1269 <xsl:message terminate="yes">
1270 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1271 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
1272 <xsl:text>of attribute 'mod' is invalid!</xsl:text>
1273 </xsl:message>
1274 </xsl:otherwise>
1275 </xsl:choose>
1276 </xsl:when>
1277 <!-- no modifiers -->
1278 <xsl:otherwise>
1279 <xsl:choose>
1280 <!-- standard types that need a zero initializer -->
1281 <xsl:when test=".='result'"> = S_OK</xsl:when>
1282 <xsl:when test=".='boolean'"> = FALSE</xsl:when>
1283 <xsl:when test=".='octet'"> = 0</xsl:when>
1284 <xsl:when test=".='short'"> = 0</xsl:when>
1285 <xsl:when test=".='unsigned short'"> = 0</xsl:when>
1286 <xsl:when test=".='long'"> = 0</xsl:when>
1287 <xsl:when test=".='long long'"> = 0</xsl:when>
1288 <xsl:when test=".='unsigned long'"> = 0</xsl:when>
1289 <xsl:when test=".='unsigned long long'"> = 0</xsl:when>
1290 <xsl:when test=".='char'"> = 0</xsl:when>
1291 <xsl:when test=".='string'"> = NULL</xsl:when>
1292 <xsl:when test=".='wchar'"> = 0</xsl:when>
1293 <xsl:otherwise>
1294 <xsl:choose>
1295 <!-- enum types initialized with 0 -->
1296 <xsl:when test="
1297 (ancestor::library/enum[@name=current()]) or
1298 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
1299 ">
1300 <xsl:value-of select="concat(' = (CEnums::',string(.),') 0')"/>
1301 </xsl:when>
1302 </xsl:choose>
1303 </xsl:otherwise>
1304 </xsl:choose>
1305 </xsl:otherwise>
1306 </xsl:choose>
1307</xsl:template>
1308
1309
1310<!--
1311 * attribute/parameter type conversion (for method declaration)
1312-->
1313<xsl:template match="attribute/@type | param/@type" mode="param">
1314
1315 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1316
1317 <xsl:choose>
1318 <!-- class types -->
1319 <xsl:when test="
1320 .='string' or
1321 .='wstring' or
1322 ../@safearray='yes' or
1323 ((ancestor::library/enum[@name=current()]) or
1324 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
1325 ) or
1326 .='$unknown' or
1327 ((ancestor::library/enumerator[@name=current()]) or
1328 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()])
1329 ) or
1330 ((ancestor::library/interface[@name=current()]) or
1331 (ancestor::library/if[@target=$self_target]/interface[@name=current()])
1332 ) or
1333 ((ancestor::library/collection[@name=current()]) or
1334 (ancestor::library/if[@target=$self_target]/collection[@name=current()])
1335 )
1336 ">
1337 <xsl:choose>
1338 <!-- <attribute> context -->
1339 <xsl:when test="name(..)='attribute'">
1340 <xsl:text>const </xsl:text>
1341 <xsl:apply-templates select="."/>
1342 <xsl:text> &amp;</xsl:text>
1343 </xsl:when>
1344 <!-- <param> context -->
1345 <xsl:when test="name(..)='param'">
1346 <xsl:choose>
1347 <xsl:when test="../@dir='in'">
1348 <xsl:text>const </xsl:text>
1349 <xsl:apply-templates select="."/>
1350 <xsl:text> &amp;</xsl:text>
1351 </xsl:when>
1352 <xsl:when test="../@dir='out'">
1353 <xsl:apply-templates select="."/>
1354 <xsl:text> &amp;</xsl:text>
1355 </xsl:when>
1356 <xsl:when test="../@dir='return'">
1357 <xsl:apply-templates select="."/>
1358 </xsl:when>
1359 </xsl:choose>
1360 </xsl:when>
1361 </xsl:choose>
1362 </xsl:when>
1363 <!-- assume scalar types -->
1364 <xsl:otherwise>
1365 <xsl:choose>
1366 <!-- <attribute> context -->
1367 <xsl:when test="name(..)='attribute'">
1368 <xsl:apply-templates select="."/>
1369 </xsl:when>
1370 <!-- <param> context -->
1371 <xsl:when test="name(..)='param'">
1372 <xsl:choose>
1373 <xsl:when test="../@array">
1374 <xsl:apply-templates select="."/>
1375 <xsl:text> *</xsl:text>
1376 <xsl:if test="../@dir='out'">
1377 <xsl:text> &amp;</xsl:text>
1378 </xsl:if>
1379 </xsl:when>
1380 <xsl:otherwise>
1381 <xsl:apply-templates select="."/>
1382 <xsl:if test="../@dir='out'">
1383 <xsl:text> &amp;</xsl:text>
1384 </xsl:if>
1385 </xsl:otherwise>
1386 </xsl:choose>
1387 </xsl:when>
1388 </xsl:choose>
1389 </xsl:otherwise>
1390 </xsl:choose>
1391</xsl:template>
1392
1393
1394<!--
1395 * attribute/parameter type conversion (returns plain COM type name)
1396 * (basically, copied from midl.xsl)
1397-->
1398<xsl:template match="
1399 attribute/@type | param/@type |
1400 enumerator/@type | collection/@type | collection/@enumerator
1401" mode="com">
1402
1403 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1404
1405 <xsl:choose>
1406 <!-- modifiers (ignored for 'enumeration' attributes)-->
1407 <xsl:when test="name(current())='type' and ../@mod">
1408 <xsl:choose>
1409 <xsl:when test="../@mod='ptr'">
1410 <xsl:choose>
1411 <!-- standard types -->
1412 <!--xsl:when test=".='result'">??</xsl:when-->
1413 <xsl:when test=".='boolean'">BOOL *</xsl:when>
1414 <xsl:when test=".='octet'">BYTE *</xsl:when>
1415 <xsl:when test=".='short'">SHORT *</xsl:when>
1416 <xsl:when test=".='unsigned short'">USHORT *</xsl:when>
1417 <xsl:when test=".='long'">LONG *</xsl:when>
1418 <xsl:when test=".='long long'">LONG64 *</xsl:when>
1419 <xsl:when test=".='unsigned long'">ULONG *</xsl:when>
1420 <xsl:when test=".='unsigned long long'">ULONG64 *</xsl:when>
1421 <xsl:when test=".='char'">CHAR *</xsl:when>
1422 <!--xsl:when test=".='string'">??</xsl:when-->
1423 <xsl:when test=".='wchar'">OLECHAR *</xsl:when>
1424 <!--xsl:when test=".='wstring'">??</xsl:when-->
1425 <xsl:otherwise>
1426 <xsl:message terminate="yes">
1427 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1428 <xsl:text>attribute 'mod=</xsl:text>
1429 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
1430 <xsl:text>' cannot be used with type </xsl:text>
1431 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
1432 </xsl:message>
1433 </xsl:otherwise>
1434 </xsl:choose>
1435 </xsl:when>
1436 <xsl:otherwise>
1437 <xsl:message terminate="yes">
1438 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1439 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
1440 <xsl:text>of attribute 'mod' is invalid!</xsl:text>
1441 </xsl:message>
1442 </xsl:otherwise>
1443 </xsl:choose>
1444 </xsl:when>
1445 <!-- no modifiers -->
1446 <xsl:otherwise>
1447 <xsl:choose>
1448 <!-- standard types -->
1449 <xsl:when test=".='result'">HRESULT</xsl:when>
1450 <xsl:when test=".='boolean'">BOOL</xsl:when>
1451 <xsl:when test=".='octet'">BYTE</xsl:when>
1452 <xsl:when test=".='short'">SHORT</xsl:when>
1453 <xsl:when test=".='unsigned short'">USHORT</xsl:when>
1454 <xsl:when test=".='long'">LONG</xsl:when>
1455 <xsl:when test=".='long long'">LONG64</xsl:when>
1456 <xsl:when test=".='unsigned long'">ULONG</xsl:when>
1457 <xsl:when test=".='unsigned long long'">ULONG64</xsl:when>
1458 <xsl:when test=".='char'">CHAR</xsl:when>
1459 <xsl:when test=".='string'">CHAR *</xsl:when>
1460 <xsl:when test=".='wchar'">OLECHAR</xsl:when>
1461 <xsl:when test=".='wstring'">BSTR</xsl:when>
1462 <!-- UUID type -->
1463 <xsl:when test=".='uuid'">GUID</xsl:when>
1464 <!-- system interface types -->
1465 <xsl:when test=".='$unknown'">IUnknown *</xsl:when>
1466 <xsl:otherwise>
1467 <xsl:choose>
1468 <!-- enum types -->
1469 <xsl:when test="
1470 (ancestor::library/enum[@name=current()]) or
1471 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
1472 ">
1473 <xsl:value-of select="."/>
1474 </xsl:when>
1475 <!-- custom interface types -->
1476 <xsl:when test="
1477 (name(current())='enumerator' and
1478 ((ancestor::library/enumerator[@name=current()]) or
1479 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()]))
1480 ) or
1481 ((ancestor::library/interface[@name=current()]) or
1482 (ancestor::library/if[@target=$self_target]/interface[@name=current()])
1483 ) or
1484 ((ancestor::library/collection[@name=current()]) or
1485 (ancestor::library/if[@target=$self_target]/collection[@name=current()])
1486 )
1487 ">
1488 <xsl:value-of select="."/><xsl:text> *</xsl:text>
1489 </xsl:when>
1490 <!-- other types -->
1491 <xsl:otherwise>
1492 <xsl:message terminate="yes">
1493 <xsl:text>Unknown parameter type: </xsl:text>
1494 <xsl:value-of select="."/>
1495 </xsl:message>
1496 </xsl:otherwise>
1497 </xsl:choose>
1498 </xsl:otherwise>
1499 </xsl:choose>
1500 </xsl:otherwise>
1501 </xsl:choose>
1502</xsl:template>
1503
1504
1505<!--
1506 * attribute/parameter type additional hooks.
1507 *
1508 * Called in the context of <attribute> or <param> elements.
1509 *
1510 * @param when When the hook is being called:
1511 * 'pre-call' - right before the method call
1512 * 'post-call' - right after the method call
1513 * @param isSetter Non-empty if called in the cotext of the attribute setter
1514 * call.
1515-->
1516<xsl:template name="hooks">
1517
1518 <xsl:param name="when" select="''"/>
1519 <xsl:param name="isSetter" select="''"/>
1520
1521 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1522
1523 <xsl:variable name="is_iface" select="(
1524 ((ancestor::library/enumerator[@name=current()/@type]) or
1525 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()/@type])
1526 ) or
1527 ((ancestor::library/interface[@name=current()/@type]) or
1528 (ancestor::library/if[@target=$self_target]/interface[@name=current()/@type])
1529 ) or
1530 ((ancestor::library/collection[@name=current()/@type]) or
1531 (ancestor::library/if[@target=$self_target]/collection[@name=current()/@type])
1532 )
1533 )"/>
1534
1535 <xsl:choose>
1536 <xsl:when test="$when='pre-call'">
1537 <xsl:choose>
1538 <xsl:when test="@safearray='yes'">
1539 <!-- declare a SafeArray variable -->
1540 <xsl:choose>
1541 <!-- interface types need special treatment here -->
1542 <xsl:when test="@type='$unknown'">
1543 <xsl:text> com::SafeIfaceArray &lt;IUnknown&gt; </xsl:text>
1544 </xsl:when>
1545 <xsl:when test="$is_iface">
1546 <xsl:text> com::SafeIfaceArray &lt;</xsl:text>
1547 <xsl:value-of select="@type"/>
1548 <xsl:text>&gt; </xsl:text>
1549 </xsl:when>
1550 <xsl:otherwise>
1551 <xsl:text> com::SafeArray &lt;</xsl:text>
1552 <xsl:apply-templates select="@type" mode="com"/>
1553 <xsl:text>&gt; </xsl:text>
1554 </xsl:otherwise>
1555 </xsl:choose>
1556 <xsl:value-of select="@name"/>
1557 <xsl:text>;&#x0A;</xsl:text>
1558 <xsl:if test="(name()='attribute' and $isSetter) or
1559 (name()='param' and @dir='in')">
1560 <!-- convert QValueVector to SafeArray -->
1561 <xsl:choose>
1562 <!-- interface types need special treatment here -->
1563 <xsl:when test="@type='$unknown' or $is_iface">
1564 <xsl:text> ToSafeIfaceArray (</xsl:text>
1565 </xsl:when>
1566 <xsl:otherwise>
1567 <xsl:text> ToSafeArray (</xsl:text>
1568 </xsl:otherwise>
1569 </xsl:choose>
1570 <xsl:text>a</xsl:text>
1571 <xsl:call-template name="capitalize">
1572 <xsl:with-param name="str" select="@name"/>
1573 </xsl:call-template>
1574 <xsl:text>, </xsl:text>
1575 <xsl:value-of select="@name"/>
1576 <xsl:text>);&#x0A;</xsl:text>
1577 </xsl:if>
1578 </xsl:when>
1579 </xsl:choose>
1580 </xsl:when>
1581 <xsl:when test="$when='post-call'">
1582 <xsl:choose>
1583 <xsl:when test="@safearray='yes'">
1584 <xsl:if test="(name()='attribute' and not($isSetter)) or
1585 (name()='param' and (@dir='out' or @dir='return'))">
1586 <!-- convert SafeArray to QValueVector -->
1587 <xsl:choose>
1588 <!-- interface types need special treatment here -->
1589 <xsl:when test="@type='$unknown' or $is_iface">
1590 <xsl:text> FromSafeIfaceArray (</xsl:text>
1591 </xsl:when>
1592 <xsl:otherwise>
1593 <xsl:text> FromSafeArray (</xsl:text>
1594 </xsl:otherwise>
1595 </xsl:choose>
1596 <xsl:value-of select="@name"/>
1597 <xsl:text>, </xsl:text>
1598 <xsl:text>a</xsl:text>
1599 <xsl:call-template name="capitalize">
1600 <xsl:with-param name="str" select="@name"/>
1601 </xsl:call-template>
1602 <xsl:text>);&#x0A;</xsl:text>
1603 </xsl:if>
1604 </xsl:when>
1605 </xsl:choose>
1606 </xsl:when>
1607 <xsl:otherwise>
1608 <xsl:message terminate="yes">
1609 <xsl:text>Invalid when value: </xsl:text>
1610 <xsl:value-of select="$when"/>
1611 </xsl:message>
1612 </xsl:otherwise>
1613 </xsl:choose>
1614
1615</xsl:template>
1616
1617
1618</xsl:stylesheet>
1619
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette