Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Private Member Functions
nsCOMPtr< T > Class Template Reference

#include <nsCOMPtr.h>

Inherits nsCOMPtr_base.

Inherited by nsFastLoadPtr< T >.

Collaboration diagram for nsCOMPtr< T >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef T element_type

Public Member Functions

 nsCOMPtr ()
 nsCOMPtr (const nsCOMPtr< T > &aSmartPtr)
 nsCOMPtr (T *aRawPtr)
 nsCOMPtr (const already_AddRefed< T > &aSmartPtr)
 nsCOMPtr (const nsQueryInterface qi)
 nsCOMPtr (const nsQueryInterfaceWithError &qi)
 nsCOMPtr (const nsGetServiceByCID gs)
 nsCOMPtr (const nsGetServiceByCIDWithError &gs)
 nsCOMPtr (const nsGetServiceByContractID gs)
 nsCOMPtr (const nsGetServiceByContractIDWithError &gs)
 nsCOMPtr (const nsCOMPtr_helper &helper)
nsCOMPtr< T > & operator= (const nsCOMPtr< T > &rhs)
nsCOMPtr< T > & operator= (T *rhs)
nsCOMPtr< T > & operator= (const already_AddRefed< T > &rhs)
nsCOMPtr< T > & operator= (const nsQueryInterface rhs)
nsCOMPtr< T > & operator= (const nsQueryInterfaceWithError &rhs)
nsCOMPtr< T > & operator= (const nsGetServiceByCID rhs)
nsCOMPtr< T > & operator= (const nsGetServiceByCIDWithError &rhs)
nsCOMPtr< T > & operator= (const nsGetServiceByContractID rhs)
nsCOMPtr< T > & operator= (const nsGetServiceByContractIDWithError &rhs)
nsCOMPtr< T > & operator= (const nsCOMPtr_helper &rhs)
void swap (nsCOMPtr< T > &rhs)
void swap (T *&rhs)
nsDerivedSafe< T > * get () const
 operator nsDerivedSafe< T > * () const
nsDerivedSafe< T > * operator-> () const
nsCOMPtr< T > * get_address ()
const nsCOMPtr< T > * get_address () const
nsDerivedSafe< T > & operator* () const
T ** StartAssignment ()

Private Member Functions

NS_COM_GLUE void NS_FASTCALL assign_with_AddRef (nsISupports *)
NS_COM_GLUE void NS_FASTCALL assign_from_qi (const nsQueryInterface, const nsIID &)
NS_COM_GLUE void NS_FASTCALL assign_from_qi_with_error (const nsQueryInterfaceWithError &, const nsIID &)
NS_COM_GLUE void NS_FASTCALL assign_from_gs_cid (const nsGetServiceByCID, const nsIID &)
NS_COM_GLUE void NS_FASTCALL assign_from_gs_cid_with_error (const nsGetServiceByCIDWithError &, const nsIID &)
NS_COM_GLUE void NS_FASTCALL assign_from_gs_contractid (const nsGetServiceByContractID, const nsIID &)
NS_COM_GLUE void NS_FASTCALL assign_from_gs_contractid_with_error (const nsGetServiceByContractIDWithError &, const nsIID &)
NS_COM_GLUE void NS_FASTCALL assign_from_helper (const nsCOMPtr_helper &, const nsIID &)
NS_COM_GLUE void **NS_FASTCALL begin_assignment ()
 NS_MAY_ALIAS_PTR (nsISupports) mRawPtr
void assign_assuming_AddRef (nsISupports *newPtr)

Detailed Description

template<class T>
class nsCOMPtr< T >

Definition at line 538 of file nsCOMPtr.h.


Member Typedef Documentation

template<class T>
typedef T nsCOMPtr< T >::element_type

Definition at line 576 of file nsCOMPtr.h.


Constructor & Destructor Documentation

template<class T>
nsCOMPtr< T >::nsCOMPtr ( ) [inline]

Definition at line 606 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(0)
          // default constructor
        {
          NSCAP_LOG_ASSIGNMENT(this, 0);
        }
template<class T>
nsCOMPtr< T >::nsCOMPtr ( const nsCOMPtr< T > &  aSmartPtr) [inline]

Definition at line 613 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(aSmartPtr.mRawPtr)
          // copy-constructor
        {
          if ( mRawPtr )
            NSCAP_ADDREF(this, mRawPtr);
          NSCAP_LOG_ASSIGNMENT(this, aSmartPtr.mRawPtr);
        }
template<class T>
nsCOMPtr< T >::nsCOMPtr ( T aRawPtr) [inline]

