Add |release| and corresponding |operator=| and add equality operators that gcc3 doesn't need but MSVC does. Not part of the build.

This commit is contained in:
dbaron%fas.harvard.edu 2001-10-26 07:15:55 +00:00
Родитель b59ced36fe
Коммит 9bd03d80e6
4 изменённых файлов: 109 добавлений и 13 удалений

Просмотреть файл

@ -13,10 +13,9 @@ nsISupportsBase.h
nsISupportsImpl.h
nsISupportsUtils.h
nsISupportsObsolete.h
nsStackWalker.h
nsTraceRefcnt.h
nsWeakReference.h
nsWeakPtr.h
nscore.h
nslog.h
nslog.h
nsIInterfaceRequestorUtils.h

Просмотреть файл

@ -40,6 +40,7 @@ CPPSRCS = \
nsErrorService.cpp \
nsDebug.cpp \
nsIInterfaceRequestor.cpp \
nsStackWalker.cpp \
nsTraceRefcnt.cpp \
nsID.cpp \
nsCWeakReference.cpp \
@ -48,6 +49,7 @@ CPPSRCS = \
nsConsoleMessage.cpp \
nsExceptionService.cpp \
$(NULL)
# nsBloatLogging.cpp \
ifdef GC_LEAK_DETECTOR
CSRCS += nsGarbageCollector.c
@ -57,26 +59,28 @@ endif
EXPORTS = \
nsAgg.h \
nsIAllocator.h \
nsMemory.h \
nsAutoPtr.h \
nsCom.h \
nsComObsolete.h \
nscore.h \
nsCWeakReference.h \
nsDebug.h \
nsError.h \
nsIAllocator.h \
nsID.h \
nsIID.h \
nsIInterfaceRequestorUtils.h \
nsIPtr.h \
nsISupportsBase.h \
nsISupportsImpl.h \
nsISupportsUtils.h \
nsISupportsObsolete.h \
nsTraceRefcnt.h \
nsWeakReference.h \
nsWeakPtr.h \
nscore.h \
nsISupportsUtils.h \
nslog.h \
nsIInterfaceRequestorUtils.h \
nsMemory.h \
nsStackWalker.h \
nsTraceRefcnt.h \
nsWeakPtr.h \
nsWeakReference.h \
$(NULL)
ifdef NS_TRACE_MALLOC

Просмотреть файл

@ -45,12 +45,12 @@ EXPORTS = \
nsISupportsImpl.h \
nsISupportsObsolete.h \
nsISupportsUtils.h \
nsStackWalker.h \
nsTraceRefcnt.h \
nsWeakReference.h \
nsWeakPtr.h \
nscore.h \
pure.h \
nslog.h \
!ifdef MOZ_TRACE_MALLOC
nsTraceMalloc.h \
!endif
@ -60,7 +60,6 @@ EXPORTS = \
XPIDL_MODULE = xpcom_base
XPIDLSRCS = \
.\nsILoggingService.idl \
.\nsrootidl.idl \
.\nsIErrorService.idl \
.\nsIMemory.idl \
@ -101,7 +100,6 @@ C_OBJS = \
!endif
CPP_OBJS = \
.\$(OBJDIR)\nsLogging.obj \
.\$(OBJDIR)\nsErrorService.obj \
.\$(OBJDIR)\nsDebug.obj \
.\$(OBJDIR)\nsAllocator.obj \
@ -109,6 +107,7 @@ CPP_OBJS = \
.\$(OBJDIR)\nsCWeakReference.obj \
.\$(OBJDIR)\nsID.obj \
.\$(OBJDIR)\nsIInterfaceRequestor.obj \
.\$(OBJDIR)\nsStackWalker.obj \
# .\$(OBJDIR)\nsSystemInfo.obj \
.\$(OBJDIR)\nsExceptionService.obj \
.\$(OBJDIR)\nsTraceRefcnt.obj \

Просмотреть файл

