improvements to wxWeakRef and related classes
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51187 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -467,6 +467,7 @@
|
||||
\input windowdc.tex
|
||||
\input destroyevt.tex
|
||||
\input weakref.tex
|
||||
\input weakrefdynamic.tex
|
||||
\input wnddisbl.tex
|
||||
\input wizard.tex
|
||||
\input wizevt.tex
|
||||
|
@@ -1,5 +1,4 @@
|
||||
|
||||
\section{\class{wxTrackableBase}}\label{wxtrackablebase}
|
||||
\section{\class{wxTrackable}}\label{wxtrackable}
|
||||
|
||||
Add-on base class for a trackable object. This class maintains
|
||||
an internal linked list of classes of type wxTrackerNode and
|
||||
@@ -10,7 +9,7 @@ API. Its only use is by deriving another class from it to
|
||||
make it trackable.
|
||||
|
||||
\begin{verbatim}
|
||||
class MyClass: public Foo, public TrackableBase
|
||||
class MyClass: public Foo, public wxTrackable
|
||||
{
|
||||
// whatever
|
||||
}
|
||||
@@ -31,18 +30,7 @@ No base class
|
||||
|
||||
\section{\class{wxTrackable}}\label{wxtrackable}
|
||||
|
||||
The only difference to \helpref{wxTrackableBase}{wxtrackablebase} is
|
||||
that this class adds a virtual table to enable dynamic\_cast query for
|
||||
wxTrackable.
|
||||
|
||||
\wxheading{Derived from}
|
||||
|
||||
\helpref{wxTrackableBase}{wxtrackablebase}
|
||||
|
||||
\wxheading{Include files}
|
||||
|
||||
<tracker.h>
|
||||
|
||||
\wxheading{Data structures}
|
||||
|
||||
|
||||
|
@@ -6,11 +6,11 @@ such as \helpref{wxEvtHandler}{wxevthandler}, \helpref{wxWindow}{wxwindow} and
|
||||
pointer, but when the object pointed is destroyed, the weak reference is
|
||||
automatically reset to a NULL pointer.
|
||||
|
||||
wxWeakref<T> can be used whenever one must keep a pointer to an object
|
||||
that does not directly own, and that may be destroyed before the object
|
||||
wxWeakRef<T> can be used whenever one must keep a pointer to an object
|
||||
that one does not directly own, and that may be destroyed before the object
|
||||
holding the reference.
|
||||
|
||||
wxWeakref<T> is a small object and the mechanism behind it is fast
|
||||
wxWeakRef<T> is a small object and the mechanism behind it is fast
|
||||
(\textbf{O(1)}). So the overall cost of using it is small.
|
||||
|
||||
|
||||
@@ -31,9 +31,8 @@ wxWeakref<T> is a small object and the mechanism behind it is fast
|
||||
wxASSERT( wr==NULL );
|
||||
\end{verbatim}
|
||||
|
||||
wxWeakref<T> works for any objects that are derived from
|
||||
\helpref{wxTrackableBase}{wxtrackablebase} or \helpref{wxTrackable}{wxtrackable}.
|
||||
By default, wxEvtHandler and wxWindow derive from wxTrackableBase. However,
|
||||
wxWeakRef<T> works for any objects that are derived from \helpref{wxTrackable}{wxtrackable}.
|
||||
By default, wxEvtHandler and wxWindow derive from wxTrackable. However,
|
||||
wxObject does not, so types like \helpref{wxFont}{wxfont} and
|
||||
\helpref{wxColour}{wxcolour} are not trackable. The example below shows how to
|
||||
create a wxObject derived class that is trackable:
|
||||
@@ -44,18 +43,11 @@ create a wxObject derived class that is trackable:
|
||||
};
|
||||
\end{verbatim}
|
||||
|
||||
\textbf{Note:} Custom trackable objects should derive from wxTrackable
|
||||
if one wants to reference them from a \texttt{wxWeakRef<wxObject>}. The
|
||||
difference between the two base classes is that wxTrackableBase
|
||||
has no virtual member functions (no VTable), and thus cannot be detected
|
||||
through \texttt{dynamic\_cast<>}.
|
||||
|
||||
\wxheading{Predefined types}
|
||||
|
||||
The following types of weak references are predefined:
|
||||
|
||||
\begin{verbatim}
|
||||
typedef wxWeakRef<wxObject> wxObjectRef;
|
||||
typedef wxWeakRef<wxEvtHandler> wxEvtHandlerRef;
|
||||
typedef wxWeakRef<wxWindow> wxWindowRef;
|
||||
\end{verbatim}
|
||||
@@ -134,7 +126,7 @@ method will cause an assert in debug mode.
|
||||
|
||||
\membersection{wxWeakRef<T>::operator=}\label{wxweakrefoperatorassign}
|
||||
|
||||
\func{T* operator}{operator=}{\param{T* }{pobj}}
|
||||
\func{T*}{operator=}{\param{T* }{pobj}}
|
||||
|
||||
Releases the currently tracked object and starts tracking {\it pobj}.
|
||||
A weak reference may be reset by passing {\it NULL} as {\it pobj}.
|
||||
@@ -142,12 +134,19 @@ A weak reference may be reset by passing {\it NULL} as {\it pobj}.
|
||||
|
||||
\membersection{wxWeakRef<T>::operator =}\label{wxweakrefoperatorassign2}
|
||||
|
||||
\func{T* operator}{operator =}{\param{wxWeakRef<T>\& }{wr}}
|
||||
\func{T*}{operator =}{\param{wxWeakRef<T>\& }{wr}}
|
||||
|
||||
Release currently tracked object and start tracking the same object as
|
||||
the wxWeakRef {\it wr}.
|
||||
|
||||
|
||||
\membersection{wxWeakRef<T>::Release}\label{wxweakrefrelease}
|
||||
|
||||
\func{void}{Release}{\void}
|
||||
|
||||
Release currently tracked object and rests object reference.
|
||||
|
||||
|
||||
\membersection{wxWeakRef<T>::OnObjectDestroy}\label{wxweakrefonobjectdestroy}
|
||||
|
||||
\func{virtual void}{OnObjectDestroy}{\void}
|
||||
|
20
docs/latex/wx/weakrefdynamic.tex
Normal file
20
docs/latex/wx/weakrefdynamic.tex
Normal file
@@ -0,0 +1,20 @@
|
||||
\section{\class{wxWeakRefDynamic<T>}}\label{wxweakrefdynamic}
|
||||
|
||||
wxWeakRefDynamic<T> is a template class for weak references that is used in
|
||||
the same way as wxWeakRef<T>. The only difference is that wxWeakRefDynamic
|
||||
defaults to using \texttt{dynamic\_cast<>} for establishing the object
|
||||
reference (while wxWeakRef defaults to \texttt{static\_cast<>}).
|
||||
|
||||
So, wxWeakRef will detect a type mismatch during compile time and will
|
||||
have a little better run-time performance. The role of wxWeakRefDynamic
|
||||
is to handle objects which derived type one does not know.
|
||||
|
||||
\textbf{Note:} wxWeakRef<T> selects an implementation based on the static type
|
||||
of T. If T does not have wxTrackable statically, it defaults to to a mixed-
|
||||
mode operation, where it uses \texttt{dynamic\_cast<>} as the last measure (if
|
||||
available from the compiler and enabled when building wxWidgets).
|
||||
|
||||
For general cases, wxWeakRef<T> is the better choice.
|
||||
|
||||
For API documentation, see: \helpref{wxWeakRef}{wxweakref}
|
||||
|
Reference in New Issue
Block a user