gecko-dev/xpcom/glue/nsWeakReference.h

83 строки
1.6 KiB
C
Исходник Обычный вид История

1999-08-03 07:41:27 +04:00
#ifndef nsWeakReference_h__
#define nsWeakReference_h__
// nsWeakReference.h
#include "nsIWeakReference.h"
class nsSupportsWeakReference : public nsISupportsWeakReference
{
public:
nsSupportsWeakReference()
: mProxy(0)
{
// nothing else to do here
}
1999-08-05 23:47:10 +04:00
inline virtual ~nsSupportsWeakReference();
1999-08-03 07:41:27 +04:00
1999-08-03 08:59:47 +04:00
NS_IMETHOD GetWeakReference( nsIWeakReference** );
1999-08-03 07:41:27 +04:00
private:
friend class nsWeakReference;
void
NoticeProxyDestruction()
// ...called (only) by an |nsWeakReference| from _its_ dtor.
{
mProxy = 0;
}
nsWeakReference* mProxy;
};
class nsWeakReference : public nsIWeakReference
{
public:
// nsISupports...
1999-08-03 08:59:47 +04:00
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
NS_IMETHOD QueryInterface( const nsIID&, void** );
1999-08-03 07:41:27 +04:00
// nsIWeakReference...
1999-08-03 08:59:47 +04:00
NS_IMETHOD QueryReference( const nsIID&, void** );
1999-08-03 07:41:27 +04:00
private:
friend class nsSupportsWeakReference;
nsWeakReference( nsSupportsWeakReference* referent )
: mRefCount(0),
mReferent(referent)
// ...I can only be constructed by an |nsSupportsWeakReference|
{
// nothing else to do here
}
1999-08-05 23:47:10 +04:00
virtual ~nsWeakReference()
1999-08-03 07:41:27 +04:00
// ...I will only be destroyed by calling |delete| myself.
{
if ( mReferent )
mReferent->NoticeProxyDestruction();
}
void
NoticeReferentDestruction()
// ...called (only) by an |nsSupportsWeakReference| from _its_ dtor.
{
mReferent = 0;
}
nsrefcnt mRefCount;
nsSupportsWeakReference* mReferent;
};
inline
nsSupportsWeakReference::~nsSupportsWeakReference()
{
if ( mProxy )
mProxy->NoticeReferentDestruction();
}
#endif