VirtualBox

Changeset 6449 in vbox for trunk/include/VBox


Ignore:
Timestamp:
Jan 22, 2008 4:13:28 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
27425
Message:

Main: Fixed build after r27415.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/com/ptr.h

    r6440 r6449  
    8080
    8181/**
    82  *  Equality operations for the ComPtrBase template.
    83  */
    84 template <class C>
    85 class ComPtrEqOps
    86 {
    87 protected:
    88 
    89     template <class I>
    90     static bool equals (C *aThis, I *aThat)
    91     {
    92         IUnknown *thatUnk = NULL, *thisUnk = NULL;
    93         if (aThat)
    94             aThat->QueryInterface (COM_IIDOF (IUnknown), (void **) &thatUnk);
    95         if (aThis)
    96             aThis->QueryInterface (COM_IIDOF (IUnknown), (void **) &thisUnk);
    97         bool equal = thisUnk == thatUnk;
    98         if (thisUnk)
    99             thisUnk->Release();
    100         if (thatUnk)
    101             thatUnk->Release();
    102         return equal;
    103     }
    104 
    105     /* specialization for IUnknown */
    106     template<>
    107     static bool equals <IUnknown> (C *aThis, IUnknown *aThat)
    108     {
    109         IUnknown *thisUnk = NULL;
    110         if (aThis)
    111             aThis->QueryInterface (COM_IIDOF (IUnknown), (void **) &thisUnk);
    112         bool equal = thisUnk == aThat;
    113         if (thisUnk)
    114             thisUnk->Release();
    115         return equal;
    116     }
    117 };
    118 
    119 /** Specialization for IUnknown */
     82 *  Returns @c true if two interface pointers are equal.
     83 * 
     84 *  According to the COM Identity Rule, interface pointers are considered to be
     85 *  equal if and only if IUnknown pointers queried on these interfaces pointers
     86 *  are equal (e.g. have the same binary value). Equal interface pointers
     87 *  represent the same object even if they are pointers to different interfaces.
     88 * 
     89 *  @param I1   Class of the first interface pointer (must be derived from
     90 *              IUnknown).
     91 *  @param I2   Class of the second interface pointer (must be derived from
     92 *              IUnknown).
     93 */
     94template <class I1, class I2>
     95inline bool ComPtrEquals (I1 *aThis, I2 *aThat)
     96{
     97    IUnknown *thatUnk = NULL, *thisUnk = NULL;
     98    if (aThat)
     99        aThat->QueryInterface (COM_IIDOF (IUnknown), (void **) &thatUnk);
     100    if (aThis)
     101        aThis->QueryInterface (COM_IIDOF (IUnknown), (void **) &thisUnk);
     102    bool equal = thisUnk == thatUnk;
     103    if (thisUnk)
     104        thisUnk->Release();
     105    if (thatUnk)
     106        thatUnk->Release();
     107    return equal;
     108}
     109
     110/* specialization for <Any, IUnknown> */
     111template <class I1>
     112inline bool ComPtrEquals (I1 *aThis, IUnknown *aThat)
     113{
     114    IUnknown *thisUnk = NULL;
     115    if (aThis)
     116        aThis->QueryInterface (COM_IIDOF (IUnknown), (void **) &thisUnk);
     117    bool equal = thisUnk == aThat;
     118    if (thisUnk)
     119        thisUnk->Release();
     120    return equal;
     121}
     122
     123/** Specialization for <IUnknown, Any> */
     124template <class I2>
     125inline bool ComPtrEquals (IUnknown *aThis, I2 *aThat)
     126{
     127    IUnknown *thatUnk = NULL;
     128    if (aThat)
     129        aThat->QueryInterface (COM_IIDOF (IUnknown), (void **) &thatUnk);
     130    bool equal = aThis == thatUnk;
     131    if (thatUnk)
     132        thatUnk->Release();
     133    return equal;
     134}
     135
     136/* specialization for IUnknown */
    120137template<>
    121 class ComPtrEqOps <IUnknown>
    122 {
    123 protected:
    124 
    125     template <class I>
    126     static bool equals (IUnknown *aThis, I *aThat)
    127     {
    128         IUnknown *thatUnk = NULL;
    129         if (aThat)
    130             aThat->QueryInterface (COM_IIDOF (IUnknown), (void **) &thatUnk);
    131         bool equal = aThis == thatUnk;
    132         if (thatUnk)
    133             thatUnk->Release();
    134         return equal;
    135     }
    136 
    137     /* specialization for IUnknown */
    138     template<>
    139     static bool equals <IUnknown> (IUnknown *aThis, IUnknown *aThat)
    140     {
    141         return aThis == aThat;
    142     }
    143 };
     138inline bool ComPtrEquals <IUnknown, IUnknown> (IUnknown *aThis, IUnknown *aThat)
     139{
     140    return aThis == aThat;
     141}
    144142
    145143/**
     
    147145 */
    148146template <class C, template <class> class RefOps = ComStrongRef>
    149 class ComPtrBase : protected RefOps <C>, protected ComPtrEqOps <C>
     147class ComPtrBase : protected RefOps <C>
    150148{
    151149public:
     
    206204    bool equalsTo (I *aThat) const
    207205    {
    208         return equals (p, aThat);
     206        return ComPtrEquals (p, aThat);
    209207    }
    210208
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