VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox4/include/COMWrappers.xsl@ 10631

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

FE/Qt4: Some updates to the COM wrapper for Qt4.

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