|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef nsWeakReference_h__ |
|
8 #define nsWeakReference_h__ |
|
9 |
|
10 // nsWeakReference.h |
|
11 |
|
12 // See mfbt/WeakPtr.h for a more typesafe C++ implementation of weak references |
|
13 |
|
14 #include "nsIWeakReferenceUtils.h" |
|
15 |
|
16 class nsWeakReference; |
|
17 |
|
18 // Set IMETHOD_VISIBILITY to empty so that the class-level NS_COM declaration |
|
19 // controls member method visibility. |
|
20 #undef IMETHOD_VISIBILITY |
|
21 #define IMETHOD_VISIBILITY NS_COM_GLUE |
|
22 |
|
23 class NS_COM_GLUE nsSupportsWeakReference : public nsISupportsWeakReference |
|
24 { |
|
25 public: |
|
26 nsSupportsWeakReference() |
|
27 : mProxy(0) |
|
28 { |
|
29 // nothing else to do here |
|
30 } |
|
31 |
|
32 NS_DECL_NSISUPPORTSWEAKREFERENCE |
|
33 |
|
34 protected: |
|
35 inline ~nsSupportsWeakReference(); |
|
36 |
|
37 private: |
|
38 friend class nsWeakReference; |
|
39 |
|
40 void |
|
41 NoticeProxyDestruction() |
|
42 // ...called (only) by an |nsWeakReference| from _its_ dtor. |
|
43 { |
|
44 mProxy = 0; |
|
45 } |
|
46 |
|
47 nsWeakReference* mProxy; |
|
48 |
|
49 protected: |
|
50 |
|
51 void ClearWeakReferences(); |
|
52 bool HasWeakReferences() const {return mProxy != 0;} |
|
53 }; |
|
54 |
|
55 #undef IMETHOD_VISIBILITY |
|
56 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN |
|
57 |
|
58 inline |
|
59 nsSupportsWeakReference::~nsSupportsWeakReference() |
|
60 { |
|
61 ClearWeakReferences(); |
|
62 } |
|
63 |
|
64 #endif |