Changeset 6851 in vbox for trunk/src/VBox/Frontends/VirtualBox/include
- Timestamp:
- Feb 7, 2008 4:02:11 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 27977
- Location:
- trunk/src/VBox/Frontends/VirtualBox/include
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/COMDefs.h
r5999 r6851 24 24 #define __COMDefs_h__ 25 25 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 */ 26 67 27 68 /* Both VBox/com/assert.h and qglobal.h contain a definition of ASSERT. … … 30 71 31 72 #include <VBox/com/com.h> 73 #include <VBox/com/array.h> 32 74 #include <VBox/com/assert.h> 33 75 … … 37 79 #include <qstring.h> 38 80 #include <quuid.h> 81 #include <qvaluevector.h> 39 82 40 83 #include <iprt/memory> // for auto_copy_ptr … … 139 182 public: 140 183 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(); 165 186 166 187 /** … … 178 199 virtual COMErrorInfo errorInfo() const { return COMErrorInfo(); } 179 200 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 180 306 protected: 181 307 … … 230 356 }; 231 357 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> 234 365 class ENUMOut 235 366 { 236 367 public: 237 368 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; } 241 372 242 373 private: 243 374 244 CE &ce;245 VE ve;375 QE &qe; 376 CE ce; 246 377 }; 247 378 … … 605 736 #include "COMWrappers.h" 606 737 738 /** @} */ 739 607 740 #endif // __COMDefs_h__ -
trunk/src/VBox/Frontends/VirtualBox/include/COMWrappers.xsl
r5999 r6851 12 12 /* 13 13 Copyright (C) 2006-2007 innotek GmbH 14 14 15 15 This file is part of VirtualBox Open Source Edition (OSE), as 16 16 available from http://www.virtualbox.org. This file is free software; … … 126 126 <xsl:text> enum </xsl:text> 127 127 <xsl:value-of select="@name"/> 128 <xsl:text> {
</xsl:text>128 <xsl:text>
 {
</xsl:text> 129 129 <xsl:for-each select="const"> 130 130 <xsl:text> </xsl:text> … … 360 360 <xsl:text> C</xsl:text> 361 361 <xsl:value-of select="substring(@name,2)"/> 362 <xsl:text> & operator = (const CUnknown & that) {
 return (C</xsl:text>362 <xsl:text> & operator = (const CUnknown & that)
 {
 return (C</xsl:text> 363 363 <xsl:value-of select="substring(@name,2)"/> 364 364 <xsl:text> &) Base::operator = (that);
 }

</xsl:text> … … 431 431 </xsl:template> 432 432 433 <!-- attribute declarations --> 433 434 <xsl:template match="interface//attribute | collection//attribute" mode="declare"> 435 <xsl:if test="@array"> 436 <xsl:message terminate="yes"> 437 <xsl:value-of select="concat(../../@name,'::',../@name,'::',@name,': ')"/> 438 <xsl:text>'array' attributes are not supported, use 'safearray="yes"' instead.</xsl:text> 439 </xsl:message> 440 </xsl:if> 434 441 <xsl:apply-templates select="parent::node()" mode="begin"/> 435 442 <xsl:apply-templates select="@if" mode="begin"/> … … 446 453 </xsl:template> 447 454 455 <!-- method declarations --> 448 456 <xsl:template match="interface//method | collection//method" mode="declare"> 449 457 <xsl:apply-templates select="parent::node()" mode="begin"/> … … 468 476 <xsl:text>inline ULONG C</xsl:text> 469 477 <xsl:value-of select="substring(@name,2)"/> 470 <xsl:text>::GetCount () const 478 <xsl:text>::GetCount () const
{
</xsl:text> 471 479 <xsl:text> ULONG count = 0;
</xsl:text> 472 480 <xsl:text> Assert (mIface);
</xsl:text> … … 481 489 <xsl:text> C</xsl:text> 482 490 <xsl:value-of select="substring(@name,2)"/> 483 <xsl:text>::GetItemAt (ULONG index) const 491 <xsl:text>::GetItemAt (ULONG index) const
{
</xsl:text> 484 492 <xsl:text> </xsl:text><xsl:apply-templates select="@type"/> 485 493 <xsl:text> item;
</xsl:text> … … 495 503 <xsl:text> C</xsl:text> 496 504 <xsl:value-of select="substring(@name,2)"/> 497 <xsl:text>::Enumerate () const 505 <xsl:text>::Enumerate () const
{
</xsl:text> 498 506 <xsl:text> </xsl:text><xsl:apply-templates select="@enumerator"/> 499 507 <xsl:text> enumerator;
</xsl:text> … … 510 518 <xsl:text>inline BOOL C</xsl:text> 511 519 <xsl:value-of select="substring(@name,2)"/> 512 <xsl:text>::HasMore () const 520 <xsl:text>::HasMore () const
{
</xsl:text> 513 521 <xsl:text> BOOL more = FALSE;
</xsl:text> 514 522 <xsl:text> Assert (mIface);
</xsl:text> … … 523 531 <xsl:text> C</xsl:text> 524 532 <xsl:value-of select="substring(@name,2)"/> 525 <xsl:text>::GetNext () const 533 <xsl:text>::GetNext () const
{
</xsl:text> 526 534 <xsl:text> </xsl:text><xsl:apply-templates select="@type"/> 527 535 <xsl:text> next;
</xsl:text> … … 545 553 </xsl:template> 546 554 555 <!-- attribute definitions --> 547 556 <xsl:template match="interface//attribute | collection//attribute" mode="define"> 548 557 <xsl:apply-templates select="parent::node()" mode="begin"/> … … 563 572 </xsl:template> 564 573 574 <!-- method definitions --> 565 575 <xsl:template match="interface//method | collection//method" mode="define"> 566 576 <xsl:apply-templates select="parent::node()" mode="begin"/> … … 625 635 </xsl:call-template> 626 636 <xsl:if test="$define"> 627 <xsl:text> 637 <xsl:text>
{
</xsl:text> 628 638 <!-- iface assertion --> 629 639 <xsl:text> Assert (mIface);
</xsl:text> … … 658 668 <xsl:call-template name="composeMethodDecl"/> 659 669 <xsl:if test="$define"> 660 <xsl:text> 670 <xsl:text>
{
 </xsl:text> 661 671 <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"> 664 674 <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> 671 676 <xsl:apply-templates select="$return/@type" mode="initializer"/> 672 677 <xsl:text>;
</xsl:text> 673 678 <!-- iface assertion --> 674 679 <xsl:text> Assert (mIface);
</xsl:text> 675 <xsl:text> if (!mIface)
 return a _</xsl:text>676 < !-- ###xsl:call-template name="capitalize">680 <xsl:text> if (!mIface)
 return a</xsl:text> 681 <xsl:call-template name="capitalize"> 677 682 <xsl:with-param name="str" select="$return/@name"/> 678 </xsl:call-template--> 679 <xsl:value-of select="$return/@name"/> 683 </xsl:call-template> 680 684 <xsl:text>;
</xsl:text> 681 685 <!-- method call --> 682 686 <xsl:call-template name="composeMethodCall"/> 683 687 <!-- 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"> 686 690 <xsl:with-param name="str" select="$return/@name"/> 687 </xsl:call-template --> 688 <xsl:value-of select="$return/@name"/> 691 </xsl:call-template> 689 692 <xsl:text>;
}
</xsl:text> 690 693 </xsl:if> … … 720 723 <!-- parameter --> 721 724 <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"> 724 727 <xsl:with-param name="str" select="@name"/> 725 </xsl:call-template --> 726 <xsl:value-of select="@name"/> 728 </xsl:call-template> 727 729 <xsl:text>)</xsl:text> 728 730 </xsl:when> … … 749 751 <xsl:for-each select="param[@dir!='return']"> 750 752 <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"> 753 755 <xsl:with-param name="str" select="@name"/> 754 </xsl:call-template --> 755 <xsl:value-of select="@name"/> 756 </xsl:call-template> 756 757 <xsl:if test="position() != last()"> 757 758 <xsl:text>, </xsl:text> … … 767 768 <xsl:template name="composeMethodCall"> 768 769 <xsl:param name="isSetter" select="''"/> 770 <!-- apply 'pre-call' hooks --> 771 <xsl:choose> 772 <xsl:when test="name()='attribute'"> 773 <xsl:call-template name="hooks"> 774 <xsl:with-param name="when" select="'pre-call'"/> 775 <xsl:with-param name="isSetter" select="$isSetter"/> 776 </xsl:call-template> 777 </xsl:when> 778 <xsl:when test="name()='method'"> 779 <xsl:for-each select="param"> 780 <xsl:call-template name="hooks"> 781 <xsl:with-param name="when" select="'pre-call'"/> 782 </xsl:call-template> 783 </xsl:for-each> 784 </xsl:when> 785 </xsl:choose> 786 <!-- start the call --> 769 787 <xsl:text> mRC = mIface-></xsl:text> 770 788 <xsl:choose> … … 807 825 </xsl:choose> 808 826 <xsl:text>);
</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 <!-- --> 809 844 <xsl:call-template name="tryComposeFetchErrorInfo"/> 810 845 </xsl:template> … … 855 890 <xsl:otherwise> 856 891 <xsl:if test="$supports='strict' or $supports='yes'"> 857 <xsl:text> if (FAILED (mRC)) {
</xsl:text>892 <xsl:text> if (FAILED (mRC))
 {
</xsl:text> 858 893 <xsl:text> fetchErrorInfo (mIface, &COM_IIDOF (Base::Iface));
</xsl:text> 859 894 <xsl:if test="$supports='strict'"> … … 868 903 869 904 <xsl:template name="composeMethodCallParam"> 905 870 906 <xsl:param name="isIn" select="@dir='in'"/> 871 907 <xsl:param name="isOut" select="@dir='out' or @dir='return'"/> … … 874 910 875 911 <xsl:choose> 912 <!-- safearrays --> 913 <xsl:when test="@safearray='yes'"> 914 <xsl:choose> 915 <xsl:when test="$isIn"> 916 <xsl:text>ComSafeArrayAsInParam (</xsl:text> 917 <xsl:value-of select="@name"/> 918 <xsl:text>)</xsl:text> 919 </xsl:when> 920 <xsl:when test="$isOut"> 921 <xsl:text>ComSafeArrayAsOutParam (</xsl:text> 922 <xsl:value-of select="@name"/> 923 <xsl:text>)</xsl:text> 924 </xsl:when> 925 </xsl:choose> 926 </xsl:when> 876 927 <!-- string types --> 877 928 <xsl:when test="@type = 'wstring'"> 878 929 <xsl:choose> 879 930 <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"> 882 933 <xsl:with-param name="str" select="@name"/> 883 </xsl:call-template --> 884 <xsl:value-of select="@name"/> 934 </xsl:call-template> 885 935 <xsl:text>)</xsl:text> 886 936 </xsl:when> 887 937 <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"> 890 940 <xsl:with-param name="str" select="@name"/> 891 </xsl:call-template --> 892 <xsl:value-of select="@name"/> 941 </xsl:call-template> 893 942 <xsl:text>)</xsl:text> 894 943 </xsl:when> … … 899 948 <xsl:choose> 900 949 <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"> 903 952 <xsl:with-param name="str" select="@name"/> 904 </xsl:call-template --> 905 <xsl:value-of select="@name"/> 953 </xsl:call-template> 906 954 <xsl:text>)</xsl:text> 907 955 </xsl:when> 908 956 <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"> 911 959 <xsl:with-param name="str" select="@name"/> 912 </xsl:call-template --> 913 <xsl:value-of select="@name"/> 960 </xsl:call-template> 914 961 <xsl:text>)</xsl:text> 915 962 </xsl:when> … … 925 972 <xsl:text>(</xsl:text> 926 973 <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"> 929 976 <xsl:with-param name="str" select="@name"/> 930 </xsl:call-template --> 931 <xsl:value-of select="@name"/> 977 </xsl:call-template> 932 978 </xsl:when> 933 979 <xsl:when test="$isOut"> … … 936 982 <xsl:text>, </xsl:text> 937 983 <xsl:value-of select="@type"/> 938 <xsl:text>_T> (a _</xsl:text>939 < !-- ###xsl:call-template name="capitalize">984 <xsl:text>_T> (a</xsl:text> 985 <xsl:call-template name="capitalize"> 940 986 <xsl:with-param name="str" select="@name"/> 941 </xsl:call-template --> 942 <xsl:value-of select="@name"/> 987 </xsl:call-template> 943 988 <xsl:text>)</xsl:text> 944 989 </xsl:when> … … 960 1005 <xsl:choose> 961 1006 <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"> 964 1009 <xsl:with-param name="str" select="@name"/> 965 </xsl:call-template --> 966 <xsl:value-of select="@name"/> 1010 </xsl:call-template> 967 1011 <xsl:choose> 968 1012 <xsl:when test="@type='$unknown'"> … … 975 1019 </xsl:when> 976 1020 <xsl:when test="$isOut"> 977 <xsl:text>&a _</xsl:text>978 < !-- ###xsl:call-template name="capitalize">1021 <xsl:text>&a</xsl:text> 1022 <xsl:call-template name="capitalize"> 979 1023 <xsl:with-param name="str" select="@name"/> 980 </xsl:call-template --> 981 <xsl:value-of select="@name"/> 1024 </xsl:call-template> 982 1025 <xsl:choose> 983 1026 <xsl:when test="@type='$unknown'"> … … 1003 1046 <xsl:choose> 1004 1047 <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"> 1007 1050 <xsl:with-param name="str" select="@name"/> 1008 </xsl:call-template --> 1009 <xsl:value-of select="@name"/> 1051 </xsl:call-template> 1010 1052 </xsl:when> 1011 1053 <xsl:when test="$isOut"> 1012 <xsl:text>&a _</xsl:text>1013 < !-- ###xsl:call-template name="capitalize">1054 <xsl:text>&a</xsl:text> 1055 <xsl:call-template name="capitalize"> 1014 1056 <xsl:with-param name="str" select="@name"/> 1015 </xsl:call-template --> 1016 <xsl:value-of select="@name"/> 1057 </xsl:call-template> 1017 1058 </xsl:when> 1018 1059 </xsl:choose> … … 1023 1064 1024 1065 <!-- 1025 * attribute/parameter type conversion ( plaintype name)1066 * attribute/parameter type conversion (returns plain Qt type name) 1026 1067 --> 1027 1068 <xsl:template match=" … … 1031 1072 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/> 1032 1073 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'))"> 1034 1082 <xsl:message terminate="yes"> 1035 1083 <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> 1037 1085 </xsl:message> 1038 1086 </xsl:if> … … 1041 1089 <!-- modifiers (ignored for 'enumeration' attributes)--> 1042 1090 <xsl:when test="name(current())='type' and ../@mod"> 1091 <xsl:if test="../@safearray"> 1092 <xsl:message terminate="yes"> 1093 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/> 1094 <xsl:text>either 'safearray' or 'mod' attribute is allowed, but not both!</xsl:text> 1095 </xsl:message> 1096 </xsl:if> 1043 1097 <xsl:if test="../@array"> 1044 1098 <xsl:message terminate="yes"> 1045 1099 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/> 1046 1100 <xsl:text>either 'array' or 'mod' attribute is allowed, but not both!</xsl:text> 1047 1101 </xsl:message> … … 1079 1133 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/> 1080 1134 <xsl:value-of select="concat('value "',../@mod,'" ')"/> 1081 <xsl:text>of att ibute 'mod' is invalid!</xsl:text>1135 <xsl:text>of attribute 'mod' is invalid!</xsl:text> 1082 1136 </xsl:message> 1083 1137 </xsl:otherwise> … … 1086 1140 <!-- no modifiers --> 1087 1141 <xsl:otherwise> 1142 <xsl:if test="../@safearray"> 1143 <xsl:text>QValueVector <</xsl:text> 1144 </xsl:if> 1088 1145 <xsl:choose> 1089 1146 <!-- standard types --> … … 1139 1196 </xsl:otherwise> 1140 1197 </xsl:choose> 1198 <xsl:if test="../@safearray"> 1199 <xsl:text>></xsl:text> 1200 </xsl:if> 1141 1201 </xsl:otherwise> 1142 1202 </xsl:choose> … … 1157 1217 1158 1218 <xsl:choose> 1219 <!-- safearrays don't need initializers --> 1220 <xsl:when test="../@safearray"> 1221 </xsl:when> 1159 1222 <!-- modifiers (ignored for 'enumeration' attributes)--> 1160 1223 <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>1167 1224 <xsl:choose> 1168 1225 <xsl:when test="../@mod='ptr'"> … … 1197 1254 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/> 1198 1255 <xsl:value-of select="concat('value "',../@mod,'" ')"/> 1199 <xsl:text>of att ibute 'mod' is invalid!</xsl:text>1256 <xsl:text>of attribute 'mod' is invalid!</xsl:text> 1200 1257 </xsl:message> 1201 1258 </xsl:otherwise> … … 1247 1304 .='string' or 1248 1305 .='wstring' or 1306 ../@safearray='yes' or 1249 1307 ((ancestor::library/enum[@name=current()]) or 1250 1308 (ancestor::library/if[@target=$self_target]/enum[@name=current()]) … … 1270 1328 <!-- <param> context --> 1271 1329 <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>1278 1330 <xsl:choose> 1279 1331 <xsl:when test="../@dir='in'"> … … 1324 1376 1325 1377 1378 <!-- 1379 * attribute/parameter type conversion (returns plain COM type name) 1380 * (basically, copied from midl.xsl) 1381 --> 1382 <xsl:template match=" 1383 attribute/@type | param/@type | 1384 enumerator/@type | collection/@type | collection/@enumerator 1385 " mode="com"> 1386 1387 <xsl:variable name="self_target" select="current()/ancestor::if/@target"/> 1388 1389 <xsl:choose> 1390 <!-- modifiers (ignored for 'enumeration' attributes)--> 1391 <xsl:when test="name(current())='type' and ../@mod"> 1392 <xsl:choose> 1393 <xsl:when test="../@mod='ptr'"> 1394 <xsl:choose> 1395 <!-- standard types --> 1396 <!--xsl:when test=".='result'">??</xsl:when--> 1397 <xsl:when test=".='boolean'">BOOL *</xsl:when> 1398 <xsl:when test=".='octet'">BYTE *</xsl:when> 1399 <xsl:when test=".='short'">SHORT *</xsl:when> 1400 <xsl:when test=".='unsigned short'">USHORT *</xsl:when> 1401 <xsl:when test=".='long'">LONG *</xsl:when> 1402 <xsl:when test=".='long long'">LONG64 *</xsl:when> 1403 <xsl:when test=".='unsigned long'">ULONG *</xsl:when> 1404 <xsl:when test=".='unsigned long long'">ULONG64 *</xsl:when> 1405 <xsl:when test=".='char'">CHAR *</xsl:when> 1406 <!--xsl:when test=".='string'">??</xsl:when--> 1407 <xsl:when test=".='wchar'">OLECHAR *</xsl:when> 1408 <!--xsl:when test=".='wstring'">??</xsl:when--> 1409 <xsl:otherwise> 1410 <xsl:message terminate="yes"> 1411 <xsl:value-of select="concat(../../../@name,'::',../../@name,'::',../@name,': ')"/> 1412 <xsl:text>attribute 'mod=</xsl:text> 1413 <xsl:value-of select="concat('"',../@mod,'"')"/> 1414 <xsl:text>' cannot be used with type </xsl:text> 1415 <xsl:value-of select="concat('"',current(),'"!')"/> 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 "',../@mod,'" ')"/> 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 <</xsl:text> 1511 <xsl:apply-templates select="@type" mode="com"/> 1512 <xsl:text>> </xsl:text> 1513 <xsl:value-of select="@name"/> 1514 <xsl:text>;
</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>);
</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>);
</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 1326 1559 </xsl:stylesheet> 1327 1560
Note:
See TracChangeset
for help on using the changeset viewer.