]> git.saurik.com Git - wxWidgets.git/commitdiff
Put sample code back in, removed during conversion to Doxygen
authorRobert Roebling <robert@roebling.de>
Mon, 7 Apr 2008 10:46:15 +0000 (10:46 +0000)
committerRobert Roebling <robert@roebling.de>
Mon, 7 Apr 2008 10:46:15 +0000 (10:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53079 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/weakref.h

index f33ee605487acfc4bab26246beb304b2beed5ce9..903de9a87636f4f9cbdd0021a00d4e091dbe4826 100644 (file)
@@ -55,6 +55,42 @@ public:
     wxWeakRef<T> is a small object and the mechanism behind it is fast
     (@b O(1)). So the overall cost of using it is small.
 
+    Example
+    
+    @code
+    wxWindow *wnd = new wxWindow( parent, wxID_ANY, "wxWindow" );
+    wxWeakRef<wxWindow> wr = wnd;  
+    wxWindowRef wr2 = wnd;        // Same as above, but using a typedef
+    // Do things with window
+    wnd->Show( true );
+    // Weak ref is used like an ordinary pointer 
+    wr->Show( false );
+    wnd->Destroy(); 
+    // Now the weak ref has been reset, so we don't risk accessing
+    // a dangling pointer:
+    wxASSERT( wr==NULL );
+    @endcode
+
+    wxWeakRef<T> works for any objects that are derived from wxTrackable. By default,
+    wxEvtHandler and wxWindow derive from wxTrackable. However, wxObject does not, so
+    types like wxFont and wxColour are not trackable. The example below shows how to
+    create a wxObject derived class that is trackable:
+
+    @code
+    class wxMyTrackableObject : public wxObject, public wxTrackable
+    { 
+        // ... other members here 
+    }; 
+    @endcode
+
+    The following types of weak references are predefined:
+
+    @code
+    typedef wxWeakRef<wxEvtHandler>  wxEvtHandlerRef;
+    typedef wxWeakRef<wxWindow>      wxWindowRef;
+    @endcode
+
+
     @library{wxbase}
     @category{FIXME}