VirtualBox

Ignore:
Timestamp:
Feb 7, 2008 4:02:11 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27977
Message:

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

Location:
trunk/src/VBox/Frontends/VirtualBox/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/COMDefs.h

    r5999 r6851  
    2424#define __COMDefs_h__
    2525
     26/** @defgroup   grp_QT_COM  Qt-COM Support Layer
     27 * @{
     28 *
     29 * The Qt-COM support layer provides a set of defintions and smart classes for
     30 * writing simple, clean and platform-independent code to access COM/XPCOM
     31 * components through exposed COM interfaces. This layer is based on the
     32 * COM/XPCOM Abstarction Layer library (the VBoxCOM glue library defined in
     33 * include/VBox/com and implemented in src/VBox/Main/glue).
     34 *
     35 * ...
     36 *
     37 * @defgroup   grp_QT_COM_arrays    Arrays
     38 * @{
     39 *
     40 * COM/XPCOM arrays are mapped to QValueVector objects. QValueVector templates
     41 * declared with a type that corresponds to the COM type of elements in the
     42 * array using normal Qt-COM type mapping rules. Here is a code example that
     43 * demonstrates how to call interface methods that take and return arrays (this
     44 * example is based on examples given in @ref grp_COM_arrays):
     45 * @code
     46
     47    CSomething component;
     48
     49    // ...
     50
     51    QValueVector <LONG> in (3);
     52    in [0] = -1;
     53    in [1] = -2;
     54    in [2] = -3;
     55
     56    QValueVector <LONG> out;
     57    QValueVector <LONG> ret;
     58
     59    ret = component.TestArrays (in, out);
     60
     61    for (size_t i = 0; i < ret.size(); ++ i)
     62        LogFlow (("*** ret[%u]=%d\n", i, ret [i]));
     63
     64 * @endcode
     65 * @}
     66 */
    2667
    2768/* Both VBox/com/assert.h and qglobal.h contain a definition of ASSERT.
     
    3071
    3172#include <VBox/com/com.h>
     73#include <VBox/com/array.h>
    3274#include <VBox/com/assert.h>
    3375
     
    3779#include <qstring.h>
    3880#include <quuid.h>
     81#include <qvaluevector.h>
    3982
    4083#include <iprt/memory> // for auto_copy_ptr
     
    139182public:
    140183
    141     static HRESULT initializeCOM();
    142     static HRESULT cleanupCOM();
    143 
    144 #if !defined (VBOX_WITH_XPCOM)
    145 
    146     /** Converts a GUID value to QUuid */
    147     static QUuid toQUuid (const GUID &id)
    148     {
    149         return QUuid (id.Data1, id.Data2, id.Data3,
    150                       id.Data4[0], id.Data4[1], id.Data4[2], id.Data4[3],
    151                       id.Data4[4], id.Data4[5], id.Data4[6], id.Data4[7]);
    152     }
    153 
    154 #else /* !defined (VBOX_WITH_XPCOM) */
    155 
    156     /** Converts a GUID value to QUuid */
    157     static QUuid toQUuid (const nsID &id)
    158     {
    159         return QUuid (id.m0, id.m1, id.m2,
    160                       id.m3[0], id.m3[1], id.m3[2], id.m3[3],
    161                       id.m3[4], id.m3[5], id.m3[6], id.m3[7]);
    162     }
    163 
    164 #endif /* !defined (VBOX_WITH_XPCOM) */
     184    static HRESULT InitializeCOM();
     185    static HRESULT CleanupCOM();
    165186
    166187    /**
     
    178199    virtual COMErrorInfo errorInfo() const { return COMErrorInfo(); }
    179200
     201#if !defined (VBOX_WITH_XPCOM)
     202
     203    /** Converts a GUID value to QUuid */
     204    static QUuid ToQUuid (const GUID &id)
     205    {
     206        return QUuid (id.Data1, id.Data2, id.Data3,
     207                      id.Data4[0], id.Data4[1], id.Data4[2], id.Data4[3],
     208                      id.Data4[4], id.Data4[5], id.Data4[6], id.Data4[7]);
     209    }
     210
     211#else /* !defined (VBOX_WITH_XPCOM) */
     212
     213    /** Converts a GUID value to QUuid */
     214    static QUuid ToQUuid (const nsID &id)
     215    {
     216        return QUuid (id.m0, id.m1, id.m2,
     217                      id.m3[0], id.m3[1], id.m3[2], id.m3[3],
     218                      id.m3[4], id.m3[5], id.m3[6], id.m3[7]);
     219    }
     220
     221#endif /* !defined (VBOX_WITH_XPCOM) */
     222
     223    /* Arrays of arbitrary types */
     224
     225    template <typename QT, typename CT>
     226    static void ToSafeArray (const QValueVector <QT> &aVec, com::SafeArray <CT> &aArr)
     227    {
     228        AssertMsgFailedReturnVoid (("No conversion!\n"));
     229    }
     230
     231    template <typename CT, typename QT>
     232    static void FromSafeArray (const com::SafeArray <CT> &aArr, QValueVector <QT> &aVec)
     233    {
     234        AssertMsgFailedReturnVoid (("No conversion!\n"));
     235    }
     236
     237    template <typename QT, typename CT>
     238    static void ToSafeArray (const QValueVector <QT *> &aVec, com::SafeArray <CT *> &aArr)
     239    {
     240        AssertMsgFailedReturnVoid (("No conversion!\n"));
     241    }
     242
     243    template <typename CT, typename QT>
     244    static void FromSafeArray (const com::SafeArray <CT *> &aArr, QValueVector <QT *> &aVec)
     245    {
     246        AssertMsgFailedReturnVoid (("No conversion!\n"));
     247    }
     248
     249    /* Arrays of equal types */
     250
     251    template <typename T>
     252    static void ToSafeArray (const QValueVector <T> &aVec, com::SafeArray <T> &aArr)
     253    {
     254        aArr.reset (aVec.size());
     255        size_t i = 0;
     256        for (typename QValueVector <T>::const_iterator it = aVec.begin();
     257             it != aVec.end(); ++ it, ++ i)
     258            aArr [i] = *it;
     259    }
     260
     261    template <typename T>
     262    static void FromSafeArray (const com::SafeArray <T> &aArr, QValueVector <T> &aVec)
     263    {
     264        aVec = QValueVector <T> (aArr.size());
     265        size_t i = 0;
     266        for (typename QValueVector <T>::iterator it = aVec.begin();
     267             it != aVec.end(); ++ it, ++ i)
     268            *it = aArr [i];
     269    }
     270
     271    /* Arrays of interface pointers */
     272
     273    template <class CI, class I>
     274    static void ToSafeArray (const QValueVector <CI> &aVec,
     275                             com::SafeArray <I *> &aArr)
     276    {
     277        aArr.reset (aVec.size());
     278        size_t i = 0;
     279        for (typename QValueVector <CI>::const_iterator it = aVec.begin();
     280             it != aVec.end(); ++ it, ++ i)
     281        {
     282            aArr [i] = (*it).iface();
     283            if (aArr [i])
     284                aArr [i]->AddRef();
     285        }
     286    }
     287
     288    template <class I, class CI>
     289    void FromSafeArray (const com::SafeArray <I *> &aArr,
     290                        QValueVector <CI> &aVec)
     291    {
     292        aVec = QValueVector <CI> (aArr.size());
     293        size_t i = 0;
     294        for (typename QValueVector <CI>::iterator it = aVec.begin();
     295             it != aVec.end(); ++ it, ++ i)
     296            (*it).attach (aArr [i]);
     297    }
     298
     299    /* Arrays of strings */
     300
     301    static void ToSafeArray (const QValueVector <QString> &aVec,
     302                             com::SafeArray <BSTR> &aArr);
     303    static void FromSafeArray (const com::SafeArray <BSTR> &aArr,
     304                               QValueVector <QString> &aVec);
     305
    180306protected:
    181307
     
    230356    };
    231357
    232     /** Adapter to pass CEnums enums as output VirtualBox enum params (*_T) */
    233     template <typename CE, typename VE>
     358    /**
     359     * Adapter to pass CEnums enums as output COM enum params (*_T).
     360     *
     361     * @param QE    CEnums enum.
     362     * @param CE    COM enum.
     363     */
     364    template <typename QE, typename CE>
    234365    class ENUMOut
    235366    {
    236367    public:
    237368
    238         ENUMOut (CE &e) : ce (e), ve ((VE) 0) {}
    239         ~ENUMOut() { ce = (CE) ve; }
    240         operator VE *() { return &ve; }
     369        ENUMOut (QE &e) : qe (e), ce ((CE) 0) {}
     370        ~ENUMOut() { qe = (QE) ce; }
     371        operator CE *() { return &ce; }
    241372
    242373    private:
    243374
    244         CE &ce;
    245         VE ve;
     375        QE &qe;
     376        CE ce;
    246377    };
    247378
     
    605736#include "COMWrappers.h"
    606737
     738/** @} */
     739
    607740#endif // __COMDefs_h__
  • trunk/src/VBox/Frontends/VirtualBox/include/COMWrappers.xsl

    r5999 r6851  
    1212/*
    1313     Copyright (C) 2006-2007 innotek GmbH
    14    
     14
    1515     This file is part of VirtualBox Open Source Edition (OSE), as
    1616     available from http://www.virtualbox.org. This file is free software;
     
    126126        <xsl:text>    enum </xsl:text>
    127127        <xsl:value-of select="@name"/>
    128         <xsl:text> {&#x0A;</xsl:text>
     128        <xsl:text>&#x0A;    {&#x0A;</xsl:text>
    129129        <xsl:for-each select="const">
    130130            <xsl:text>        </xsl:text>
     
    360360    <xsl:text>    C</xsl:text>
    361361    <xsl:value-of select="substring(@name,2)"/>
    362     <xsl:text> &amp; operator = (const CUnknown &amp; that) {&#x0A;        return (C</xsl:text>
     362    <xsl:text> &amp; operator = (const CUnknown &amp; that)&#x0A;    {&#x0A;        return (C</xsl:text>
    363363    <xsl:value-of select="substring(@name,2)"/>
    364364    <xsl:text> &amp;) Base::operator = (that);&#x0A;    }&#x0A;&#x0A;</xsl:text>
     
    431431</xsl:template>
    432432
     433<!-- attribute declarations -->
    433434<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>
    434441    <xsl:apply-templates select="parent::node()" mode="begin"/>
    435442    <xsl:apply-templates select="@if" mode="begin"/>
     
    446453</xsl:template>
    447454
     455<!-- method declarations -->
    448456<xsl:template match="interface//method | collection//method" mode="declare">
    449457    <xsl:apply-templates select="parent::node()" mode="begin"/>
     
    468476        <xsl:text>inline ULONG C</xsl:text>
    469477        <xsl:value-of select="substring(@name,2)"/>
    470         <xsl:text>::GetCount () const {&#x0A;</xsl:text>
     478        <xsl:text>::GetCount () const&#x0A;{&#x0A;</xsl:text>
    471479        <xsl:text>    ULONG count = 0;&#x0A;</xsl:text>
    472480        <xsl:text>    Assert (mIface);&#x0A;</xsl:text>
     
    481489        <xsl:text> C</xsl:text>
    482490        <xsl:value-of select="substring(@name,2)"/>
    483         <xsl:text>::GetItemAt (ULONG index) const {&#x0A;</xsl:text>
     491        <xsl:text>::GetItemAt (ULONG index) const&#x0A;{&#x0A;</xsl:text>
    484492        <xsl:text>    </xsl:text><xsl:apply-templates select="@type"/>
    485493        <xsl:text> item;&#x0A;</xsl:text>
     
    495503        <xsl:text> C</xsl:text>
    496504        <xsl:value-of select="substring(@name,2)"/>
    497         <xsl:text>::Enumerate () const {&#x0A;</xsl:text>
     505        <xsl:text>::Enumerate () const&#x0A;{&#x0A;</xsl:text>
    498506        <xsl:text>    </xsl:text><xsl:apply-templates select="@enumerator"/>
    499507        <xsl:text> enumerator;&#x0A;</xsl:text>
     
    510518        <xsl:text>inline BOOL C</xsl:text>
    511519        <xsl:value-of select="substring(@name,2)"/>
    512         <xsl:text>::HasMore () const {&#x0A;</xsl:text>
     520        <xsl:text>::HasMore () const&#x0A;{&#x0A;</xsl:text>
    513521        <xsl:text>    BOOL more = FALSE;&#x0A;</xsl:text>
    514522        <xsl:text>    Assert (mIface);&#x0A;</xsl:text>
     
    523531        <xsl:text> C</xsl:text>
    524532        <xsl:value-of select="substring(@name,2)"/>
    525         <xsl:text>::GetNext () const {&#x0A;</xsl:text>
     533        <xsl:text>::GetNext () const&#x0A;{&#x0A;</xsl:text>
    526534        <xsl:text>    </xsl:text><xsl:apply-templates select="@type"/>
    527535        <xsl:text> next;&#x0A;</xsl:text>
     
    545553</xsl:template>
    546554
     555<!-- attribute definitions -->
    547556<xsl:template match="interface//attribute | collection//attribute" mode="define">
    548557    <xsl:apply-templates select="parent::node()" mode="begin"/>
     
    563572</xsl:template>
    564573
     574<!-- method definitions -->
    565575<xsl:template match="interface//method | collection//method" mode="define">
    566576    <xsl:apply-templates select="parent::node()" mode="begin"/>
     
    625635            </xsl:call-template>
    626636            <xsl:if test="$define">
    627                 <xsl:text> {&#x0A;</xsl:text>
     637                <xsl:text>&#x0A;{&#x0A;</xsl:text>
    628638                <!-- iface assertion -->
    629639                <xsl:text>    Assert (mIface);&#x0A;</xsl:text>
     
    658668            <xsl:call-template name="composeMethodDecl"/>
    659669            <xsl:if test="$define">
    660                 <xsl:text> {&#x0A;    </xsl:text>
     670                <xsl:text>&#x0A;{&#x0A;    </xsl:text>
    661671                <xsl:apply-templates select="$return/@type"/>
    662                 <xsl:text> a_</xsl:text>
    663                 <!-- ### xsl:call-template name="capitalize">
     672                <xsl:text> a</xsl:text>
     673                <xsl:call-template name="capitalize">
    664674                    <xsl:with-param name="str" select="$return/@name"/>
    665                 </xsl:call-template-->
    666                 <!--
    667                     using one of the blocks marked with ### causes sabcmd on RedHat
    668                     to stupidly fail, so we use <value-of> instead.
    669                 -->
    670                 <xsl:value-of select="$return/@name"/>
     675                </xsl:call-template>
    671676                <xsl:apply-templates select="$return/@type" mode="initializer"/>
    672677                <xsl:text>;&#x0A;</xsl:text>
    673678                <!-- iface assertion -->
    674679                <xsl:text>    Assert (mIface);&#x0A;</xsl:text>
    675                 <xsl:text>    if (!mIface)&#x0A;        return a_</xsl:text>
    676                 <!-- ### xsl:call-template name="capitalize">
     680                <xsl:text>    if (!mIface)&#x0A;        return a</xsl:text>
     681                <xsl:call-template name="capitalize">
    677682                    <xsl:with-param name="str" select="$return/@name"/>
    678                 </xsl:call-template-->
    679                 <xsl:value-of select="$return/@name"/>
     683                </xsl:call-template>
    680684                <xsl:text>;&#x0A;</xsl:text>
    681685                <!-- method call -->
    682686                <xsl:call-template name="composeMethodCall"/>
    683687                <!-- return statement -->
    684                 <xsl:text>    return a_</xsl:text>
    685                 <!-- ### xsl:call-template name="capitalize">
     688                <xsl:text>    return a</xsl:text>
     689                <xsl:call-template name="capitalize">
    686690                    <xsl:with-param name="str" select="$return/@name"/>
    687                 </xsl:call-template -->
    688                 <xsl:value-of select="$return/@name"/>
     691                </xsl:call-template>
    689692                <xsl:text>;&#x0A;}&#x0A;</xsl:text>
    690693            </xsl:if>
     
    720723                    <!-- parameter -->
    721724                    <xsl:apply-templates select="@type" mode="param"/>
    722                     <xsl:text> a_</xsl:text>
    723                     <!-- ### xsl:call-template name="capitalize">
     725                    <xsl:text> a</xsl:text>
     726                    <xsl:call-template name="capitalize">
    724727                        <xsl:with-param name="str" select="@name"/>
    725                     </xsl:call-template -->
    726                     <xsl:value-of select="@name"/>
     728                    </xsl:call-template>
    727729                    <xsl:text>)</xsl:text>
    728730                </xsl:when>
     
    749751            <xsl:for-each select="param[@dir!='return']">
    750752                <xsl:apply-templates select="@type" mode="param"/>
    751                 <xsl:text> a_</xsl:text>
    752                 <!-- ###  xsl:call-template name="capitalize">
     753                <xsl:text> a</xsl:text>
     754                <xsl:call-template name="capitalize">
    753755                    <xsl:with-param name="str" select="@name"/>
    754                 </xsl:call-template -->
    755                 <xsl:value-of select="@name"/>
     756                </xsl:call-template>
    756757                <xsl:if test="position() != last()">
    757758                    <xsl:text>, </xsl:text>
     
    767768<xsl:template name="composeMethodCall">
    768769    <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 -->
    769787    <xsl:text>    mRC = mIface-></xsl:text>
    770788    <xsl:choose>
     
    807825    </xsl:choose>
    808826    <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    <!-- -->
    809844    <xsl:call-template name="tryComposeFetchErrorInfo"/>
    810845</xsl:template>
     
    855890        <xsl:otherwise>
    856891            <xsl:if test="$supports='strict' or $supports='yes'">
    857                 <xsl:text>    if (FAILED (mRC)) {&#x0A;</xsl:text>
     892                <xsl:text>    if (FAILED (mRC))&#x0A;    {&#x0A;</xsl:text>
    858893                <xsl:text>        fetchErrorInfo (mIface, &amp;COM_IIDOF (Base::Iface));&#x0A;</xsl:text>
    859894                <xsl:if test="$supports='strict'">
     
    868903
    869904<xsl:template name="composeMethodCallParam">
     905
    870906    <xsl:param name="isIn" select="@dir='in'"/>
    871907    <xsl:param name="isOut" select="@dir='out' or @dir='return'"/>
     
    874910
    875911    <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>
    876927        <!-- string types -->
    877928        <xsl:when test="@type = 'wstring'">
    878929            <xsl:choose>
    879930                <xsl:when test="$isIn">
    880                     <xsl:text>BSTRIn (a_</xsl:text>
    881                     <!-- ### xsl:call-template name="capitalize">
     931                    <xsl:text>BSTRIn (a</xsl:text>
     932                    <xsl:call-template name="capitalize">
    882933                        <xsl:with-param name="str" select="@name"/>
    883                     </xsl:call-template -->
    884                     <xsl:value-of select="@name"/>
     934                    </xsl:call-template>
    885935                    <xsl:text>)</xsl:text>
    886936                </xsl:when>
    887937                <xsl:when test="$isOut">
    888                     <xsl:text>BSTROut (a_</xsl:text>
    889                     <!-- ### xsl:call-template name="capitalize">
     938                    <xsl:text>BSTROut (a</xsl:text>
     939                    <xsl:call-template name="capitalize">
    890940                        <xsl:with-param name="str" select="@name"/>
    891                     </xsl:call-template -->
    892                     <xsl:value-of select="@name"/>
     941                    </xsl:call-template>
    893942                    <xsl:text>)</xsl:text>
    894943                </xsl:when>
     
    899948            <xsl:choose>
    900949                <xsl:when test="$isIn">
    901                     <xsl:text>GUIDIn (a_</xsl:text>
    902                     <!-- ### xsl:call-template name="capitalize">
     950                    <xsl:text>GUIDIn (a</xsl:text>
     951                    <xsl:call-template name="capitalize">
    903952                        <xsl:with-param name="str" select="@name"/>
    904                     </xsl:call-template -->
    905                     <xsl:value-of select="@name"/>
     953                    </xsl:call-template>
    906954                    <xsl:text>)</xsl:text>
    907955                </xsl:when>
    908956                <xsl:when test="$isOut">
    909                     <xsl:text>GUIDOut (a_</xsl:text>
    910                     <!-- ### xsl:call-template name="capitalize">
     957                    <xsl:text>GUIDOut (a</xsl:text>
     958                    <xsl:call-template name="capitalize">
    911959                        <xsl:with-param name="str" select="@name"/>
    912                     </xsl:call-template -->
    913                     <xsl:value-of select="@name"/>
     960                    </xsl:call-template>
    914961                    <xsl:text>)</xsl:text>
    915962                </xsl:when>
     
    925972                    <xsl:text>(</xsl:text>
    926973                    <xsl:value-of select="@type"/>
    927                     <xsl:text>_T) a_</xsl:text>
    928                     <!-- ### xsl:call-template name="capitalize">
     974                    <xsl:text>_T) a</xsl:text>
     975                    <xsl:call-template name="capitalize">
    929976                        <xsl:with-param name="str" select="@name"/>
    930                     </xsl:call-template -->
    931                     <xsl:value-of select="@name"/>
     977                    </xsl:call-template>
    932978                </xsl:when>
    933979                <xsl:when test="$isOut">
     
    936982                    <xsl:text>, </xsl:text>
    937983                    <xsl:value-of select="@type"/>
    938                     <xsl:text>_T&gt; (a_</xsl:text>
    939                     <!-- ### xsl:call-template name="capitalize">
     984                    <xsl:text>_T&gt; (a</xsl:text>
     985                    <xsl:call-template name="capitalize">
    940986                        <xsl:with-param name="str" select="@name"/>
    941                     </xsl:call-template -->
    942                     <xsl:value-of select="@name"/>
     987                    </xsl:call-template>
    943988                    <xsl:text>)</xsl:text>
    944989                </xsl:when>
     
    9601005            <xsl:choose>
    9611006                <xsl:when test="$isIn">
    962                     <xsl:text>a_</xsl:text>
    963                     <!-- ### xsl:call-template name="capitalize">
     1007                    <xsl:text>a</xsl:text>
     1008                    <xsl:call-template name="capitalize">
    9641009                        <xsl:with-param name="str" select="@name"/>
    965                     </xsl:call-template -->
    966                     <xsl:value-of select="@name"/>
     1010                    </xsl:call-template>
    9671011                    <xsl:choose>
    9681012                        <xsl:when test="@type='$unknown'">
     
    9751019                </xsl:when>
    9761020                <xsl:when test="$isOut">
    977                     <xsl:text>&amp;a_</xsl:text>
    978                     <!-- ### xsl:call-template name="capitalize">
     1021                    <xsl:text>&amp;a</xsl:text>
     1022                    <xsl:call-template name="capitalize">
    9791023                        <xsl:with-param name="str" select="@name"/>
    980                     </xsl:call-template -->
    981                     <xsl:value-of select="@name"/>
     1024                    </xsl:call-template>
    9821025                    <xsl:choose>
    9831026                        <xsl:when test="@type='$unknown'">
     
    10031046            <xsl:choose>
    10041047                <xsl:when test="$isIn">
    1005                     <xsl:text>a_</xsl:text>
    1006                     <!-- ### xsl:call-template name="capitalize">
     1048                    <xsl:text>a</xsl:text>
     1049                    <xsl:call-template name="capitalize">
    10071050                        <xsl:with-param name="str" select="@name"/>
    1008                     </xsl:call-template -->
    1009                     <xsl:value-of select="@name"/>
     1051                    </xsl:call-template>
    10101052                </xsl:when>
    10111053                <xsl:when test="$isOut">
    1012                     <xsl:text>&amp;a_</xsl:text>
    1013                     <!-- ### xsl:call-template name="capitalize">
     1054                    <xsl:text>&amp;a</xsl:text>
     1055                    <xsl:call-template name="capitalize">
    10141056                        <xsl:with-param name="str" select="@name"/>
    1015                     </xsl:call-template -->
    1016                     <xsl:value-of select="@name"/>
     1057                    </xsl:call-template>
    10171058                </xsl:when>
    10181059            </xsl:choose>
     
    10231064
    10241065<!--
    1025  *  attribute/parameter type conversion (plain type name)
     1066 *  attribute/parameter type conversion (returns plain Qt type name)
    10261067-->
    10271068<xsl:template match="
     
    10311072    <xsl:variable name="self_target" select="current()/ancestor::if/@target"/>
    10321073
    1033     <xsl:if test="name(..)='param' and ../@array and ../@dir='return'">
     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'))">
    10341082        <xsl:message terminate="yes">
    10351083            <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
    1036             <xsl:text>return array parameters are not currently supported</xsl:text>
     1084            <xsl:text>return 'array' parameters and 'array' attributes are not supported, use 'safearray="yes"' instead.</xsl:text>
    10371085        </xsl:message>
    10381086    </xsl:if>
     
    10411089        <!-- modifiers (ignored for 'enumeration' attributes)-->
    10421090        <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>
    10431097            <xsl:if test="../@array">
    10441098                <xsl:message terminate="yes">
    1045                         <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
     1099                    <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
    10461100                    <xsl:text>either 'array' or 'mod' attribute is allowed, but not both!</xsl:text>
    10471101                </xsl:message>
     
    10791133                        <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
    10801134                        <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
    1081                         <xsl:text>of attibute 'mod' is invalid!</xsl:text>
     1135                        <xsl:text>of attribute 'mod' is invalid!</xsl:text>
    10821136                    </xsl:message>
    10831137                </xsl:otherwise>
     
    10861140        <!-- no modifiers -->
    10871141        <xsl:otherwise>
     1142            <xsl:if test="../@safearray">
     1143                <xsl:text>QValueVector &lt;</xsl:text>
     1144            </xsl:if>
    10881145            <xsl:choose>
    10891146                <!-- standard types -->
     
    11391196                </xsl:otherwise>
    11401197            </xsl:choose>
     1198            <xsl:if test="../@safearray">
     1199                <xsl:text>&gt;</xsl:text>
     1200            </xsl:if>
    11411201        </xsl:otherwise>
    11421202    </xsl:choose>
     
    11571217
    11581218    <xsl:choose>
     1219        <!-- safearrays don't need initializers -->
     1220        <xsl:when test="../@safearray">
     1221        </xsl:when>
    11591222        <!-- modifiers (ignored for 'enumeration' attributes)-->
    11601223        <xsl:when test="name(current())='type' and ../@mod">
    1161             <xsl:if test="../@array">
    1162                 <xsl:message terminate="yes">
    1163                         <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
    1164                     <xsl:text>either 'array' or 'mod' attribute is allowed, but not both!</xsl:text>
    1165                 </xsl:message>
    1166             </xsl:if>
    11671224            <xsl:choose>
    11681225                <xsl:when test="../@mod='ptr'">
     
    11971254                        <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
    11981255                        <xsl:value-of select="concat('value &quot;',../@mod,'&quot; ')"/>
    1199                         <xsl:text>of attibute 'mod' is invalid!</xsl:text>
     1256                        <xsl:text>of attribute 'mod' is invalid!</xsl:text>
    12001257                    </xsl:message>
    12011258                </xsl:otherwise>
     
    12471304            .='string' or
    12481305            .='wstring' or
     1306            ../@safearray='yes' or
    12491307            ((ancestor::library/enum[@name=current()]) or
    12501308             (ancestor::library/if[@target=$self_target]/enum[@name=current()])
     
    12701328                <!-- <param> context -->
    12711329                <xsl:when test="name(..)='param'">
    1272                     <xsl:if test="../@array">
    1273                         <xsl:message terminate="yes">
    1274                             <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/>
    1275                             <xsl:text>arrays of non-scalar types are not currently supported</xsl:text>
    1276                         </xsl:message>
    1277                     </xsl:if>
    12781330                    <xsl:choose>
    12791331                        <xsl:when test="../@dir='in'">
     
    13241376
    13251377
     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
    13261559</xsl:stylesheet>
    13271560
Note: See TracChangeset for help on using the changeset viewer.

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