Definition at line 622 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(aRawPtr)
          // construct from a raw pointer (of the right type)
        {
          if ( mRawPtr )
            NSCAP_ADDREF(this, mRawPtr);
          NSCAP_LOG_ASSIGNMENT(this, aRawPtr);
          NSCAP_ASSERT_NO_QUERY_NEEDED();
        }
template<class T>
nsCOMPtr< T >::nsCOMPtr ( const already_AddRefed< T > &  aSmartPtr) [inline]

Definition at line 632 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(aSmartPtr.mRawPtr)
          // construct from |dont_AddRef(expr)|
        {
          NSCAP_LOG_ASSIGNMENT(this, aSmartPtr.mRawPtr);
          NSCAP_ASSERT_NO_QUERY_NEEDED();
        }
template<class T>
nsCOMPtr< T >::nsCOMPtr ( const nsQueryInterface  qi) [inline]

Definition at line 640 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(0)
          // construct from |do_QueryInterface(expr)|
        {
          NSCAP_LOG_ASSIGNMENT(this, 0);
          assign_from_qi(qi, NS_GET_IID(T));
        }
template<class T>
nsCOMPtr< T >::nsCOMPtr ( const nsQueryInterfaceWithError &  qi) [inline]

Definition at line 648 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(0)
          // construct from |do_QueryInterface(expr, &rv)|
        {
          NSCAP_LOG_ASSIGNMENT(this, 0);
          assign_from_qi_with_error(qi, NS_GET_IID(T));
        }
template<class T>
nsCOMPtr< T >::nsCOMPtr ( const nsGetServiceByCID  gs) [inline]

Definition at line 656 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(0)
          // construct from |do_GetService(cid_expr)|
        {
          NSCAP_LOG_ASSIGNMENT(this, 0);
          assign_from_gs_cid(gs, NS_GET_IID(T));
        }
template<class T>
nsCOMPtr< T >::nsCOMPtr ( const nsGetServiceByCIDWithError &  gs) [inline]

Definition at line 664 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(0)
          // construct from |do_GetService(cid_expr, &rv)|
        {
          NSCAP_LOG_ASSIGNMENT(this, 0);
          assign_from_gs_cid_with_error(gs, NS_GET_IID(T));
        }
template<class T>
nsCOMPtr< T >::nsCOMPtr ( const nsGetServiceByContractID  gs) [inline]

Definition at line 672 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(0)
          // construct from |do_GetService(contractid_expr)|
        {
          NSCAP_LOG_ASSIGNMENT(this, 0);
          assign_from_gs_contractid(gs, NS_GET_IID(T));
        }
template<class T>
nsCOMPtr< T >::nsCOMPtr ( const nsGetServiceByContractIDWithError &  gs) [inline]

Definition at line 680 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(0)
          // construct from |do_GetService(contractid_expr, &rv)|
        {
          NSCAP_LOG_ASSIGNMENT(this, 0);
          assign_from_gs_contractid_with_error(gs, NS_GET_IID(T));
        }
template<class T>
nsCOMPtr< T >::nsCOMPtr ( const nsCOMPtr_helper helper) [inline]

Definition at line 688 of file nsCOMPtr.h.

            : NSCAP_CTOR_BASE(0)
          // ...and finally, anything else we might need to construct from
          //  can exploit the |nsCOMPtr_helper| facility
        {
          NSCAP_LOG_ASSIGNMENT(this, 0);
          assign_from_helper(helper, NS_GET_IID(T));
          NSCAP_ASSERT_NO_QUERY_NEEDED();
        }

Member Function Documentation

void nsCOMPtr_base::assign_assuming_AddRef ( nsISupports *  newPtr) [inline, protected, inherited]

Definition at line 516 of file nsCOMPtr.h.

        {
            /*
              |AddRef()|ing the new value (before entering this function) before
              |Release()|ing the old lets us safely ignore the self-assignment case.
              We must, however, be careful only to |Release()| _after_ doing the
              assignment, in case the |Release()| leads to our _own_ destruction,
              which would, in turn, cause an incorrect second |Release()| of our old
              pointer.  Thank <waterson@netscape.com> for discovering this.
            */
          nsISupports* oldPtr = mRawPtr;
          mRawPtr = newPtr;
          NSCAP_LOG_ASSIGNMENT(this, newPtr);
          NSCAP_LOG_RELEASE(this, oldPtr);
          if ( oldPtr )
            NSCAP_RELEASE(this, oldPtr);
        }

Here is the caller graph for this function:

void nsCOMPtr_base::assign_from_gs_cid ( const nsGetServiceByCID  gs,
const nsIID iid 
) [inherited]

