]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: weakref.h | |
3 | // Purpose: interface of wxWeakRefDynamic<T> | |
4 | // Author: wxWidgets team | |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @wxheader{weakref.h} | |
11 | ||
12 | wxWeakRefDynamicT is a template class for weak references that is used in | |
13 | the same way as wxWeakRefT. The only difference is that wxWeakRefDynamic | |
14 | defaults to using @c dynamic_cast for establishing the object | |
15 | reference (while wxWeakRef defaults to @c static_cast). | |
16 | ||
17 | So, wxWeakRef will detect a type mismatch during compile time and will | |
18 | have a little better run-time performance. The role of wxWeakRefDynamic | |
19 | is to handle objects which derived type one does not know. | |
20 | ||
21 | @b Note: wxWeakRefT selects an implementation based on the static type | |
22 | of T. If T does not have wxTrackable statically, it defaults to to a mixed- | |
23 | mode operation, where it uses @c dynamic_cast as the last measure (if | |
24 | available from the compiler and enabled when building wxWidgets). | |
25 | ||
26 | For general cases, wxWeakRefT is the better choice. | |
27 | ||
28 | For API documentation, see: wxWeakRef | |
29 | ||
30 | @library{wxcore} | |
31 | @category{FIXME} | |
32 | */ | |
33 | class wxWeakRefDynamic<T> | |
34 | { | |
35 | public: | |
36 | ||
37 | }; | |
38 | ||
39 | ||
40 | ||
41 | /** | |
42 | @wxheader{weakref.h} | |
43 | ||
44 | wxWeakRef is a template class for weak references to wxWidgets objects, | |
45 | such as wxEvtHandler, wxWindow and | |
46 | wxObject. A weak reference behaves much like an ordinary | |
47 | pointer, but when the object pointed is destroyed, the weak reference is | |
48 | automatically reset to a @NULL pointer. | |
49 | ||
50 | wxWeakRefT can be used whenever one must keep a pointer to an object | |
51 | that one does not directly own, and that may be destroyed before the object | |
52 | holding the reference. | |
53 | ||
54 | wxWeakRefT is a small object and the mechanism behind it is fast | |
55 | (@b O(1)). So the overall cost of using it is small. | |
56 | ||
57 | @library{wxbase} | |
58 | @category{FIXME} | |
59 | ||
60 | @see wxSharedPtr, wxScopedPtr | |
61 | */ | |
62 | class wxWeakRef<T> | |
63 | { | |
64 | public: | |
65 | /** | |
66 | Constructor. The weak reference is initialized to @e pobj. | |
67 | */ | |
68 | wxWeakRefT(T* pobj = NULL); | |
69 | ||
70 | /** | |
71 | Destructor. | |
72 | */ | |
73 | ~wxWeakRefT(); | |
74 | ||
75 | /** | |
76 | Called when the tracked object is destroyed. Be default sets | |
77 | internal pointer to @NULL. | |
78 | */ | |
79 | virtual void OnObjectDestroy(); | |
80 | ||
81 | /** | |
82 | Release currently tracked object and rests object reference. | |
83 | */ | |
84 | void Release(); | |
85 | ||
86 | /** | |
87 | Returns pointer to the tracked object or @NULL. | |
88 | */ | |
89 | T* get() const; | |
90 | ||
91 | /** | |
92 | Release currently tracked object and start tracking the same object as | |
93 | the wxWeakRef @e wr. | |
94 | */ | |
95 | T* operator =(wxWeakRef<T>& wr); | |
96 | ||
97 | /** | |
98 | Implicit conversion to T*. Returns pointer to the tracked | |
99 | object or @NULL. | |
100 | */ | |
101 | T* operator*() const; | |
102 | ||
103 | /** | |
104 | Returns a reference to the tracked object. If the internal pointer is @NULL | |
105 | this method will cause an assert in debug mode. | |
106 | */ | |
107 | T operator*() const; | |
108 | ||
109 | /** | |
110 | Smart pointer member access. Returns a pointer to the | |
111 | tracked object. If the internal pointer is @NULL this | |
112 | method will cause an assert in debug mode. | |
113 | */ | |
114 | T* operator-(); | |
115 | ||
116 | /** | |
117 | Releases the currently tracked object and starts tracking @e pobj. | |
118 | A weak reference may be reset by passing @e @NULL as @e pobj. | |
119 | */ | |
120 | T* operator=(T* pobj); | |
121 | }; | |
122 |