1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Support class for object lifetime tracking (wxWeakRef<T>)
4 // Author: Arne Steinarson
7 // Copyright: (c) 2007 Arne Steinarson
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_TRACKER_H_
12 #define _WX_TRACKER_H_
16 class wxEventConnectionRef
;
18 // This class represents an object tracker and is stored in a linked list
19 // in the tracked object. It is only used in one of its derived forms.
20 class WXDLLIMPEXP_BASE wxTrackerNode
23 wxTrackerNode() : m_nxt(NULL
) { }
24 virtual ~wxTrackerNode() { }
26 virtual void OnObjectDestroy() = 0;
28 virtual wxEventConnectionRef
*ToEventConnection() { return NULL
; }
33 friend class wxTrackable
; // For list access
34 friend class wxEvtHandler
; // For list access
37 // Add-on base class for a trackable object.
41 void AddNode(wxTrackerNode
*prn
)
47 void RemoveNode(wxTrackerNode
*prn
)
49 for ( wxTrackerNode
**pprn
= &m_first
; *pprn
; pprn
= &(*pprn
)->m_nxt
)
58 wxFAIL_MSG( "removing invalid tracker node" );
61 wxTrackerNode
*GetFirst() const { return m_first
; }
64 // this class is only supposed to be used as a base class but never be
65 // created nor destroyed directly so all ctors and dtor are protected
67 wxTrackable() : m_first(NULL
) { }
69 // copy ctor and assignment operator intentionally do not copy m_first: the
70 // objects which track the original trackable shouldn't track the new copy
71 wxTrackable(const wxTrackable
& WXUNUSED(other
)) : m_first(NULL
) { }
72 wxTrackable
& operator=(const wxTrackable
& WXUNUSED(other
)) { return *this; }
74 // dtor is not virtual: this class is not supposed to be used
75 // polymorphically and adding a virtual table to it would add unwanted
79 // Notify all registered refs
82 wxTrackerNode
* const first
= m_first
;
83 m_first
= first
->m_nxt
;
84 first
->OnObjectDestroy();
88 wxTrackerNode
*m_first
;
91 #endif // _WX_TRACKER_H_