Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions
nsISupportsUtils.h File Reference
#include "nscore.h"
#include "nsISupportsBase.h"
#include "nsError.h"
#include "nsDebug.h"
#include "nsISupportsImpl.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  nsCOMTypeInfo< T >
struct  nsCOMTypeInfo< nsISupports >

Defines

#define NS_NEWXPCOM(_result, _type)
 Macro for instantiating a new object that implements nsISupports.
#define NS_DELETEXPCOM(_ptr)
 Macro for deleting an object that implements nsISupports.
#define NS_ADDREF(_ptr)   (_ptr)->AddRef()
 Macro for adding a reference to an interface.
#define NS_ADDREF_THIS()   AddRef()
 Macro for adding a reference to this.
#define NS_IF_ADDREF(_expr)   ns_if_addref(_expr)
 Macro for adding a reference to an interface that checks for NULL.
#define NS_RELEASE(_ptr)
 Macro for releasing a reference to an interface.
#define NS_RELEASE_THIS()   Release()
 Macro for releasing a reference to an interface.
#define NS_RELEASE2(_ptr, _rv)
 Macro for releasing a reference to an interface, except that this macro preserves the return value from the underlying Release call.
#define NS_IF_RELEASE(_ptr)
 Macro for releasing a reference to an interface that checks for NULL;.
#define NS_ISUPPORTS_CAST(__unambiguousBase, __expr)   NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(__unambiguousBase, __expr))
#define NS_GET_IID(T)   nsCOMTypeInfo<T>::GetIID()

Functions

template<class T >
nsrefcnt ns_if_addref (T expr)
template<class T , class DestinationType >
nsresult CallQueryInterface (T *aSource, DestinationType **aDestination)

Define Documentation

#define NS_ADDREF (   _ptr)    (_ptr)->AddRef()

Macro for adding a reference to an interface.

Parameters:
_ptrThe interface pointer.

Definition at line 89 of file nsISupportsUtils.h.

#define NS_ADDREF_THIS ( )    AddRef()

Macro for adding a reference to this.

This macro should be used because NS_ADDREF (when tracing) may require an ambiguous cast from the pointers primary type to nsISupports. This macro sidesteps that entire problem.

Definition at line 98 of file nsISupportsUtils.h.

#define NS_DELETEXPCOM (   _ptr)
Value:
PR_BEGIN_MACRO                                                              \
    delete (_ptr);                                                            \
  PR_END_MACRO

Macro for deleting an object that implements nsISupports.

Parameters:
_ptrThe object to delete.

Definition at line 80 of file nsISupportsUtils.h.

#define NS_GET_IID (   T)    nsCOMTypeInfo<T>::GetIID()

Definition at line 213 of file nsISupportsUtils.h.

#define NS_IF_ADDREF (   _expr)    ns_if_addref(_expr)

Macro for adding a reference to an interface that checks for NULL.

Parameters:
_exprThe interface pointer.

Definition at line 123 of file nsISupportsUtils.h.

#define NS_IF_RELEASE (   _ptr)
Value:
PR_BEGIN_MACRO                                                              \
    if (_ptr) {                                                               \
      (_ptr)->Release();                                                      \
      (_ptr) = 0;                                                             \
    }                                                                         \
  PR_END_MACRO

Macro for releasing a reference to an interface that checks for NULL;.

Parameters:
_ptrThe interface pointer.

Definition at line 169 of file nsISupportsUtils.h.

#define NS_ISUPPORTS_CAST (   __unambiguousBase,
  __expr 
)    NS_STATIC_CAST(nsISupports*, NS_STATIC_CAST(__unambiguousBase, __expr))

Definition at line 190 of file nsISupportsUtils.h.

#define NS_NEWXPCOM (   _result,
  _type 
)
Value:
PR_BEGIN_MACRO                                                              \
    _result = new _type();                                                    \
  PR_END_MACRO

Macro for instantiating a new object that implements nsISupports.

Note that you can only use this if you adhere to the no arguments constructor com policy (which you really should!).

Parameters:
_resultWhere the new instance pointer is stored
_typeThe type of object to call "new" with.

Definition at line 71 of file nsISupportsUtils.h.

#define NS_RELEASE (   _ptr)
Value:
PR_BEGIN_MACRO                                                              \
    (_ptr)->Release();                                                        \
    (_ptr) = 0;                                                               \
  PR_END_MACRO

Macro for releasing a reference to an interface.

Parameters:
_ptrThe interface pointer.

Definition at line 138 of file nsISupportsUtils.h.

#define NS_RELEASE2 (   _ptr,
  _rv 
)
Value:
PR_BEGIN_MACRO                                                              \
    _rv = (_ptr)->Release();                                                  \
    if (0 == (_rv)) (_ptr) = 0;                                               \
  PR_END_MACRO

Macro for releasing a reference to an interface, except that this macro preserves the return value from the underlying Release call.

The interface pointer argument will only be NULLed if the reference count goes to zero.

Parameters:
_ptrThe interface pointer.

Definition at line 159 of file nsISupportsUtils.h.

Macro for releasing a reference to an interface.

Parameters:
_ptrThe interface pointer.

Definition at line 148 of file nsISupportsUtils.h.


Function Documentation

template<class T , class DestinationType >
nsresult CallQueryInterface ( T aSource,
DestinationType **  aDestination 
) [inline]

Definition at line 219 of file nsISupportsUtils.h.

{
    NS_PRECONDITION(aSource, "null parameter");
    NS_PRECONDITION(aDestination, "null parameter");
    
    return aSource->QueryInterface(NS_GET_IID(DestinationType),
                                   NS_REINTERPRET_CAST(void**, aDestination));
}
template<class T >
nsrefcnt ns_if_addref ( T  expr) [inline]

Definition at line 112 of file nsISupportsUtils.h.

{
    return expr ? expr->AddRef() : 0;
}