@ -65,8 +65,19 @@ nsAutoPtr
return *this;
}
nsAutoPtr<T>&
operator=(nsAutoPtr<T>& aSmartPtr)
{
T* temp = mPtr;
enter(aPtr);
mPtr = aPtr.release();
exit(temp);
return *this;
}
operator T*() const { return mPtr; }
T* get() const { return mPtr; }
T* release() { T* temp = mPtr; mPtr = 0; return temp; }
// To be used only by helpers (such as |getter_Transfers| below)
T** begin_assignment() { mPtr = 0; return &mPtr; }
@ -105,8 +116,19 @@ nsAutoArrayPtr
return *this;
}
nsAutoArrayPtr<T>&
operator=(nsAutoArrayPtr<T>& aSmartPtr)
{
T* temp = mPtr;
enter(aPtr);
mPtr = aPtr.release();
exit(temp);
return *this;
}
operator T*() const { return mPtr; }
T* get() const { return mPtr; }
T* release() { T* temp = mPtr; mPtr = 0; return temp; }
// To be used only by helpers (such as |getter_Transfers| below)
T** begin_assignment() { mPtr = 0; return &mPtr; }
@ -149,8 +171,19 @@ nsMemoryAutoPtr
return *this;
}
nsMemoryAutoPtr<T>&
operator=(nsMemoryAutoPtr<T>& aSmartPtr)
{
T* temp = mPtr;
enter(aPtr);
mPtr = aPtr.release();
exit(temp);
return *this;
}
operator T*() const { return mPtr; }
T* get() const { return mPtr; }
T* release() { T* temp = mPtr; mPtr = 0; return temp; }
// To be used only by helpers (such as |getter_Transfers| below)
T** begin_assignment() { mPtr = 0; return &mPtr; }
@ -302,3 +335,64 @@ getter_AddRefs(nsRefPtr<T>& aSmartPtr)
{
return nsRefPtrGetterAddRefs<T>(aSmartPtr);
}
#define EQ_OP(op_, lhtype_, rhtype_, lhget_, rhget_) \
template <class T, class U> \
inline PRBool \
operator op_( lhtype_ lhs, rhtype_ rhs ) \
{ \
return lhs lhget_ op_ rhs rhget_; \
}
#define SMART_SMART_EQ_OP(op_, type_, lhconst_, rhconst_) \
EQ_OP(op_, const type_<lhconst_ T>&, const type_<rhconst_ U>&, \
.get(), .get())
#define SMART_RAW_EQ_OP(op_, type_, lhconst_, rhconst_) \
EQ_OP(op_, const type_<lhconst_ T>&, rhconst_ U *, .get(), )
#define RAW_SMART_EQ_OP(op_, type_, lhconst_, rhconst_) \
EQ_OP(op_, lhconst_ T *, const type_<rhconst_ U>&, , .get())
#define CONST_OPEQ_OPS(type_) \
SMART_SMART_EQ_OP(==, type_, , const) \
SMART_SMART_EQ_OP(!=, type_, , const) \
SMART_SMART_EQ_OP(==, type_, const, ) \
SMART_SMART_EQ_OP(!=, type_, const, ) \
SMART_SMART_EQ_OP(==, type_, const, const) \
SMART_SMART_EQ_OP(!=, type_, const, const) \
SMART_RAW_EQ_OP(==, type_, , const) \
SMART_RAW_EQ_OP(!=, type_, , const) \
SMART_RAW_EQ_OP(==, type_, const, ) \
SMART_RAW_EQ_OP(!=, type_, const, ) \
SMART_RAW_EQ_OP(==, type_, const, const) \
SMART_RAW_EQ_OP(!=, type_, const, const) \
RAW_SMART_EQ_OP(==, type_, , const) \
RAW_SMART_EQ_OP(!=, type_, , const) \
RAW_SMART_EQ_OP(==, type_, const, ) \
RAW_SMART_EQ_OP(!=, type_, const, ) \
RAW_SMART_EQ_OP(==, type_, const, const) \
RAW_SMART_EQ_OP(!=, type_, const, const)
#define NON_CONST_OPEQ_OPS(type_) \
SMART_SMART_EQ_OP(==, type_, , ) \
SMART_SMART_EQ_OP(!=, type_, , ) \
SMART_RAW_EQ_OP(==, type_, , ) \
SMART_RAW_EQ_OP(!=, type_, , ) \
RAW_SMART_EQ_OP(==, type_, , ) \
RAW_SMART_EQ_OP(!=, type_, , )
#ifdef NSCAP_DONT_PROVIDE_NONCONST_OPEQ
#define ALL_EQ_OPS(type_) \
CONST_OPEQ_OPS(type_)
#else
#define ALL_EQ_OPS(type_) \
NON_CONST_OPEQ_OPS(type_) \
CONST_OPEQ_OPS(type_)
#endif
ALL_EQ_OPS(nsAutoPtr)
ALL_EQ_OPS(nsAutoArrayPtr)
ALL_EQ_OPS(nsMemoryAutoPtr)
ALL_EQ_OPS(nsRefPtr)