1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: runtime metadata information (extended class info)
4 // Author: Stefan Csomor
5 // Modified by: Francesco Montorsi
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 /////////////////////////////////////////////////////////////////////////////
15 // ----------------------------------------------------------------------------
16 // second part of xti headers, is included from object.h
17 // ----------------------------------------------------------------------------
19 #if wxUSE_EXTENDED_RTTI
21 class WXDLLIMPEXP_BASE wxDynamicObject
: public wxObject
23 friend class WXDLLIMPEXP_FWD_BASE wxDynamicClassInfo
;
25 // instantiates this object with an instance of its superclass
26 wxDynamicObject(wxObject
* superClassInstance
, const wxDynamicClassInfo
*info
) ;
27 virtual ~wxDynamicObject();
29 void SetProperty (const wxChar
*propertyName
, const wxAny
&value
);
30 wxAny
GetProperty (const wxChar
*propertyName
) const ;
32 // get the runtime identity of this object
33 wxClassInfo
*GetClassInfo() const
36 return (wxClassInfo
*) m_classInfo
;
38 wxDynamicClassInfo
*nonconst
= const_cast<wxDynamicClassInfo
*>(m_classInfo
);
39 return static_cast<wxClassInfo
*>(nonconst
);
43 wxObject
* GetSuperClassInstance() const
45 return m_superClassInstance
;
48 // removes an existing runtime-property
49 void RemoveProperty( const wxChar
*propertyName
) ;
51 // renames an existing runtime-property
52 void RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
) ;
54 wxObject
*m_superClassInstance
;
55 const wxDynamicClassInfo
*m_classInfo
;
56 struct wxDynamicObjectInternal
;
57 wxDynamicObjectInternal
*m_data
;
60 #include "wx/xtiprop.h"
62 // ----------------------------------------------------------------------------
63 // wxIMPLEMENT class macros for concrete classes
64 // ----------------------------------------------------------------------------
66 // Single inheritance with one base class
68 #define _DEFAULT_CONSTRUCTOR(name) \
69 wxObject* wxConstructorFor##name() \
72 #define _DEFAULT_CONVERTERS(name) \
73 wxObject* wxVariantOfPtrToObjectConverter##name ( const wxAny &data ) \
74 { return data.As( (name**)NULL ); } \
75 wxAny wxObjectToVariantConverter##name ( wxObject *data ) \
76 { return wxAny( wx_dynamic_cast(name*, data) ); }
78 #define _TYPEINFO_CLASSES(n, toString, fromString ) \
79 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT, &n::ms_classInfo, \
80 toString, fromString, typeid(n).name()); \
81 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR, &n::ms_classInfo, \
82 toString, fromString, typeid(n*).name());
84 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit, callback) \
85 _DEFAULT_CONSTRUCTOR(name) \
86 _DEFAULT_CONVERTERS(name) \
88 const wxClassInfo* name::ms_classParents[] = \
89 { &basename::ms_classInfo, NULL }; \
90 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
91 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
92 name::GetPropertiesStatic, name::GetHandlersStatic, name::ms_constructor, \
93 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
94 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
97 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
98 _DEFAULT_CONSTRUCTOR(name) \
99 _DEFAULT_CONVERTERS(name) \
100 void wxVariantToObjectConverter##name ( const wxAny &data, wxObjectFunctor* fn ) \
101 { (*fn)( &wxANY_AS(data, name) ); } \
103 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo,NULL }; \
104 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
105 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
106 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
107 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
108 wxVariantOfPtrToObjectConverter##name, wxVariantToObjectConverter##name, \
109 wxObjectToVariantConverter##name, callback);
111 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename ) \
112 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, "", NULL ) \
113 _TYPEINFO_CLASSES(name, NULL, NULL) \
114 const wxPropertyInfo *name::GetPropertiesStatic() \
115 { return (wxPropertyInfo*) NULL; } \
116 const wxHandlerInfo *name::GetHandlersStatic() \
117 { return (wxHandlerInfo*) NULL; } \
118 wxCONSTRUCTOR_DUMMY( name )
120 #define wxIMPLEMENT_DYNAMIC_CLASS( name, basename ) \
121 _IMPLEMENT_DYNAMIC_CLASS( name, basename, "", NULL ) \
122 _TYPEINFO_CLASSES(name, NULL, NULL) \
123 wxPropertyInfo *name::GetPropertiesStatic() \
124 { return (wxPropertyInfo*) NULL; } \
125 wxHandlerInfo *name::GetHandlersStatic() \
126 { return (wxHandlerInfo*) NULL; } \
127 wxCONSTRUCTOR_DUMMY( name )
129 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \
130 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, NULL ) \
131 _TYPEINFO_CLASSES(name, NULL, NULL)
133 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback )\
134 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, &callback ) \
135 _TYPEINFO_CLASSES(name, NULL, NULL)
137 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \
138 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
139 _TYPEINFO_CLASSES(name, NULL, NULL)
141 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
144 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
145 _TYPEINFO_CLASSES(name, toString, fromString)
147 // this is for classes that do not derive from wxObject, there are no creators for these
149 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) \
150 const wxClassInfo* name::ms_classParents[] = { NULL }; \
151 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
152 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
153 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
155 _TYPEINFO_CLASSES(name, NULL, NULL)
157 // this is for subclasses that still do not derive from wxObject
159 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) \
160 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo, NULL }; \
161 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
162 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
163 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
165 _TYPEINFO_CLASSES(name, NULL, NULL)
168 // Multiple inheritance with two base classes
170 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \
171 _DEFAULT_CONSTRUCTOR(name) \
172 _DEFAULT_CONVERTERS(name) \
174 const wxClassInfo* name::ms_classParents[] = \
175 { &basename::ms_classInfo,&basename2::ms_classInfo, NULL }; \
176 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
177 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
178 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
179 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
180 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
183 #define wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2) \
184 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, "", NULL) \
185 _TYPEINFO_CLASSES(name, NULL, NULL) \
186 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; } \
187 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
188 wxCONSTRUCTOR_DUMMY( name )
190 #define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) \
191 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, unit, NULL) \
192 _TYPEINFO_CLASSES(name, NULL, NULL)
196 // ----------------------------------------------------------------------------
197 // wxIMPLEMENT class macros for abstract classes
198 // ----------------------------------------------------------------------------
200 // Single inheritance with one base class
202 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
203 _DEFAULT_CONVERTERS(name) \
205 const wxClassInfo* name::ms_classParents[] = \
206 { &basename::ms_classInfo,NULL }; \
207 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
208 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
209 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
210 0, wxVariantOfPtrToObjectConverter##name,0, \
211 wxObjectToVariantConverter##name); \
212 _TYPEINFO_CLASSES(name, NULL, NULL)
214 #define wxIMPLEMENT_ABSTRACT_CLASS( name, basename ) \
215 _IMPLEMENT_ABSTRACT_CLASS( name, basename ) \
216 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
217 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; }
219 // Multiple inheritance with two base classes
221 #define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
222 wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
223 wxT(#basename2), (int) sizeof(name), \
224 (wxObjectConstructorFn) 0);
226 // templated streaming, every type must have their specialization for these methods
229 void wxStringReadValue( const wxString
&s
, T
&data
);
232 void wxStringWriteValue( wxString
&s
, const T
&data
);
235 void wxToStringConverter( const wxAny
&v
, wxString
&s
)
236 { wxStringWriteValue(s
, wxANY_AS(v
, T
)); }
239 void wxFromStringConverter( const wxString
&s
, wxAny
&v
)
240 { T d
; wxStringReadValue(s
, d
); v
= wxAny(d
); }
244 #endif // _WX_XTIH2__