+
+protected:
+ wxWeakRefImpl() : m_pobj(NULL), m_ptbase(NULL) { }
+
+ // Assign receives most derived class here and can use that
+ template <class TDerived>
+ void Assign( TDerived* pobj )
+ {
+ AssignHelper( pobj, wxInt2Type<wxIsStaticTrackable<TDerived>::value>() );
+ }
+
+ template <class TDerived>
+ void AssignHelper(TDerived* pobj, wxInt2Type<true>)
+ {
+ wxTrackable *ptbase = static_cast<wxTrackable*>(pobj);
+ DoAssign( pobj, ptbase );
+ }
+
+#ifdef HAVE_DYNAMIC_CAST
+ void AssignHelper(T* pobj, wxInt2Type<false>)
+ {
+ // A last way to get a trackable pointer
+ wxTrackable *ptbase = dynamic_cast<wxTrackable*>(pobj);
+ if ( ptbase )
+ {
+ DoAssign( pobj, ptbase );
+ }
+ else
+ {
+ wxFAIL_MSG( "Tracked class should inherit from wxTrackable" );
+
+ Release();
+ }
+ }
+#endif // HAVE_DYNAMIC_CAST
+
+ void AssignCopy(const wxWeakRefImpl& wr)
+ {
+ DoAssign(wr.m_pobj, wr.m_ptbase);
+ }
+
+ void DoAssign( T* pobj, wxTrackable *ptbase ) {
+ if( m_pobj==pobj ) return;
+ Release();
+
+ // Now set new trackable object
+ if( pobj )
+ {
+ // Add ourselves to object tracker list
+ wxASSERT( ptbase );
+ ptbase->AddNode( this );
+ m_pobj = pobj;
+ m_ptbase = ptbase;
+ }
+ }
+