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 // ----------------------------------------------------------------------------
22 // wxDynamicObject class, its instances connect to a 'super class instance'
23 // ----------------------------------------------------------------------------
25 class WXDLLIMPEXP_BASE wxDynamicObject
: public wxObject
27 friend class WXDLLIMPEXP_FWD_BASE wxDynamicClassInfo
;
29 // instantiates this object with an instance of its superclass
30 wxDynamicObject(wxObject
* superClassInstance
, const wxDynamicClassInfo
*info
) ;
31 virtual ~wxDynamicObject();
33 void SetProperty (const wxChar
*propertyName
, const wxAny
&value
);
34 wxAny
GetProperty (const wxChar
*propertyName
) const ;
36 // get the runtime identity of this object
37 wxClassInfo
*GetClassInfo() const
40 return (wxClassInfo
*) m_classInfo
;
42 wxDynamicClassInfo
*nonconst
= const_cast<wxDynamicClassInfo
*>(m_classInfo
);
43 return static_cast<wxClassInfo
*>(nonconst
);
47 wxObject
* GetSuperClassInstance() const
49 return m_superClassInstance
;
52 // removes an existing runtime-property
53 void RemoveProperty( const wxChar
*propertyName
) ;
55 // renames an existing runtime-property
56 void RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
) ;
58 wxObject
*m_superClassInstance
;
59 const wxDynamicClassInfo
*m_classInfo
;
60 struct wxDynamicObjectInternal
;
61 wxDynamicObjectInternal
*m_data
;
64 // ----------------------------------------------------------------------------
65 // String conversion templates supporting older compilers
66 // ----------------------------------------------------------------------------
68 #if wxUSE_FUNC_TEMPLATE_POINTER
69 # define wxTO_STRING(type) wxToStringConverter<type>
70 # define wxTO_STRING_IMP(type)
71 # define wxFROM_STRING(type) wxFromStringConverter<type>
72 # define wxFROM_STRING_IMP(type)
74 # define wxTO_STRING(type) ToString##type
75 # define wxTO_STRING_IMP(type) \
76 inline void ToString##type( const wxAny& data, wxString &result ) \
77 { wxToStringConverter<type>(data, result); }
79 # define wxFROM_STRING(type) FromString##type
80 # define wxFROM_STRING_IMP(type) \
81 inline void FromString##type( const wxString& data, wxAny &result ) \
82 { wxFromStringConverter<type>(data, result); }
85 #include "wx/xtiprop.h"
86 #include "wx/xtictor.h"
88 // ----------------------------------------------------------------------------
89 // wxIMPLEMENT class macros for concrete classes
90 // ----------------------------------------------------------------------------
92 // Single inheritance with one base class
94 #define _DEFAULT_CONSTRUCTOR(name) \
95 wxObject* wxConstructorFor##name() \
98 #define _DEFAULT_CONVERTERS(name) \
99 wxObject* wxVariantOfPtrToObjectConverter##name ( const wxAny &data ) \
100 { return data.As( (name**)NULL ); } \
101 wxAny wxObjectToVariantConverter##name ( wxObject *data ) \
102 { return wxAny( wx_dynamic_cast(name*, data) ); }
104 #define _TYPEINFO_CLASSES(n, toString, fromString ) \
105 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT, &n::ms_classInfo, \
106 toString, fromString, typeid(n).name()); \
107 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR, &n::ms_classInfo, \
108 toString, fromString, typeid(n*).name());
110 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit, callback) \
111 _DEFAULT_CONSTRUCTOR(name) \
112 _DEFAULT_CONVERTERS(name) \
114 const wxClassInfo* name::ms_classParents[] = \
115 { &basename::ms_classInfo, NULL }; \
116 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
117 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
118 name::GetPropertiesStatic, name::GetHandlersStatic, name::ms_constructor, \
119 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
120 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
123 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
124 _DEFAULT_CONSTRUCTOR(name) \
125 _DEFAULT_CONVERTERS(name) \
126 void wxVariantToObjectConverter##name ( const wxAny &data, wxObjectFunctor* fn ) \
127 { (*fn)( &wxANY_AS(data, name) ); } \
129 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo,NULL }; \
130 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
131 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
132 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
133 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
134 wxVariantOfPtrToObjectConverter##name, wxVariantToObjectConverter##name, \
135 wxObjectToVariantConverter##name, callback);
137 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename ) \
138 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, "", NULL ) \
139 _TYPEINFO_CLASSES(name, NULL, NULL) \
140 const wxPropertyInfo *name::GetPropertiesStatic() \
141 { return (wxPropertyInfo*) NULL; } \
142 const wxHandlerInfo *name::GetHandlersStatic() \
143 { return (wxHandlerInfo*) NULL; } \
144 wxCONSTRUCTOR_DUMMY( name )
146 #define wxIMPLEMENT_DYNAMIC_CLASS( name, basename ) \
147 _IMPLEMENT_DYNAMIC_CLASS( name, basename, "", NULL ) \
148 _TYPEINFO_CLASSES(name, NULL, NULL) \
149 wxPropertyInfo *name::GetPropertiesStatic() \
150 { return (wxPropertyInfo*) NULL; } \
151 wxHandlerInfo *name::GetHandlersStatic() \
152 { return (wxHandlerInfo*) NULL; } \
153 wxCONSTRUCTOR_DUMMY( name )
155 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \
156 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, NULL ) \
157 _TYPEINFO_CLASSES(name, NULL, NULL)
159 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback )\
160 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, &callback ) \
161 _TYPEINFO_CLASSES(name, NULL, NULL)
163 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \
164 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
165 _TYPEINFO_CLASSES(name, NULL, NULL)
167 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
170 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
171 _TYPEINFO_CLASSES(name, toString, fromString)
173 // this is for classes that do not derive from wxObject, there are no creators for these
175 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) \
176 const wxClassInfo* name::ms_classParents[] = { NULL }; \
177 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
178 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
179 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
181 _TYPEINFO_CLASSES(name, NULL, NULL)
183 // this is for subclasses that still do not derive from wxObject
185 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) \
186 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo, NULL }; \
187 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
188 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
189 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
191 _TYPEINFO_CLASSES(name, NULL, NULL)
194 // Multiple inheritance with two base classes
196 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \
197 _DEFAULT_CONSTRUCTOR(name) \
198 _DEFAULT_CONVERTERS(name) \
200 const wxClassInfo* name::ms_classParents[] = \
201 { &basename::ms_classInfo,&basename2::ms_classInfo, NULL }; \
202 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
203 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
204 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
205 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
206 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
209 #define wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2) \
210 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, "", NULL) \
211 _TYPEINFO_CLASSES(name, NULL, NULL) \
212 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; } \
213 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
214 wxCONSTRUCTOR_DUMMY( name )
216 #define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) \
217 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, unit, NULL) \
218 _TYPEINFO_CLASSES(name, NULL, NULL)
222 // ----------------------------------------------------------------------------
223 // wxIMPLEMENT class macros for abstract classes
224 // ----------------------------------------------------------------------------
226 // Single inheritance with one base class
228 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
229 _DEFAULT_CONVERTERS(name) \
231 const wxClassInfo* name::ms_classParents[] = \
232 { &basename::ms_classInfo,NULL }; \
233 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
234 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
235 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
236 0, wxVariantOfPtrToObjectConverter##name,0, \
237 wxObjectToVariantConverter##name); \
238 _TYPEINFO_CLASSES(name, NULL, NULL)
240 #define wxIMPLEMENT_ABSTRACT_CLASS( name, basename ) \
241 _IMPLEMENT_ABSTRACT_CLASS( name, basename ) \
242 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
243 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; }
245 // Multiple inheritance with two base classes
247 #define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
248 wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
249 wxT(#basename2), (int) sizeof(name), \
250 (wxObjectConstructorFn) 0);
252 // templated streaming, every type must have their specialization for these methods
255 void wxStringReadValue( const wxString
&s
, T
&data
);
258 void wxStringWriteValue( wxString
&s
, const T
&data
);
261 void wxToStringConverter( const wxAny
&v
, wxString
&s
)
262 { wxStringWriteValue(s
, wxANY_AS(v
, T
)); }
265 void wxFromStringConverter( const wxString
&s
, wxAny
&v
)
266 { T d
; wxStringReadValue(s
, d
); v
= wxAny(d
); }
268 // --------------------------------------------------------------------------
269 // Collection Support
270 // --------------------------------------------------------------------------
272 template<typename iter
, typename collection_t
> void wxListCollectionToAnyList(
273 const collection_t
& coll
, wxAnyList
&value
)
275 for ( iter current
= coll
.GetFirst(); current
;
276 current
= current
->GetNext() )
278 value
.Append( new wxAny(current
->GetData()) );
282 template<typename collection_t
> void wxArrayCollectionToVariantArray(
283 const collection_t
& coll
, wxAnyList
&value
)
285 for( size_t i
= 0; i
< coll
.GetCount(); i
++ )
287 value
.Append( new wxAny(coll
[i
]) );
293 #endif // _WX_XTIH2__