Definition at line 111 of file nsCOMPtr.cpp.

       {
              nsISupports* newRawPtr;
              if ( NS_FAILED( gs(iid, NS_REINTERPRET_CAST(void**, &newRawPtr)) ) )
                     newRawPtr = 0;
    assign_assuming_AddRef(newRawPtr);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCOMPtr_base::assign_from_gs_cid_with_error ( const nsGetServiceByCIDWithError &  gs,
const nsIID iid 
) [inherited]

Definition at line 120 of file nsCOMPtr.cpp.

       {
              nsISupports* newRawPtr;
              if ( NS_FAILED( gs(iid, NS_REINTERPRET_CAST(void**, &newRawPtr)) ) )
                     newRawPtr = 0;
    assign_assuming_AddRef(newRawPtr);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCOMPtr_base::assign_from_gs_contractid ( const nsGetServiceByContractID  gs,
const nsIID iid 
) [inherited]

Definition at line 129 of file nsCOMPtr.cpp.

       {
              nsISupports* newRawPtr;
              if ( NS_FAILED( gs(iid, NS_REINTERPRET_CAST(void**, &newRawPtr)) ) )
                     newRawPtr = 0;
    assign_assuming_AddRef(newRawPtr);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCOMPtr_base::assign_from_gs_contractid_with_error ( const nsGetServiceByContractIDWithError &  gs,
const nsIID iid 
) [inherited]

Definition at line 138 of file nsCOMPtr.cpp.

       {
              nsISupports* newRawPtr;
              if ( NS_FAILED( gs(iid, NS_REINTERPRET_CAST(void**, &newRawPtr)) ) )
                     newRawPtr = 0;
    assign_assuming_AddRef(newRawPtr);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCOMPtr_base::assign_from_helper ( const nsCOMPtr_helper helper,
const nsIID iid 
) [inherited]

Definition at line 147 of file nsCOMPtr.cpp.

       {
              nsISupports* newRawPtr;
              if ( NS_FAILED( helper(iid, NS_REINTERPRET_CAST(void**, &newRawPtr)) ) )
                     newRawPtr = 0;
    assign_assuming_AddRef(newRawPtr);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCOMPtr_base::assign_from_qi ( const nsQueryInterface  qi,
const nsIID iid 
) [inherited]

Definition at line 93 of file nsCOMPtr.cpp.

       {
              nsISupports* newRawPtr;
              if ( NS_FAILED( qi(iid, NS_REINTERPRET_CAST(void**, &newRawPtr)) ) )
                     newRawPtr = 0;
    assign_assuming_AddRef(newRawPtr);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCOMPtr_base::assign_from_qi_with_error ( const nsQueryInterfaceWithError &  qi,
const nsIID iid 
) [inherited]

Definition at line 102 of file nsCOMPtr.cpp.

       {
              nsISupports* newRawPtr;
              if ( NS_FAILED( qi(iid, NS_REINTERPRET_CAST(void**, &newRawPtr)) ) )
                     newRawPtr = 0;
    assign_assuming_AddRef(newRawPtr);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCOMPtr_base::assign_with_AddRef ( nsISupports *  rawPtr) [inherited]

Definition at line 85 of file nsCOMPtr.cpp.

       {
    if ( rawPtr )
       NSCAP_ADDREF(this, rawPtr);
    assign_assuming_AddRef(rawPtr);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 156 of file nsCOMPtr.cpp.

  {
    assign_assuming_AddRef(0);
    return NS_REINTERPRET_CAST(void**, &mRawPtr);
  }

Here is the call graph for this function:

Here is the caller graph for this function:

template<class T>
nsDerivedSafe<T>* nsCOMPtr< T >::get ( ) const [inline]

Reimplemented in nsFastLoadPtr< T >.

Definition at line 823 of file nsCOMPtr.h.

        {
          return NS_REINTERPRET_CAST(nsDerivedSafe<T>*, mRawPtr);
        }
template<class T>
nsCOMPtr<T>* nsCOMPtr< T >::get_address ( ) [inline]

Definition at line 867 of file nsCOMPtr.h.

        {
          return this;
        }

Here is the caller graph for this function:

template<class T>
const nsCOMPtr<T>* nsCOMPtr< T >::get_address ( ) const [inline]

Definition at line 875 of file nsCOMPtr.h.

        {
          return this;
        }
nsCOMPtr_base::NS_MAY_ALIAS_PTR ( nsISupports  ) [protected, inherited]
template<class T>
nsCOMPtr< T >::operator nsDerivedSafe< T > * ( ) const [inline]

Definition at line 834 of file nsCOMPtr.h.

        {
          return get();
        }
template<class T>
nsDerivedSafe<T>& nsCOMPtr< T >::operator* ( ) const [inline]

Definition at line 886 of file nsCOMPtr.h.

        {
          NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsCOMPtr with operator*().");
          return *get();
        }
template<class T>
nsDerivedSafe<T>* nsCOMPtr< T >::operator-> ( void  ) const [inline]

Definition at line 847 of file nsCOMPtr.h.

        {
          NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsCOMPtr with operator->().");
          return get();
        }
template<class T>
nsCOMPtr<T>& nsCOMPtr< T >::operator= ( const nsCOMPtr< T > &  rhs) [inline]

Definition at line 702 of file nsCOMPtr.h.

        {
          assign_with_AddRef(rhs.mRawPtr);
          return *this;
        }
template<class T>
nsCOMPtr<T>& nsCOMPtr< T >::operator= ( T rhs) [inline]

Definition at line 710 of file nsCOMPtr.h.

template<class T>
nsCOMPtr<T>& nsCOMPtr< T >::operator= ( const already_AddRefed< T > &  rhs) [inline]

Definition at line 719 of file nsCOMPtr.h.

template<class T>
nsCOMPtr<T>& nsCOMPtr< T >::operator= ( const nsQueryInterface  rhs) [inline]

Definition at line 728 of file nsCOMPtr.h.

        {
          assign_from_qi(rhs, NS_GET_IID(T));
          return *this;
        }
template<class T>
nsCOMPtr<T>& nsCOMPtr< T >::operator= ( const nsQueryInterfaceWithError &  rhs) [inline]

Definition at line 736 of file nsCOMPtr.h.

        {
          assign_from_qi_with_error(rhs, NS_GET_IID(T));
          return *this;
        }
template<class T>
nsCOMPtr<T>& nsCOMPtr< T >::operator= ( const nsGetServiceByCID  rhs) [inline]

Definition at line 744 of file nsCOMPtr.h.

        {
          assign_from_gs_cid(rhs, NS_GET_IID(T));
          return *this;
        }
template<class T>
nsCOMPtr<T>& nsCOMPtr< T >::operator= ( const nsGetServiceByCIDWithError &  rhs) [inline]

Definition at line 752 of file nsCOMPtr.h.

        {
          assign_from_gs_cid_with_error(rhs, NS_GET_IID(T));
          return *this;
        }
template<class T>
nsCOMPtr<T>& nsCOMPtr< T >::operator= ( const nsGetServiceByContractID  rhs) [inline]

Definition at line 760 of file nsCOMPtr.h.

        {
          assign_from_gs_contractid(rhs, NS_GET_IID(T));
          return *this;
        }
template<class T>
nsCOMPtr<T>& nsCOMPtr< T >::operator= ( const nsGetServiceByContractIDWithError &  rhs) [inline]

Definition at line 768 of file nsCOMPtr.h.

template<class T>
nsCOMPtr<T>& nsCOMPtr< T >::operator= ( const nsCOMPtr_helper rhs) [inline]

Definition at line 776 of file nsCOMPtr.h.

template<class T>
T** nsCOMPtr< T >::StartAssignment ( ) [inline]

Definition at line 898 of file nsCOMPtr.h.

        {
#ifndef NSCAP_FEATURE_INLINE_STARTASSIGNMENT
          return NS_REINTERPRET_CAST(T**, begin_assignment());
#else
          assign_assuming_AddRef(0);
          return NS_REINTERPRET_CAST(T**, &mRawPtr);
#endif
        }
template<class T>
void nsCOMPtr< T >::swap ( nsCOMPtr< T > &  rhs) [inline]

Definition at line 786 of file nsCOMPtr.h.

        {
#ifdef NSCAP_FEATURE_USE_BASE
          nsISupports* temp = rhs.mRawPtr;
#else
          T* temp = rhs.mRawPtr;
#endif
          NSCAP_LOG_ASSIGNMENT(&rhs, mRawPtr);
          NSCAP_LOG_ASSIGNMENT(this, temp);
          NSCAP_LOG_RELEASE(this, mRawPtr);
          NSCAP_LOG_RELEASE(&rhs, temp);
          rhs.mRawPtr = mRawPtr;
          mRawPtr = temp;
          // |rhs| maintains the same invariants, so we don't need to |NSCAP_ASSERT_NO_QUERY_NEEDED|
        }
template<class T>
void nsCOMPtr< T >::swap ( T *&  rhs) [inline]

Definition at line 804 of file nsCOMPtr.h.

        {
#ifdef NSCAP_FEATURE_USE_BASE
          nsISupports* temp = rhs;
#else
          T* temp = rhs;
#endif
          NSCAP_LOG_ASSIGNMENT(this, temp);
          NSCAP_LOG_RELEASE(this, mRawPtr);
          rhs = NS_REINTERPRET_CAST(T*, mRawPtr);
          mRawPtr = temp;
          NSCAP_ASSERT_NO_QUERY_NEEDED();
        }

The documentation for this class was generated from the following file: