michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsWeakReference_h__ michael@0: #define nsWeakReference_h__ michael@0: michael@0: // nsWeakReference.h michael@0: michael@0: // See mfbt/WeakPtr.h for a more typesafe C++ implementation of weak references michael@0: michael@0: #include "nsIWeakReferenceUtils.h" michael@0: michael@0: class nsWeakReference; michael@0: michael@0: // Set IMETHOD_VISIBILITY to empty so that the class-level NS_COM declaration michael@0: // controls member method visibility. michael@0: #undef IMETHOD_VISIBILITY michael@0: #define IMETHOD_VISIBILITY NS_COM_GLUE michael@0: michael@0: class NS_COM_GLUE nsSupportsWeakReference : public nsISupportsWeakReference michael@0: { michael@0: public: michael@0: nsSupportsWeakReference() michael@0: : mProxy(0) michael@0: { michael@0: // nothing else to do here michael@0: } michael@0: michael@0: NS_DECL_NSISUPPORTSWEAKREFERENCE michael@0: michael@0: protected: michael@0: inline ~nsSupportsWeakReference(); michael@0: michael@0: private: michael@0: friend class nsWeakReference; michael@0: michael@0: void michael@0: NoticeProxyDestruction() michael@0: // ...called (only) by an |nsWeakReference| from _its_ dtor. michael@0: { michael@0: mProxy = 0; michael@0: } michael@0: michael@0: nsWeakReference* mProxy; michael@0: michael@0: protected: michael@0: michael@0: void ClearWeakReferences(); michael@0: bool HasWeakReferences() const {return mProxy != 0;} michael@0: }; michael@0: michael@0: #undef IMETHOD_VISIBILITY michael@0: #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN michael@0: michael@0: inline michael@0: nsSupportsWeakReference::~nsSupportsWeakReference() michael@0: { michael@0: ClearWeakReferences(); michael@0: } michael@0: michael@0: #endif