1 \section{Run time class information overview
}\label{runtimeclassoverview
}
3 Classes:
\helpref{wxObject
}{wxobject
},
\helpref{wxClassInfo
}{wxclassinfo
}.
5 One of the failings of C++ is that no run-time information is provided
6 about a class and its position in the inheritance hierarchy.
7 Another is that instances of a class cannot be created just by knowing the name of a class,
8 which makes facilities such as persistent storage hard to implement.
10 Most C++ GUI frameworks overcome these limitations by means of a set of
11 macros and functions and wxWindows (from version
1.62) is no exception.
12 Each class that you wish to be known the type system should have
13 a macro such as DECLARE
\_DYNAMIC\_CLASS just inside the class declaration.
14 The macro IMPLEMENT
\_DYNAMIC\_CLASS should be in the implementation file.
16 Variations on these
\helpref{macros
}{macros
} are used for multiple inheritance, and abstract
17 classes that cannot be instantiated dynamically or otherwise.
19 DECLARE
\_DYNAMIC\_CLASS inserts a static wxClassInfo declaration into the
20 class, initialized by IMPLEMENT
\_DYNAMIC\_CLASS. When initialized, the
21 wxClassInfo object inserts itself into a linked list (accessed through
22 wxClassInfo::first and wxClassInfo::next pointers). The linked list
23 is fully created by the time all global initialisation is done.
25 IMPLEMENT
\_DYNAMIC\_CLASS is a macro that not only initialises the static
26 wxClassInfo member, but defines a global function capable of creating a
27 dynamic object of the class in question. A pointer to this function is
28 stored in wxClassInfo, and is used when an object should be created
31 wxObject::IsKindOf uses the linked list of wxClassInfo. It takes
32 a wxClassInfo argument, so use CLASSINFO(className) to return an
33 appropriate wxClassInfo pointer to use in this function.
35 The function
\helpref{wxCreateDynamicObject
}{wxcreatedynamicobject
} can be used
36 to construct a new object of a given type, by supplying a string name.
37 If you have a pointer to the wxClassInfo object instead, then you
38 can simply call wxClassInfo::CreateObject.
40 \subsection{wxClassInfo
}\label{wxclassinfooverview
}
42 \overview{Run time class information overview
}{runtimeclassoverview
}
44 Class:
\helpref{wxClassInfo
}{wxclassinfo
}
46 This class stores meta-information about classes. An application
47 may use macros such as DECLARE
\_DYNAMIC\_CLASS and IMPLEMENT
\_DYNAMIC\_CLASS
48 to record run-time information about a class, including:
50 \begin{itemize
}\itemsep=
0pt
51 \item its position in the inheritance hierarchy;
52 \item the base class name(s) (up to two base classes are permitted);
53 \item a string representation of the class name;
54 \item a function that can be called to construct an instance of this class.
57 The DECLARE
\_... macros declare a static wxClassInfo variable in a class, which is initialized
58 by macros of the form IMPLEMENT
\_... in the implementation C++ file. Classes whose instances may be
59 constructed dynamically are given a global constructor function which returns a new object.
61 You can get the wxClassInfo for a class by using the CLASSINFO macro, e.g. CLASSINFO(wxFrame).
62 You can get the wxClassInfo for an object using wxObject::GetClassInfo.
64 See also
\helpref{wxObject
}{wxobject
} and
\helpref{wxCreateDynamicObject
}{wxcreatedynamicobject
}.
68 In a header file wx
\_frame.h:
71 class wxFrame: public wxWindow
73 DECLARE_DYNAMIC_CLASS(wxFrame)
82 In a C++ file wx
\_frame.cc:
85 IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
87 wxFrame::wxFrame(void)