VirtualBox

Changeset 60504 in vbox for trunk/include


Ignore:
Timestamp:
Apr 14, 2016 4:39:11 PM (9 years ago)
Author:
vboxsync
Message:

include/VBox/com/ptr.h: streamline ATL use, whitespace cleanup

File:
1 edited

Legend:

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

    r58110 r60504  
    44
    55/*
    6  * Copyright (C) 2006-2015 Oracle Corporation
     6 * Copyright (C) 2006-2016 Oracle Corporation
    77 *
    88 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3535#endif
    3636
    37 #if !defined (VBOX_WITH_XPCOM)
    38  #include <atlbase.h>
    39  #ifndef _ATL_IIDOF
    40  # define _ATL_IIDOF(c) __uuidof(c)
    41  #endif
    42 #else
    43  #include <nsISupportsUtils.h>
    44 
    45 #endif /* !defined (VBOX_WITH_XPCOM) */
     37#ifdef VBOX_WITH_XPCOM
     38# include <nsISupportsUtils.h>
     39#endif /* VBOX_WITH_XPCOM */
    4640
    4741#include <VBox/com/defs.h>
     
    6256                                 const char *serverName,
    6357                                 const nsIID &id,
    64                                  void** ppobj);
     58                                 void **ppobj);
    6559HRESULT GlueCreateInstance(const CLSID &clsid,
    6660                           const nsIID &id,
    67                            void** ppobj);
     61                           void **ppobj);
    6862}
    6963
     
    130124        m_p = NULL;
    131125        if (!that.isNull())
    132             that->QueryInterface(COM_IIDOF(T), (void**)&m_p);
     126            that->QueryInterface(COM_IIDOF(T), (void **)&m_p);
    133127    }
    134128
     
    155149        m_p = NULL;
    156150        if (p)
    157             p->QueryInterface(COM_IIDOF(T), (void**)&m_p);
    158     }
    159 
    160     /**
    161      * Specialization: copy constructor from a plain T* pointer. Calls AddRef().
     151            p->QueryInterface(COM_IIDOF(T), (void **)&m_p);
     152    }
     153
     154    /**
     155     * Specialization: copy constructor from a plain T * pointer. Calls AddRef().
    162156     */
    163157    ComPtr(T *that_p)
     
    178172    ComPtr& operator=(const ComPtr<T2> &that)
    179173    {
    180         return operator=((T2*)that);
     174        return operator=((T2 *)that);
    181175    }
    182176
     
    187181    ComPtr& operator=(const ComPtr &that)
    188182    {
    189         return operator=((T*)that);
     183        return operator=((T *)that);
    190184    }
    191185
     
    204198        cleanup();
    205199        if (p)
    206             p->QueryInterface(COM_IIDOF(T), (void**)&m_p);
     200            p->QueryInterface(COM_IIDOF(T), (void **)&m_p);
    207201        return *this;
    208202    }
    209203
    210204    /**
    211      * Specialization of the previous: assignment from a plain T* pointer.
     205     * Specialization of the previous: assignment from a plain T * pointer.
    212206     * Calls Release() on the previous member pointer, if any, and AddRef() on the new one.
    213207     */
     
    243237    }
    244238
    245 
    246     bool operator<(T* p) const
     239    bool operator<(T *p) const
    247240    {
    248241        return m_p < p;
     
    253246     * parameters to COM method calls.
    254247     */
    255     operator T*() const
     248    operator T *() const
    256249    {
    257250        return m_p;
     
    262255     *  pointer).
    263256     */
    264     T* operator->() const
     257    T *operator->() const
    265258    {
    266259        return m_p;
     
    276269     * can get cleaned up properly.
    277270     */
    278     T** asOutParam()
     271    T **asOutParam()
    279272    {
    280273        cleanup();
     
    294287        {
    295288            if (m_p)
    296                 return m_p->QueryInterface(COM_IIDOF(T2), (void**)pp);
     289                return m_p->QueryInterface(COM_IIDOF(T2), (void **)pp);
    297290            else
    298291            {
     
    310303     */
    311304    template <class T2>
    312     bool operator==(T2* p)
     305    bool operator==(T2 *p)
    313306    {
    314307        IUnknown *p1 = NULL;
    315308        bool fNeedsRelease1 = false;
    316309        if (m_p)
    317             fNeedsRelease1 = (SUCCEEDED(m_p->QueryInterface(COM_IIDOF(IUnknown), (void**)&p1)));
     310            fNeedsRelease1 = (SUCCEEDED(m_p->QueryInterface(COM_IIDOF(IUnknown), (void **)&p1)));
    318311
    319312        IUnknown *p2 = NULL;
    320313        bool fNeedsRelease2 = false;
    321314        if (p)
    322             fNeedsRelease2 = (SUCCEEDED(p->QueryInterface(COM_IIDOF(IUnknown), (void**)&p2)));
     315            fNeedsRelease2 = (SUCCEEDED(p->QueryInterface(COM_IIDOF(IUnknown), (void **)&p2)));
    323316
    324317        bool f = p1 == p2;
     
    338331        HRESULT rc;
    339332        T *obj = NULL;
    340 #if !defined (VBOX_WITH_XPCOM)
    341         rc = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, _ATL_IIDOF(T),
    342                               (void**)&obj);
    343 #else /* !defined (VBOX_WITH_XPCOM) */
     333#ifndef VBOX_WITH_XPCOM
     334        rc = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, COM_IIDOF(T),
     335                              (void **)&obj);
     336#else /* VBOX_WITH_XPCOM */
    344337        using namespace com;
    345         rc = GlueCreateInstance(clsid, NS_GET_IID(T), (void**)&obj);
    346 #endif /* !defined (VBOX_WITH_XPCOM) */
     338        rc = GlueCreateInstance(clsid, NS_GET_IID(T), (void **)&obj);
     339#endif /* VBOX_WITH_XPCOM */
    347340        *this = obj;
    348341        if (SUCCEEDED(rc))
     
    362355    HRESULT createLocalObject(const CLSID &clsid)
    363356    {
    364 #if !defined (VBOX_WITH_XPCOM)
     357#ifndef VBOX_WITH_XPCOM
    365358        HRESULT rc;
    366359        T *obj = NULL;
    367         rc = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, _ATL_IIDOF(T),
    368                               (void**)&obj);
     360        rc = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, COM_IIDOF(T),
     361                              (void **)&obj);
    369362        *this = obj;
    370363        if (SUCCEEDED(rc))
    371364            obj->Release();
    372365        return rc;
    373 #else /* !defined (VBOX_WITH_XPCOM) */
     366#else /* VBOX_WITH_XPCOM */
    374367        return createInprocObject(clsid);
    375 #endif /* !defined (VBOX_WITH_XPCOM) */
     368#endif /* VBOX_WITH_XPCOM */
    376369    }
    377370
     
    386379    {
    387380        T *obj = NULL;
    388         HRESULT rc = GlueCreateObjectOnServer(clsid, serverName, NS_GET_IID(T), (void**)&obj);
     381        HRESULT rc = GlueCreateObjectOnServer(clsid, serverName, NS_GET_IID(T), (void **)&obj);
    389382        *this = obj;
    390383        if (SUCCEEDED(rc))
     
    395388
    396389protected:
    397     void copyFrom(T* p)
     390    void copyFrom(T *p)
    398391    {
    399392        m_p = p;
     
    411404    }
    412405
     406public:
     407    // Do NOT access this member unless you really know what you're doing!
    413408    T *m_p;
    414409};
     
    479474    {
    480475        HRESULT rc;
    481 #if !defined (VBOX_WITH_XPCOM)
    482 #   ifdef VBOX_COM_OUTOFPROC_MODULE
    483         CComObjectNoLock<T> *obj = new CComObjectNoLock<T>();
     476#ifndef VBOX_WITH_XPCOM
     477# ifdef VBOX_COM_OUTOFPROC_MODULE
     478        ATL::CComObjectNoLock<T> *obj = new ATL::CComObjectNoLock<T>();
    484479        if (obj)
    485480        {
     
    490485        else
    491486            rc = E_OUTOFMEMORY;
    492 #   else
    493         CComObject<T> *obj = NULL;
    494         rc = CComObject<T>::CreateInstance(&obj);
    495 #   endif
    496 #else /* !defined (VBOX_WITH_XPCOM) */
     487# else
     488        ATL::CComObject<T> *obj = NULL;
     489        rc = ATL::CComObject<T>::CreateInstance(&obj);
     490# endif
     491#else /* VBOX_WITH_XPCOM */
    497492        CComObject<T> *obj = new CComObject<T>();
    498493        if (obj)
     
    500495        else
    501496            rc = E_OUTOFMEMORY;
    502 #endif /* !defined (VBOX_WITH_XPCOM) */
     497#endif /* VBOX_WITH_XPCOM */
    503498        *this = obj;
    504499        return rc;
Note: See TracChangeset for help on using the changeset viewer.

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