1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Support class for object lifetime tracking (wxWeakRef<T>)
4 // Author: Arne Steinarson
6 // Copyright: (c) 2007 Arne Steinarson
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef _WX_TRACKER_H_
11 #define _WX_TRACKER_H_
15 class wxEventConnectionRef
;
17 // This class represents an object tracker and is stored in a linked list
18 // in the tracked object. It is only used in one of its derived forms.
19 class WXDLLIMPEXP_BASE wxTrackerNode
22 wxTrackerNode() : m_nxt(NULL
) { }
23 virtual ~wxTrackerNode() { }
25 virtual void OnObjectDestroy() = 0;
27 virtual wxEventConnectionRef
*ToEventConnection() { return NULL
; }
32 friend class wxTrackable
; // For list access
33 friend class wxEvtHandler
; // For list access
36 // Add-on base class for a trackable object.
37 class WXDLLIMPEXP_BASE wxTrackable
40 void AddNode(wxTrackerNode
*prn
)
46 void RemoveNode(wxTrackerNode
*prn
)
48 for ( wxTrackerNode
**pprn
= &m_first
; *pprn
; pprn
= &(*pprn
)->m_nxt
)
57 wxFAIL_MSG( "removing invalid tracker node" );
60 wxTrackerNode
*GetFirst() const { return m_first
; }
63 // this class is only supposed to be used as a base class but never be
64 // created nor destroyed directly so all ctors and dtor are protected
66 wxTrackable() : m_first(NULL
) { }
68 // copy ctor and assignment operator intentionally do not copy m_first: the
69 // objects which track the original trackable shouldn't track the new copy
70 wxTrackable(const wxTrackable
& WXUNUSED(other
)) : m_first(NULL
) { }
71 wxTrackable
& operator=(const wxTrackable
& WXUNUSED(other
)) { return *this; }
73 // dtor is not virtual: this class is not supposed to be used
74 // polymorphically and adding a virtual table to it would add unwanted
78 // Notify all registered refs
81 wxTrackerNode
* const first
= m_first
;
82 m_first
= first
->m_nxt
;
83 first
->OnObjectDestroy();
87 wxTrackerNode
*m_first
;
90 #endif // _WX_TRACKER_H_