VirtualBox

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

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

Ported r27277:27975 (array support) from branches/dmik/s2.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 63.9 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 <!-- wrapper declarations -->
236 <xsl:text>// wrapper declarations&#x0A;&#x0A;</xsl:text>
237 <xsl:apply-templates select="
238 if |
239 interface[not(@internal='yes')] |
240 collection[not(@internal='yes')] |
241 enumerator[not(@internal='yes')]
242 "
243 mode="declare"
244 />
245 <!-- wrapper definitions -->
246 <xsl:text>// wrapper definitions&#x0A;&#x0A;</xsl:text>
247 <xsl:apply-templates select="
248 if |
249 interface[not(@internal='yes')] |
250 collection[not(@internal='yes')] |
251 enumerator[not(@internal='yes')]
252 "
253 mode="define"
254 />
255</xsl:template>
256
257
258<!--
259 * interface declarations
260-->
261<xsl:template match="interface | collection | enumerator" mode="declare">
262
263 <xsl:text>// </xsl:text>
264 <xsl:value-of select="@name"/>
265 <xsl:text> wrapper&#x0A;&#x0A;class C</xsl:text>
266 <xsl:value-of select="substring(@name,2)"/>
267 <xsl:text> : public CInterface &lt;</xsl:text>
268 <xsl:value-of select="@name"/>
269 <!-- use the correct base if supportsErrorInfo -->
270 <xsl:call-template name="tryComposeFetchErrorInfo">
271 <xsl:with-param name="mode" select="'getBaseClassName'"/>
272 </xsl:call-template>
273 <xsl:text>&gt;&#x0A;{&#x0A;public:&#x0A;&#x0A;</xsl:text>
274
275 <!-- generate the Base typedef-->
276 <xsl:text> typedef CInterface &lt;</xsl:text>
277 <xsl:value-of select="@name"/>
278 <!-- Use the correct base if supportsErrorInfo -->
279 <xsl:call-template name="tryComposeFetchErrorInfo">
280 <xsl:with-param name="mode" select="'getBaseClassName'"/>
281 </xsl:call-template>
282 <xsl:text>&gt; Base;&#x0A;&#x0A;</xsl:text>
283
284 <xsl:if test="name()='collection'">
285 <xsl:text> // collection stuff&#x0A;&#x0A;</xsl:text>
286 <xsl:text> ULONG GetCount () const;&#x0A;</xsl:text>
287 <xsl:text> </xsl:text>
288 <xsl:apply-templates select="@type"/>
289 <xsl:text> GetItemAt (ULONG index) const;&#x0A;</xsl:text>
290 <xsl:text> </xsl:text>
291 <xsl:apply-templates select="@enumerator"/>
292 <xsl:text> Enumerate () const;&#x0A;&#x0A;</xsl:text>
293 </xsl:if>
294
295 <xsl:if test="name()='enumerator'">
296 <xsl:text> // enumerator stuff&#x0A;&#x0A;</xsl:text>
297 <xsl:text> BOOL HasMore () const;&#x0A;</xsl:text>
298 <xsl:text> </xsl:text>
299 <xsl:apply-templates select="@type"/>
300 <xsl:text> GetNext () const;&#x0A;&#x0A;</xsl:text>
301 <xsl:text> // friend wrappers&#x0A;&#x0A;</xsl:text>
302 <xsl:text> friend class CUnknown;&#x0A;</xsl:text>
303 <xsl:variable name="name" select="@name"/>
304 <xsl:variable name="parent" select=".."/>
305 <!-- for definitions inside <if> -->
306 <xsl:if test="name(..)='if'">
307 <xsl:for-each select="
308 preceding-sibling::collection | following-sibling::collection |
309 ../preceding-sibling::if[@target=$parent/@target]/collection |
310 ../following-sibling::if[@target=$parent/@target]/collection
311 ">
312 <xsl:if test="@enumerator=$name">
313 <xsl:text> friend class C</xsl:text>
314 <xsl:value-of select="substring(@name,2)"/>
315 <xsl:text>;&#x0A;</xsl:text>
316 </xsl:if>
317 </xsl:for-each>
318 </xsl:if>
319 <!-- for definitions outside <if> (i.e. inside <library>) -->
320 <xsl:if test="name(..)!='if'">
321 <xsl:for-each select="
322 preceding-sibling::collection | following-sibling::collection
323 ">
324 <xsl:if test="@enumerator=$name">
325 <xsl:text> friend class C</xsl:text>
326 <xsl:value-of select="substring(@name,2)"/>
327 <xsl:text>;&#x0A;</xsl:text>
328 </xsl:if>
329 </xsl:for-each>
330 </xsl:if>
331 </xsl:if>
332
333 <xsl:if test="name()='interface' or name()='collection'">
334 <xsl:call-template name="declareMembers"/>
335 </xsl:if>
336
337 <xsl:text>};&#x0A;&#x0A;</xsl:text>
338
339</xsl:template>
340
341<xsl:template name="declareMembers">
342
343 <xsl:text> // constructors and assignments taking CUnknown and </xsl:text>
344 <xsl:text>raw iface pointer&#x0A;&#x0A;</xsl:text>
345 <!-- default constructor -->
346 <xsl:text> C</xsl:text>
347 <xsl:value-of select="substring(@name,2)"/>
348 <xsl:text> () : Base () {}&#x0A;</xsl:text>
349 <!-- constructor taking CUnknown -->
350 <xsl:text> C</xsl:text>
351 <xsl:value-of select="substring(@name,2)"/>
352 <xsl:text> (const CUnknown &amp; that) : Base (that) {}&#x0A;</xsl:text>
353 <!-- constructor taking raw iface pointer -->
354 <xsl:text> C</xsl:text>
355 <xsl:value-of select="substring(@name,2)"/>
356 <xsl:text> (</xsl:text>
357 <xsl:value-of select="@name"/>
358 <xsl:text> *i) : Base (i) {}&#x0A;</xsl:text>
359 <!-- assignment taking CUnknown -->
360 <xsl:text> C</xsl:text>
361 <xsl:value-of select="substring(@name,2)"/>
362 <xsl:text> &amp; operator = (const CUnknown &amp; that)&#x0A; {&#x0A; return (C</xsl:text>
363 <xsl:value-of select="substring(@name,2)"/>
364 <xsl:text> &amp;) Base::operator = (that);&#x0A; }&#x0A;&#x0A;</xsl:text>
365
366 <xsl:text> // attributes (properties)&#x0A;&#x0A;</xsl:text>
367 <xsl:apply-templates select=".//attribute[not(@internal='yes')]" mode="declare"/>
368 <xsl:if test=".//attribute[not(@internal='yes')]">
369 <xsl:text>&#x0A;</xsl:text>
370 </xsl:if>
371
372 <xsl:text> // methods&#x0A;&#x0A;</xsl:text>
373 <xsl:apply-templates select=".//method[not(@internal='yes')]" mode="declare"/>
374 <xsl:if test=".//method[not(@internal='yes')]">
375 <xsl:text>&#x0A;</xsl:text>
376 </xsl:if>
377
378 <xsl:text> // friend wrappers&#x0A;&#x0A;</xsl:text>
379 <xsl:text> friend class CUnknown;&#x0A;</xsl:text>
380 <xsl:variable name="name" select="@name"/>
381 <xsl:variable name="parent" select=".."/>
382 <!-- for definitions inside <if> -->
383 <xsl:if test="name(..)='if'">
384 <xsl:for-each select="
385 preceding-sibling::*[self::interface or self::collection or self::enumerator] |
386 following-sibling::*[self::interface or self::collection or self::enumerator] |
387 ../preceding-sibling::*[self::interface or self::collection or self::enumerator] |
388 ../following-sibling::*[self::interface or self::collection or self::enumerator] |
389 ../preceding-sibling::if[@target=$parent/@target]/*[self::interface or self::collection or self::enumerator] |
390 ../following-sibling::if[@target=$parent/@target]/*[self::interface or self::collection or self::enumerator]
391 ">
392 <xsl:if test="
393 ((name()='interface' or name()='collection')
394 and
395 ((name(..)!='if' and (if[@target=$parent/@target]/method/param[@type=$name]
396 or
397 if[@target=$parent/@target]/attribute[@type=$name]))
398 or
399 (.//method/param[@type=$name] or attribute[@type=$name])))
400 or
401 (name(..)='if' and (name()='collection' or name()='enumerator') and @type=$name)
402 ">
403 <xsl:text> friend class C</xsl:text>
404 <xsl:value-of select="substring(@name,2)"/>
405 <xsl:text>;&#x0A;</xsl:text>
406 </xsl:if>
407 </xsl:for-each>
408 </xsl:if>
409 <!-- for definitions outside <if> (i.e. inside <library>) -->
410 <xsl:if test="name(..)!='if'">
411 <xsl:for-each select="
412 preceding-sibling::*[self::interface or self::collection or self::enumerator] |
413 following-sibling::*[self::interface or self::collection or self::enumerator] |
414 preceding-sibling::if/*[self::interface or self::collection or self::enumerator] |
415 following-sibling::if/*[self::interface or self::collection or self::enumerator]
416 ">
417 <xsl:if test="
418 ((name()='interface' or name()='collection')
419 and
420 (.//method/param[@type=$name] or attribute[@type=$name]))
421 or
422 ((name()='collection' or name()='enumerator') and @type=$name)
423 ">
424 <xsl:text> friend class C</xsl:text>
425 <xsl:value-of select="substring(@name,2)"/>
426 <xsl:text>;&#x0A;</xsl:text>
427 </xsl:if>
428 </xsl:for-each>
429 </xsl:if>
430
431</xsl:template>
432
433<!-- attribute declarations -->
434<xsl:template match="interface//attribute | collection//attribute" mode="declare">
435 <xsl:if test="@array">
436 <xsl:message terminate="yes">
437 <xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/>
438 <xsl:text>'array' attributes are not supported, use 'safearray="yes"' instead.</xsl:text>
439 </xsl:message>
440 </xsl:if>
441 <xsl:apply-templates select="parent::node()" mode="begin"/>
442 <xsl:apply-templates select="@if" mode="begin"/>
443 <xsl:call-template name="composeMethod">
444 <xsl:with-param name="return" select="."/>
445 </xsl:call-template>
446 <xsl:if test="not(@readonly='yes')">
447 <xsl:call-template name="composeMethod">
448 <xsl:with-param name="return" select="''"/>
449 </xsl:call-template>
450 </xsl:if>
451 <xsl:apply-templates select="@if" mode="end"/>
452 <xsl:apply-templates select="parent::node()" mode="end"/>
453</xsl:template>
454
455<!-- method declarations -->
456<xsl:template match="interface//method | collection//method" mode="declare">
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:apply-templates select="@if" mode="end"/>
461 <xsl:apply-templates select="parent::node()" mode="end"/>
462</xsl:template>
463
464
465<!--
466 * interface definitions
467-->
468<xsl:template match="interface | collection | enumerator" mode="define">
469
470 <xsl:text>// </xsl:text>
471 <xsl:value-of select="@name"/>
472 <xsl:text> wrapper&#x0A;&#x0A;</xsl:text>
473
474 <xsl:if test="name()='collection'">
475 <!-- GetCount -->
476 <xsl:text>inline ULONG C</xsl:text>
477 <xsl:value-of select="substring(@name,2)"/>
478 <xsl:text>::GetCount () const&#x0A;{&#x0A;</xsl:text>
479 <xsl:text> ULONG count = 0;&#x0A;</xsl:text>
480 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
481 <xsl:text> if (!mIface)&#x0A; return count;&#x0A;</xsl:text>
482 <xsl:text> mRC = mIface->COMGETTER(Count) (&amp;count);&#x0A;</xsl:text>
483 <xsl:call-template name="tryComposeFetchErrorInfo"/>
484 <xsl:text> return count;&#x0A;</xsl:text>
485 <xsl:text>}&#x0A;&#x0A;</xsl:text>
486 <!-- GetItemAt -->
487 <xsl:text>inline </xsl:text>
488 <xsl:apply-templates select="@type"/>
489 <xsl:text> C</xsl:text>
490 <xsl:value-of select="substring(@name,2)"/>
491 <xsl:text>::GetItemAt (ULONG index) const&#x0A;{&#x0A;</xsl:text>
492 <xsl:text> </xsl:text><xsl:apply-templates select="@type"/>
493 <xsl:text> item;&#x0A;</xsl:text>
494 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
495 <xsl:text> if (!mIface)&#x0A; return item;&#x0A;</xsl:text>
496 <xsl:text> mRC = mIface->GetItemAt (index, &amp;item.mIface);&#x0A;</xsl:text>
497 <xsl:call-template name="tryComposeFetchErrorInfo"/>
498 <xsl:text> return item;&#x0A;</xsl:text>
499 <xsl:text>}&#x0A;&#x0A;</xsl:text>
500 <!-- Enumerate -->
501 <xsl:text>inline </xsl:text>
502 <xsl:apply-templates select="@enumerator"/>
503 <xsl:text> C</xsl:text>
504 <xsl:value-of select="substring(@name,2)"/>
505 <xsl:text>::Enumerate () const&#x0A;{&#x0A;</xsl:text>
506 <xsl:text> </xsl:text><xsl:apply-templates select="@enumerator"/>
507 <xsl:text> enumerator;&#x0A;</xsl:text>
508 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
509 <xsl:text> if (!mIface)&#x0A; return enumerator;&#x0A;</xsl:text>
510 <xsl:text> mRC = mIface->Enumerate (&amp;enumerator.mIface);&#x0A;</xsl:text>
511 <xsl:call-template name="tryComposeFetchErrorInfo"/>
512 <xsl:text> return enumerator;&#x0A;</xsl:text>
513 <xsl:text>}&#x0A;&#x0A;</xsl:text>
514 </xsl:if>
515
516 <xsl:if test="name()='enumerator'">
517 <!-- HasMore -->
518 <xsl:text>inline BOOL C</xsl:text>
519 <xsl:value-of select="substring(@name,2)"/>
520 <xsl:text>::HasMore () const&#x0A;{&#x0A;</xsl:text>
521 <xsl:text> BOOL more = FALSE;&#x0A;</xsl:text>
522 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
523 <xsl:text> if (!mIface)&#x0A; return more;&#x0A;</xsl:text>
524 <xsl:text> mRC = mIface->HasMore (&amp;more);&#x0A;</xsl:text>
525 <xsl:call-template name="tryComposeFetchErrorInfo"/>
526 <xsl:text> return more;&#x0A;</xsl:text>
527 <xsl:text>}&#x0A;&#x0A;</xsl:text>
528 <!-- GetNext -->
529 <xsl:text>inline </xsl:text>
530 <xsl:apply-templates select="@type"/>
531 <xsl:text> C</xsl:text>
532 <xsl:value-of select="substring(@name,2)"/>
533 <xsl:text>::GetNext () const&#x0A;{&#x0A;</xsl:text>
534 <xsl:text> </xsl:text><xsl:apply-templates select="@type"/>
535 <xsl:text> next;&#x0A;</xsl:text>
536 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
537 <xsl:text> if (!mIface)&#x0A; return next;&#x0A;</xsl:text>
538 <xsl:text> mRC = mIface->GetNext (&amp;next.mIface);&#x0A;</xsl:text>
539 <xsl:call-template name="tryComposeFetchErrorInfo"/>
540 <xsl:text> return next;&#x0A;</xsl:text>
541 <xsl:text>}&#x0A;&#x0A;</xsl:text>
542 </xsl:if>
543
544 <xsl:if test="name()='interface' or name()='collection'">
545 <xsl:call-template name="defineMembers"/>
546 </xsl:if>
547
548</xsl:template>
549
550<xsl:template name="defineMembers">
551 <xsl:apply-templates select=".//attribute[not(@internal='yes')]" mode="define"/>
552 <xsl:apply-templates select=".//method[not(@internal='yes')]" mode="define"/>
553</xsl:template>
554
555<!-- attribute definitions -->
556<xsl:template match="interface//attribute | collection//attribute" mode="define">
557 <xsl:apply-templates select="parent::node()" mode="begin"/>
558 <xsl:apply-templates select="@if" mode="begin"/>
559 <xsl:call-template name="composeMethod">
560 <xsl:with-param name="return" select="."/>
561 <xsl:with-param name="define" select="'yes'"/>
562 </xsl:call-template>
563 <xsl:if test="not(@readonly='yes')">
564 <xsl:call-template name="composeMethod">
565 <xsl:with-param name="return" select="''"/>
566 <xsl:with-param name="define" select="'yes'"/>
567 </xsl:call-template>
568 </xsl:if>
569 <xsl:apply-templates select="@if" mode="end"/>
570 <xsl:apply-templates select="parent::node()" mode="end"/>
571 <xsl:text>&#x0A;</xsl:text>
572</xsl:template>
573
574<!-- method definitions -->
575<xsl:template match="interface//method | collection//method" mode="define">
576 <xsl:apply-templates select="parent::node()" mode="begin"/>
577 <xsl:apply-templates select="@if" mode="begin"/>
578 <xsl:call-template name="composeMethod">
579 <xsl:with-param name="define" select="'yes'"/>
580 </xsl:call-template>
581 <xsl:apply-templates select="@if" mode="end"/>
582 <xsl:apply-templates select="parent::node()" mode="end"/>
583 <xsl:text>&#x0A;</xsl:text>
584</xsl:template>
585
586
587<!--
588 * co-classes
589-->
590<xsl:template match="module/class"/>
591
592
593<!--
594 * enums
595-->
596<xsl:template match="enum"/>
597
598
599<!--
600 * base template to produce interface methods
601 *
602 * @param return
603 * - in <attribute> context, must be '.' for getters and
604 * '' for setters
605 * - in <method> context, must not be specified (the default value
606 * will apply)
607 * @param define
608 * 'yes' to procuce inlined definition outside the class
609 * declaration, or
610 * empty string to produce method declaration only (w/o body)
611-->
612<xsl:template name="composeMethod">
613 <xsl:param name="return" select="param[@dir='return']"/>
614 <xsl:param name="define" select="''"/>
615 <xsl:variable name="namespace" select="(ancestor::interface | ancestor::collection)[1]"/>
616 <xsl:choose>
617 <!-- no return value -->
618 <xsl:when test="not($return)">
619 <xsl:choose>
620 <xsl:when test="$define">
621 <xsl:text>inline </xsl:text>
622 </xsl:when>
623 <xsl:otherwise>
624 <xsl:text> </xsl:text>
625 </xsl:otherwise>
626 </xsl:choose>
627 <xsl:text>void </xsl:text>
628 <xsl:if test="$define">
629 <xsl:text>C</xsl:text>
630 <xsl:value-of select="substring($namespace/@name,2)"/>
631 <xsl:text>::</xsl:text>
632 </xsl:if>
633 <xsl:call-template name="composeMethodDecl">
634 <xsl:with-param name="isSetter" select="'yes'"/>
635 </xsl:call-template>
636 <xsl:if test="$define">
637 <xsl:text>&#x0A;{&#x0A;</xsl:text>
638 <!-- iface assertion -->
639 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
640 <xsl:text> if (!mIface)&#x0A; return;&#x0A;</xsl:text>
641 <!-- method call -->
642 <xsl:call-template name="composeMethodCall">
643 <xsl:with-param name="isSetter" select="'yes'"/>
644 </xsl:call-template>
645 <xsl:text>}&#x0A;</xsl:text>
646 </xsl:if>
647 <xsl:if test="not($define)">
648 <xsl:text>;&#x0A;</xsl:text>
649 </xsl:if>
650 </xsl:when>
651 <!-- has a return value -->
652 <xsl:when test="count($return) = 1">
653 <xsl:choose>
654 <xsl:when test="$define">
655 <xsl:text>inline </xsl:text>
656 </xsl:when>
657 <xsl:otherwise>
658 <xsl:text> </xsl:text>
659 </xsl:otherwise>
660 </xsl:choose>
661 <xsl:apply-templates select="$return/@type"/>
662 <xsl:text> </xsl:text>
663 <xsl:if test="$define">
664 <xsl:text>C</xsl:text>
665 <xsl:value-of select="substring($namespace/@name,2)"/>
666 <xsl:text>::</xsl:text>
667 </xsl:if>
668 <xsl:call-template name="composeMethodDecl"/>
669 <xsl:if test="$define">
670 <xsl:text>&#x0A;{&#x0A; </xsl:text>
671 <xsl:apply-templates select="$return/@type"/>
672 <xsl:text> a</xsl:text>
673 <xsl:call-template name="capitalize">
674 <xsl:with-param name="str" select="$return/@name"/>
675 </xsl:call-template>
676 <xsl:apply-templates select="$return/@type" mode="initializer"/>
677 <xsl:text>;&#x0A;</xsl:text>
678 <!-- iface assertion -->
679 <xsl:text> Assert (mIface);&#x0A;</xsl:text>
680 <xsl:text> if (!mIface)&#x0A; return a</xsl:text>
681 <xsl:call-template name="capitalize">
682 <xsl:with-param name="str" select="$return/@name"/>
683 </xsl:call-template>
684 <xsl:text>;&#x0A;</xsl:text>
685 <!-- method call -->
686 <xsl:call-template name="composeMethodCall"/>
687 <!-- return statement -->
688 <xsl:text> return a</xsl:text>
689 <xsl:call-template name="capitalize">
690 <xsl:with-param name="str" select="$return/@name"/>
691 </xsl:call-template>
692 <xsl:text>;&#x0A;}&#x0A;</xsl:text>
693 </xsl:if>
694 <xsl:if test="not($define)">
695 <xsl:text>;&#x0A;</xsl:text>
696 </xsl:if>
697 </xsl:when>
698 <!-- otherwise error -->
699 <xsl:otherwise>
700 <xsl:message terminate="yes">
701 <xsl:text>More than one return value in method: </xsl:text>
702 <xsl:value-of select="$namespace/@name"/>
703 <xsl:text>::</xsl:text>
704 <xsl:value-of select="@name"/>
705 </xsl:message>
706 </xsl:otherwise>
707 </xsl:choose>
708</xsl:template>
709
710<xsl:template name="composeMethodDecl">
711 <xsl:param name="isSetter" select="''"/>
712 <xsl:choose>
713 <!-- attribute method call -->
714 <xsl:when test="name()='attribute'">
715 <xsl:choose>
716 <xsl:when test="$isSetter">
717 <!-- name -->
718 <xsl:text>Set</xsl:text>
719 <xsl:call-template name="capitalize">
720 <xsl:with-param name="str" select="@name"/>
721 </xsl:call-template>
722 <xsl:text> (</xsl:text>
723 <!-- parameter -->
724 <xsl:apply-templates select="@type" mode="param"/>
725 <xsl:text> a</xsl:text>
726 <xsl:call-template name="capitalize">
727 <xsl:with-param name="str" select="@name"/>
728 </xsl:call-template>
729 <xsl:text>)</xsl:text>
730 </xsl:when>
731 <xsl:otherwise>
732 <!-- name -->
733 <xsl:text>Get</xsl:text>
734 <xsl:call-template name="capitalize">
735 <xsl:with-param name="str" select="@name"/>
736 </xsl:call-template>
737 <xsl:text> (</xsl:text>
738 <!-- const method -->
739 <xsl:text>) const</xsl:text>
740 </xsl:otherwise>
741 </xsl:choose>
742 </xsl:when>
743 <!-- regular method call -->
744 <xsl:when test="name()='method'">
745 <!-- name -->
746 <xsl:call-template name="capitalize">
747 <xsl:with-param name="str" select="@name"/>
748 </xsl:call-template>
749 <xsl:text> (</xsl:text>
750 <!-- parameters -->
751 <xsl:for-each select="param[@dir!='return']">
752 <xsl:apply-templates select="@type" mode="param"/>
753 <xsl:text> a</xsl:text>
754 <xsl:call-template name="capitalize">
755 <xsl:with-param name="str" select="@name"/>
756 </xsl:call-template>
757 <xsl:if test="position() != last()">
758 <xsl:text>, </xsl:text>
759 </xsl:if>
760 </xsl:for-each>
761 <xsl:text>)</xsl:text>
762 <!-- const method -->
763 <xsl:if test="@const='yes'"> const</xsl:if>
764 </xsl:when>
765 </xsl:choose>
766</xsl:template>
767
768<xsl:template name="composeMethodCall">
769 <xsl:param name="isSetter" select="''"/>
770 <!-- apply 'pre-call' hooks -->
771 <xsl:choose>
772 <xsl:when test="name()='attribute'">
773 <xsl:call-template name="hooks">
774 <xsl:with-param name="when" select="'pre-call'"/>
775 <xsl:with-param name="isSetter" select="$isSetter"/>
776 </xsl:call-template>
777 </xsl:when>
778 <xsl:when test="name()='method'">
779 <xsl:for-each select="param">
780 <xsl:call-template name="hooks">
781 <xsl:with-param name="when" select="'pre-call'"/>
782 </xsl:call-template>
783 </xsl:for-each>
784 </xsl:when>
785 </xsl:choose>
786 <!-- start the call -->
787 <xsl:text> mRC = mIface-></xsl:text>
788 <xsl:choose>
789 <!-- attribute method call -->
790 <xsl:when test="name()='attribute'">
791 <!-- method name -->
792 <xsl:choose>
793 <xsl:when test="$isSetter">
794 <xsl:text>COMSETTER(</xsl:text>
795 </xsl:when>
796 <xsl:otherwise>
797 <xsl:text>COMGETTER(</xsl:text>
798 </xsl:otherwise>
799 </xsl:choose>
800 <xsl:call-template name="capitalize">
801 <xsl:with-param name="str" select="@name"/>
802 </xsl:call-template>
803 <xsl:text>) (</xsl:text>
804 <!-- parameter -->
805 <xsl:call-template name="composeMethodCallParam">
806 <xsl:with-param name="isIn" select="$isSetter"/>
807 <xsl:with-param name="isOut" select="not($isSetter)"/>
808 </xsl:call-template>
809 </xsl:when>
810 <!-- regular method call -->
811 <xsl:when test="name()='method'">
812 <!-- method name -->
813 <xsl:call-template name="capitalize">
814 <xsl:with-param name="str" select="@name"/>
815 </xsl:call-template>
816 <xsl:text> (</xsl:text>
817 <!-- parameters -->
818 <xsl:for-each select="param">
819 <xsl:call-template name="composeMethodCallParam"/>
820 <xsl:if test="position() != last()">
821 <xsl:text>, </xsl:text>
822 </xsl:if>
823 </xsl:for-each>
824 </xsl:when>
825 </xsl:choose>
826 <xsl:text>);&#x0A;</xsl:text>
827 <!-- apply 'post-call' hooks -->
828 <xsl:choose>
829 <xsl:when test="name()='attribute'">
830 <xsl:call-template name="hooks">
831 <xsl:with-param name="when" select="'post-call'"/>
832 <xsl:with-param name="isSetter" select="$isSetter"/>
833 </xsl:call-template>
834 </xsl:when>
835 <xsl:when test="name()='method'">
836 <xsl:for-each select="param">
837 <xsl:call-template name="hooks">
838 <xsl:with-param name="when" select="'post-call'"/>
839 </xsl:call-template>
840 </xsl:for-each>
841 </xsl:when>
842 </xsl:choose>
843 <!-- -->
844 <xsl:call-template name="tryComposeFetchErrorInfo"/>
845</xsl:template>
846
847<!--
848 * Composes a 'fetch error info' call or returns the name of the
849 * appropriate base class name that provides error info functionality
850 * (depending on the mode parameter). Does nothing if the current
851 * entity (interface, collection or enumerator) does not support error info.
852 *
853 * @param mode
854 * - 'getBaseClassName': expands to the base class name
855 * - any other value: composes a 'fetch error info' method call
856-->
857<xsl:template name="tryComposeFetchErrorInfo">
858 <xsl:param name="mode" select="''"/>
859 <xsl:variable name="ifaceSupportsErrorInfo" select="
860 (ancestor-or-self::interface |
861 ancestor-or-self::collection |
862 ancestor-or-self::enumerator)[1]/@supportsErrorInfo
863 "/>
864 <xsl:variable name="librarySupportsErrorInfo" select="ancestor::library/@supportsErrorInfo"/>
865 <xsl:choose>
866 <xsl:when test="$ifaceSupportsErrorInfo">
867 <xsl:call-template name="composeFetchErrorInfo">
868 <xsl:with-param name="supports" select="string($ifaceSupportsErrorInfo)"/>
869 <xsl:with-param name="mode" select="$mode"/>
870 </xsl:call-template>
871 </xsl:when>
872 <xsl:when test="$librarySupportsErrorInfo">
873 <xsl:call-template name="composeFetchErrorInfo">
874 <xsl:with-param name="supports" select="string($librarySupportsErrorInfo)"/>
875 <xsl:with-param name="mode" select="$mode"/>
876 </xsl:call-template>
877 </xsl:when>
878 </xsl:choose>
879</xsl:template>
880
881<xsl:template name="composeFetchErrorInfo">
882 <xsl:param name="supports" select="''"/>
883 <xsl:param name="mode" select="''"/>
884 <xsl:choose>
885 <xsl:when test="$mode='getBaseClassName'">
886 <xsl:if test="$supports='strict' or $supports='yes'">
887 <xsl:text>, COMBaseWithEI</xsl:text>
888 </xsl:if>
889 </xsl:when>
890 <xsl:otherwise>
891 <xsl:if test="$supports='strict' or $supports='yes'">
892 <xsl:text> if (FAILED (mRC))&#x0A; {&#x0A;</xsl:text>
893 <xsl:text> fetchErrorInfo (mIface, &amp;COM_IIDOF (Base::Iface));&#x0A;</xsl:text>
894 <xsl:if test="$supports='strict'">
895 <xsl:text> AssertMsg (errInfo.isFullAvailable(), </xsl:text>
896 <xsl:text>("for RC=0x%08X\n", mRC));&#x0A;</xsl:text>
897 </xsl:if>
898 <xsl:text> }&#x0A;</xsl:text>
899 </xsl:if>
900 </xsl:otherwise>
901 </xsl:choose>
902</xsl:template>
903
904<xsl:template name="composeMethodCallParam">
905
906 <xsl:param name="isIn" select="@dir='in'"/>
907 <xsl:param name="isOut" select="@dir='out' or @dir='return'"/>
908
909 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
910
911 <xsl:choose>
912 <!-- safearrays -->
913 <xsl:when test="@safearray='yes'">
914 <xsl:choose>
915 <xsl:when test="$isIn">
916 <xsl:text>ComSafeArrayAsInParam (</xsl:text>
917 <xsl:value-of select="@name"/>
918 <xsl:text>)</xsl:text>
919 </xsl:when>
920 <xsl:when test="$isOut">
921 <xsl:text>ComSafeArrayAsOutParam (</xsl:text>
922 <xsl:value-of select="@name"/>
923 <xsl:text>)</xsl:text>
924 </xsl:when>
925 </xsl:choose>
926 </xsl:when>
927 <!-- string types -->
928 <xsl:when test="@type = 'wstring'">
929 <xsl:choose>
930 <xsl:when test="$isIn">
931 <xsl:text>BSTRIn (a</xsl:text>
932 <xsl:call-template name="capitalize">
933 <xsl:with-param name="str" select="@name"/>
934 </xsl:call-template>
935 <xsl:text>)</xsl:text>
936 </xsl:when>
937 <xsl:when test="$isOut">
938 <xsl:text>BSTROut (a</xsl:text>
939 <xsl:call-template name="capitalize">
940 <xsl:with-param name="str" select="@name"/>
941 </xsl:call-template>
942 <xsl:text>)</xsl:text>
943 </xsl:when>
944 </xsl:choose>
945 </xsl:when>
946 <!-- uuid type -->
947 <xsl:when test="@type = 'uuid'">
948 <xsl:choose>
949 <xsl:when test="$isIn">
950 <xsl:text>GUIDIn (a</xsl:text>
951 <xsl:call-template name="capitalize">
952 <xsl:with-param name="str" select="@name"/>
953 </xsl:call-template>
954 <xsl:text>)</xsl:text>
955 </xsl:when>
956 <xsl:when test="$isOut">
957 <xsl:text>GUIDOut (a</xsl:text>
958 <xsl:call-template name="capitalize">
959 <xsl:with-param name="str" select="@name"/>
960 </xsl:call-template>
961 <xsl:text>)</xsl:text>
962 </xsl:when>
963 </xsl:choose>
964 </xsl:when>
965 <!-- enum types -->
966 <xsl:when test="
967 (ancestor::library/enum[@name=current()/@type]) or
968 (ancestor::library/if[@target=$self_target]/enum[@name=current()/@type])
969 ">
970 <xsl:choose>
971 <xsl:when test="$isIn">
972 <xsl:text>(</xsl:text>
973 <xsl:value-of select="@type"/>
974 <xsl:text>_T) a</xsl:text>
975 <xsl:call-template name="capitalize">
976 <xsl:with-param name="str" select="@name"/>
977 </xsl:call-template>
978 </xsl:when>
979 <xsl:when test="$isOut">
980 <xsl:text>ENUMOut &lt;CEnums::</xsl:text>
981 <xsl:value-of select="@type"/>
982 <xsl:text>, </xsl:text>
983 <xsl:value-of select="@type"/>
984 <xsl:text>_T&gt; (a</xsl:text>
985 <xsl:call-template name="capitalize">
986 <xsl:with-param name="str" select="@name"/>
987 </xsl:call-template>
988 <xsl:text>)</xsl:text>
989 </xsl:when>
990 </xsl:choose>
991 </xsl:when>
992 <!-- interface types -->
993 <xsl:when test="
994 @type='$unknown' or
995 ((ancestor::library/enumerator[@name=current()/@type]) or
996 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()/@type])
997 ) or
998 ((ancestor::library/interface[@name=current()/@type]) or
999 (ancestor::library/if[@target=$self_target]/interface[@name=current()/@type])
1000 ) or
1001 ((ancestor::library/collection[@name=current()/@type]) or
1002 (ancestor::library/if[@target=$self_target]/collection[@name=current()/@type])
1003 )
1004 ">
1005 <xsl:choose>
1006 <xsl:when test="$isIn">
1007 <xsl:text>a</xsl:text>
1008 <xsl:call-template name="capitalize">
1009 <xsl:with-param name="str" select="@name"/>
1010 </xsl:call-template>
1011 <xsl:choose>
1012 <xsl:when test="@type='$unknown'">
1013 <xsl:text>.iface()</xsl:text>
1014 </xsl:when>
1015 <xsl:otherwise>
1016 <xsl:text>.mIface</xsl:text>
1017 </xsl:otherwise>
1018 </xsl:choose>
1019 </xsl:when>
1020 <xsl:when test="$isOut">
1021 <xsl:text>&amp;a</xsl:text>
1022 <xsl:call-template name="capitalize">
1023 <xsl:with-param name="str" select="@name"/>
1024 </xsl:call-template>
1025 <xsl:choose>
1026 <xsl:when test="@type='$unknown'">
1027 <xsl:text>.ifaceRef()</xsl:text>
1028 </xsl:when>
1029 <xsl:otherwise>
1030 <xsl:text>.mIface</xsl:text>
1031 </xsl:otherwise>
1032 </xsl:choose>
1033 </xsl:when>
1034 </xsl:choose>
1035 </xsl:when>
1036 <!-- currently unsupported types -->
1037 <xsl:when test="@type = 'string'">
1038 <xsl:message terminate="yes">
1039 <xsl:text>Parameter type </xsl:text>
1040 <xsl:value-of select="@type"/>
1041 <xsl:text>is not currently supported</xsl:text>
1042 </xsl:message>
1043 </xsl:when>
1044 <!-- assuming scalar types -->
1045 <xsl:otherwise>
1046 <xsl:choose>
1047 <xsl:when test="$isIn">
1048 <xsl:text>a</xsl:text>
1049 <xsl:call-template name="capitalize">
1050 <xsl:with-param name="str" select="@name"/>
1051 </xsl:call-template>
1052 </xsl:when>
1053 <xsl:when test="$isOut">
1054 <xsl:text>&amp;a</xsl:text>
1055 <xsl:call-template name="capitalize">
1056 <xsl:with-param name="str" select="@name"/>
1057 </xsl:call-template>
1058 </xsl:when>
1059 </xsl:choose>
1060 </xsl:otherwise>
1061 </xsl:choose>
1062</xsl:template>
1063
1064
1065<!--
1066 * attribute/parameter type conversion (returns plain Qt type name)
1067-->
1068<xsl:template match="
1069 attribute/@type | param/@type |
1070 enumerator/@type | collection/@type | collection/@enumerator
1071">
1072 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1073
1074 <xsl:if test="../@array and ../@safearray='yes'">
1075 <xsl:message terminate="yes">
1076 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1077 <xsl:text>either 'array' or 'safearray="yes"' attribute is allowed, but not both!</xsl:text>
1078 </xsl:message>
1079 </xsl:if>
1080
1081 <xsl:if test="../@array and ((name(..)='param' and ../@dir='return') or (name(..)='attribute'))">
1082 <xsl:message terminate="yes">
1083 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1084 <xsl:text>return 'array' parameters and 'array' attributes are not supported, use 'safearray="yes"' instead.</xsl:text>
1085 </xsl:message>
1086 </xsl:if>
1087
1088 <xsl:choose>
1089 <!-- modifiers (ignored for 'enumeration' attributes)-->
1090 <xsl:when test="name(current())='type' and ../@mod">
1091 <xsl:if test="../@safearray">
1092 <xsl:message terminate="yes">
1093 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1094 <xsl:text>either 'safearray' or 'mod' attribute is allowed, but not both!</xsl:text>
1095 </xsl:message>
1096 </xsl:if>
1097 <xsl:if test="../@array">
1098 <xsl:message terminate="yes">
1099 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1100 <xsl:text>either 'array' or 'mod' attribute is allowed, but not both!</xsl:text>
1101 </xsl:message>
1102 </xsl:if>
1103 <xsl:choose>
1104 <xsl:when test="../@mod='ptr'">
1105 <xsl:choose>
1106 <!-- standard types -->
1107 <!--xsl:when test=".='result'">??</xsl:when-->
1108 <xsl:when test=".='boolean'">BOOL *</xsl:when>
1109 <xsl:when test=".='octet'">BYTE *</xsl:when>
1110 <xsl:when test=".='short'">SHORT *</xsl:when>
1111 <xsl:when test=".='unsigned short'">USHORT *</xsl:when>
1112 <xsl:when test=".='long'">LONG *</xsl:when>
1113 <xsl:when test=".='long long'">LONG64 *</xsl:when>
1114 <xsl:when test=".='unsigned long'">ULONG *</xsl:when>
1115 <xsl:when test=".='unsigned long long'">ULONG64 *</xsl:when>
1116 <xsl:when test=".='char'">CHAR *</xsl:when>
1117 <!--<xsl:when test=".='string'">??</xsl:when-->
1118 <xsl:when test=".='wchar'">OLECHAR *</xsl:when>
1119 <!--<xsl:when test=".='wstring'">??</xsl:when-->
1120 <xsl:otherwise>
1121 <xsl:message terminate="yes">
1122 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1123 <xsl:text>attribute 'mod=</xsl:text>
1124 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
1125 <xsl:text>' cannot be used with type </xsl:text>
1126 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
1127 </xsl:message>
1128 </xsl:otherwise>
1129 </xsl:choose>
1130 </xsl:when>
1131 <xsl:otherwise>
1132 <xsl:message terminate="yes">
1133 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1134 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
1135 <xsl:text>of attribute 'mod' is invalid!</xsl:text>
1136 </xsl:message>
1137 </xsl:otherwise>
1138 </xsl:choose>
1139 </xsl:when>
1140 <!-- no modifiers -->
1141 <xsl:otherwise>
1142 <xsl:if test="../@safearray">
1143 <xsl:text>QValueVector &lt;</xsl:text>
1144 </xsl:if>
1145 <xsl:choose>
1146 <!-- standard types -->
1147 <xsl:when test=".='result'">HRESULT</xsl:when>
1148 <xsl:when test=".='boolean'">BOOL</xsl:when>
1149 <xsl:when test=".='octet'">BYTE</xsl:when>
1150 <xsl:when test=".='short'">SHORT</xsl:when>
1151 <xsl:when test=".='unsigned short'">USHORT</xsl:when>
1152 <xsl:when test=".='long'">LONG</xsl:when>
1153 <xsl:when test=".='long long'">LONG64</xsl:when>
1154 <xsl:when test=".='unsigned long'">ULONG</xsl:when>
1155 <xsl:when test=".='unsigned long long'">ULONG64</xsl:when>
1156 <xsl:when test=".='char'">CHAR</xsl:when>
1157 <xsl:when test=".='string'">CHAR *</xsl:when>
1158 <xsl:when test=".='wchar'">OLECHAR</xsl:when>
1159 <xsl:when test=".='wstring'">QString</xsl:when>
1160 <!-- UUID type -->
1161 <xsl:when test=".='uuid'">QUuid</xsl:when>
1162 <!-- system interface types -->
1163 <xsl:when test=".='$unknown'">CUnknown</xsl:when>
1164 <xsl:otherwise>
1165 <xsl:choose>
1166 <!-- enum types -->
1167 <xsl:when test="
1168 (ancestor::library/enum[@name=current()]) or
1169 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
1170 ">
1171 <xsl:value-of select="concat('CEnums::',string(.))"/>
1172 </xsl:when>
1173 <!-- custom interface types -->
1174 <xsl:when test="
1175 (name(current())='enumerator' and
1176 ((ancestor::library/enumerator[@name=current()]) or
1177 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()]))
1178 ) or
1179 ((ancestor::library/interface[@name=current()]) or
1180 (ancestor::library/if[@target=$self_target]/interface[@name=current()])
1181 ) or
1182 ((ancestor::library/collection[@name=current()]) or
1183 (ancestor::library/if[@target=$self_target]/collection[@name=current()])
1184 )
1185 ">
1186 <xsl:value-of select="concat('C',substring(.,2))"/>
1187 </xsl:when>
1188 <!-- other types -->
1189 <xsl:otherwise>
1190 <xsl:message terminate="yes">
1191 <xsl:text>Unknown parameter type: </xsl:text>
1192 <xsl:value-of select="."/>
1193 </xsl:message>
1194 </xsl:otherwise>
1195 </xsl:choose>
1196 </xsl:otherwise>
1197 </xsl:choose>
1198 <xsl:if test="../@safearray">
1199 <xsl:text>&gt;</xsl:text>
1200 </xsl:if>
1201 </xsl:otherwise>
1202 </xsl:choose>
1203</xsl:template>
1204
1205
1206<!--
1207 * generates a null initializer for all scalar types (such as bool or long)
1208 * and enum types in the form of ' = <null_initializer>', or nothing for other
1209 * types.
1210-->
1211<xsl:template match="
1212 attribute/@type | param/@type |
1213 enumerator/@type | collection/@type | collection/@enumerator
1214" mode="initializer">
1215
1216 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1217
1218 <xsl:choose>
1219 <!-- safearrays don't need initializers -->
1220 <xsl:when test="../@safearray">
1221 </xsl:when>
1222 <!-- modifiers (ignored for 'enumeration' attributes)-->
1223 <xsl:when test="name(current())='type' and ../@mod">
1224 <xsl:choose>
1225 <xsl:when test="../@mod='ptr'">
1226 <xsl:choose>
1227 <!-- standard types -->
1228 <!--xsl:when test=".='result'">??</xsl:when-->
1229 <xsl:when test=".='boolean'"> = NULL</xsl:when>
1230 <xsl:when test=".='octet'"> = NULL</xsl:when>
1231 <xsl:when test=".='short'"> = NULL</xsl:when>
1232 <xsl:when test=".='unsigned short'"> = NULL</xsl:when>
1233 <xsl:when test=".='long'"> = NULL</xsl:when>
1234 <xsl:when test=".='long long'"> = NULL</xsl:when>
1235 <xsl:when test=".='unsigned long'"> = NULL</xsl:when>
1236 <xsl:when test=".='unsigned long long'"> = NULL</xsl:when>
1237 <xsl:when test=".='char'"> = NULL</xsl:when>
1238 <!--<xsl:when test=".='string'">??</xsl:when-->
1239 <xsl:when test=".='wchar'"> = NULL</xsl:when>
1240 <!--<xsl:when test=".='wstring'">??</xsl:when-->
1241 <xsl:otherwise>
1242 <xsl:message terminate="yes">
1243 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1244 <xsl:text>attribute 'mod=</xsl:text>
1245 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
1246 <xsl:text>' cannot be used with type </xsl:text>
1247 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
1248 </xsl:message>
1249 </xsl:otherwise>
1250 </xsl:choose>
1251 </xsl:when>
1252 <xsl:otherwise>
1253 <xsl:message terminate="yes">
1254 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1255 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
1256 <xsl:text>of attribute 'mod' is invalid!</xsl:text>
1257 </xsl:message>
1258 </xsl:otherwise>
1259 </xsl:choose>
1260 </xsl:when>
1261 <!-- no modifiers -->
1262 <xsl:otherwise>
1263 <xsl:choose>
1264 <!-- standard types that need a zero initializer -->
1265 <xsl:when test=".='result'"> = S_OK</xsl:when>
1266 <xsl:when test=".='boolean'"> = FALSE</xsl:when>
1267 <xsl:when test=".='octet'"> = 0</xsl:when>
1268 <xsl:when test=".='short'"> = 0</xsl:when>
1269 <xsl:when test=".='unsigned short'"> = 0</xsl:when>
1270 <xsl:when test=".='long'"> = 0</xsl:when>
1271 <xsl:when test=".='long long'"> = 0</xsl:when>
1272 <xsl:when test=".='unsigned long'"> = 0</xsl:when>
1273 <xsl:when test=".='unsigned long long'"> = 0</xsl:when>
1274 <xsl:when test=".='char'"> = 0</xsl:when>
1275 <xsl:when test=".='string'"> = NULL</xsl:when>
1276 <xsl:when test=".='wchar'"> = 0</xsl:when>
1277 <xsl:otherwise>
1278 <xsl:choose>
1279 <!-- enum types initialized with 0 -->
1280 <xsl:when test="
1281 (ancestor::library/enum[@name=current()]) or
1282 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
1283 ">
1284 <xsl:value-of select="concat(' = (CEnums::',string(.),') 0')"/>
1285 </xsl:when>
1286 </xsl:choose>
1287 </xsl:otherwise>
1288 </xsl:choose>
1289 </xsl:otherwise>
1290 </xsl:choose>
1291</xsl:template>
1292
1293
1294<!--
1295 * attribute/parameter type conversion (for method declaration)
1296-->
1297<xsl:template match="attribute/@type | param/@type" mode="param">
1298
1299 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1300
1301 <xsl:choose>
1302 <!-- class types -->
1303 <xsl:when test="
1304 .='string' or
1305 .='wstring' or
1306 ../@safearray='yes' or
1307 ((ancestor::library/enum[@name=current()]) or
1308 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
1309 ) or
1310 .='$unknown' or
1311 ((ancestor::library/enumerator[@name=current()]) or
1312 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()])
1313 ) or
1314 ((ancestor::library/interface[@name=current()]) or
1315 (ancestor::library/if[@target=$self_target]/interface[@name=current()])
1316 ) or
1317 ((ancestor::library/collection[@name=current()]) or
1318 (ancestor::library/if[@target=$self_target]/collection[@name=current()])
1319 )
1320 ">
1321 <xsl:choose>
1322 <!-- <attribute> context -->
1323 <xsl:when test="name(..)='attribute'">
1324 <xsl:text>const </xsl:text>
1325 <xsl:apply-templates select="."/>
1326 <xsl:text> &amp;</xsl:text>
1327 </xsl:when>
1328 <!-- <param> context -->
1329 <xsl:when test="name(..)='param'">
1330 <xsl:choose>
1331 <xsl:when test="../@dir='in'">
1332 <xsl:text>const </xsl:text>
1333 <xsl:apply-templates select="."/>
1334 <xsl:text> &amp;</xsl:text>
1335 </xsl:when>
1336 <xsl:when test="../@dir='out'">
1337 <xsl:apply-templates select="."/>
1338 <xsl:text> &amp;</xsl:text>
1339 </xsl:when>
1340 <xsl:when test="../@dir='return'">
1341 <xsl:apply-templates select="."/>
1342 </xsl:when>
1343 </xsl:choose>
1344 </xsl:when>
1345 </xsl:choose>
1346 </xsl:when>
1347 <!-- assume scalar types -->
1348 <xsl:otherwise>
1349 <xsl:choose>
1350 <!-- <attribute> context -->
1351 <xsl:when test="name(..)='attribute'">
1352 <xsl:apply-templates select="."/>
1353 </xsl:when>
1354 <!-- <param> context -->
1355 <xsl:when test="name(..)='param'">
1356 <xsl:choose>
1357 <xsl:when test="../@array">
1358 <xsl:apply-templates select="."/>
1359 <xsl:text> *</xsl:text>
1360 <xsl:if test="../@dir='out'">
1361 <xsl:text> &amp;</xsl:text>
1362 </xsl:if>
1363 </xsl:when>
1364 <xsl:otherwise>
1365 <xsl:apply-templates select="."/>
1366 <xsl:if test="../@dir='out'">
1367 <xsl:text> &amp;</xsl:text>
1368 </xsl:if>
1369 </xsl:otherwise>
1370 </xsl:choose>
1371 </xsl:when>
1372 </xsl:choose>
1373 </xsl:otherwise>
1374 </xsl:choose>
1375</xsl:template>
1376
1377
1378<!--
1379 * attribute/parameter type conversion (returns plain COM type name)
1380 * (basically, copied from midl.xsl)
1381-->
1382<xsl:template match="
1383 attribute/@type | param/@type |
1384 enumerator/@type | collection/@type | collection/@enumerator
1385" mode="com">
1386
1387 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
1388
1389 <xsl:choose>
1390 <!-- modifiers (ignored for 'enumeration' attributes)-->
1391 <xsl:when test="name(current())='type' and ../@mod">
1392 <xsl:choose>
1393 <xsl:when test="../@mod='ptr'">
1394 <xsl:choose>
1395 <!-- standard types -->
1396 <!--xsl:when test=".='result'">??</xsl:when-->
1397 <xsl:when test=".='boolean'">BOOL *</xsl:when>
1398 <xsl:when test=".='octet'">BYTE *</xsl:when>
1399 <xsl:when test=".='short'">SHORT *</xsl:when>
1400 <xsl:when test=".='unsigned short'">USHORT *</xsl:when>
1401 <xsl:when test=".='long'">LONG *</xsl:when>
1402 <xsl:when test=".='long long'">LONG64 *</xsl:when>
1403 <xsl:when test=".='unsigned long'">ULONG *</xsl:when>
1404 <xsl:when test=".='unsigned long long'">ULONG64 *</xsl:when>
1405 <xsl:when test=".='char'">CHAR *</xsl:when>
1406 <!--xsl:when test=".='string'">??</xsl:when-->
1407 <xsl:when test=".='wchar'">OLECHAR *</xsl:when>
1408 <!--xsl:when test=".='wstring'">??</xsl:when-->
1409 <xsl:otherwise>
1410 <xsl:message terminate="yes">
1411 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1412 <xsl:text>attribute 'mod=</xsl:text>
1413 <xsl:value-of select="concat('&quot;',../@mod,'&quot;')"/>
1414 <xsl:text>' cannot be used with type </xsl:text>
1415 <xsl:value-of select="concat('&quot;',current(),'&quot;!')"/>
1416 </xsl:message>
1417 </xsl:otherwise>
1418 </xsl:choose>
1419 </xsl:when>
1420 <xsl:otherwise>
1421 <xsl:message terminate="yes">
1422 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
1423 <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
1424 <xsl:text>of attribute 'mod' is invalid!</xsl:text>
1425 </xsl:message>
1426 </xsl:otherwise>
1427 </xsl:choose>
1428 </xsl:when>
1429 <!-- no modifiers -->
1430 <xsl:otherwise>
1431 <xsl:choose>
1432 <!-- standard types -->
1433 <xsl:when test=".='result'">HRESULT</xsl:when>
1434 <xsl:when test=".='boolean'">BOOL</xsl:when>
1435 <xsl:when test=".='octet'">BYTE</xsl:when>
1436 <xsl:when test=".='short'">SHORT</xsl:when>
1437 <xsl:when test=".='unsigned short'">USHORT</xsl:when>
1438 <xsl:when test=".='long'">LONG</xsl:when>
1439 <xsl:when test=".='long long'">LONG64</xsl:when>
1440 <xsl:when test=".='unsigned long'">ULONG</xsl:when>
1441 <xsl:when test=".='unsigned long long'">ULONG64</xsl:when>
1442 <xsl:when test=".='char'">CHAR</xsl:when>
1443 <xsl:when test=".='string'">CHAR *</xsl:when>
1444 <xsl:when test=".='wchar'">OLECHAR</xsl:when>
1445 <xsl:when test=".='wstring'">BSTR</xsl:when>
1446 <!-- UUID type -->
1447 <xsl:when test=".='uuid'">GUID</xsl:when>
1448 <!-- system interface types -->
1449 <xsl:when test=".='$unknown'">IUnknown *</xsl:when>
1450 <xsl:otherwise>
1451 <xsl:choose>
1452 <!-- enum types -->
1453 <xsl:when test="
1454 (ancestor::library/enum[@name=current()]) or
1455 (ancestor::library/if[@target=$self_target]/enum[@name=current()])
1456 ">
1457 <xsl:value-of select="."/>
1458 </xsl:when>
1459 <!-- custom interface types -->
1460 <xsl:when test="
1461 (name(current())='enumerator' and
1462 ((ancestor::library/enumerator[@name=current()]) or
1463 (ancestor::library/if[@target=$self_target]/enumerator[@name=current()]))
1464 ) or
1465 ((ancestor::library/interface[@name=current()]) or
1466 (ancestor::library/if[@target=$self_target]/interface[@name=current()])
1467 ) or
1468 ((ancestor::library/collection[@name=current()]) or
1469 (ancestor::library/if[@target=$self_target]/collection[@name=current()])
1470 )
1471 ">
1472 <xsl:value-of select="."/><xsl:text> *</xsl:text>
1473 </xsl:when>
1474 <!-- other types -->
1475 <xsl:otherwise>
1476 <xsl:message terminate="yes">
1477 <xsl:text>Unknown parameter type: </xsl:text>
1478 <xsl:value-of select="."/>
1479 </xsl:message>
1480 </xsl:otherwise>
1481 </xsl:choose>
1482 </xsl:otherwise>
1483 </xsl:choose>
1484 </xsl:otherwise>
1485 </xsl:choose>
1486</xsl:template>
1487
1488
1489<!--
1490 * attribute/parameter type additional hooks.
1491 *
1492 * Called in the context of <attribute> or <param> elements.
1493 *
1494 * @param when When the hook is being called:
1495 * 'pre-call' - right before the method call
1496 * 'post-call' - right after the method call
1497 * @param isSetter Non-empty if called in the cotext of the attribute setter
1498 * call.
1499-->
1500<xsl:template name="hooks">
1501
1502 <xsl:param name="when" select="''"/>
1503 <xsl:param name="isSetter" select="''"/>
1504
1505 <xsl:choose>
1506 <xsl:when test="$when='pre-call'">
1507 <xsl:choose>
1508 <xsl:when test="@safearray='yes'">
1509 <!-- declare a SafeArray variable -->
1510 <xsl:text> com::SafeArray &lt;</xsl:text>
1511 <xsl:apply-templates select="@type" mode="com"/>
1512 <xsl:text>&gt; </xsl:text>
1513 <xsl:value-of select="@name"/>
1514 <xsl:text>;&#x0A;</xsl:text>
1515 <xsl:if test="(name()='attribute' and $isSetter) or
1516 (name()='param' and @dir='in')">
1517 <!-- convert QValueVector to SafeArray -->
1518 <xsl:text> ToSafeArray (</xsl:text>
1519 <xsl:text>a</xsl:text>
1520 <xsl:call-template name="capitalize">
1521 <xsl:with-param name="str" select="@name"/>
1522 </xsl:call-template>
1523 <xsl:text>, </xsl:text>
1524 <xsl:value-of select="@name"/>
1525 <xsl:text>);&#x0A;</xsl:text>
1526 </xsl:if>
1527 </xsl:when>
1528 </xsl:choose>
1529 </xsl:when>
1530 <xsl:when test="$when='post-call'">
1531 <xsl:choose>
1532 <xsl:when test="@safearray='yes'">
1533 <xsl:if test="(name()='attribute' and not($isSetter)) or
1534 (name()='param' and (@dir='out' or @dir='return'))">
1535 <!-- convert SafeArray to QValueVector -->
1536 <xsl:text> FromSafeArray (</xsl:text>
1537 <xsl:value-of select="@name"/>
1538 <xsl:text>, </xsl:text>
1539 <xsl:text>a</xsl:text>
1540 <xsl:call-template name="capitalize">
1541 <xsl:with-param name="str" select="@name"/>
1542 </xsl:call-template>
1543 <xsl:text>);&#x0A;</xsl:text>
1544 </xsl:if>
1545 </xsl:when>
1546 </xsl:choose>
1547 </xsl:when>
1548 <xsl:otherwise>
1549 <xsl:message terminate="yes">
1550 <xsl:text>Invalid when value: </xsl:text>
1551 <xsl:value-of select="$when"/>
1552 </xsl:message>
1553 </xsl:otherwise>
1554 </xsl:choose>
1555
1556</xsl:template>
1557
1558
1559</xsl:stylesheet>
1560
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