1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: runtime metadata information (extended class info)
4 // Author: Stefan Csomor
5 // Modified by: Francesco Montorsi
7 // Copyright: (c) 1997 Julian Smart
8 // (c) 2003 Stefan Csomor
9 /////////////////////////////////////////////////////////////////////////////
14 // ----------------------------------------------------------------------------
15 // second part of xti headers, is included from object.h
16 // ----------------------------------------------------------------------------
18 #if wxUSE_EXTENDED_RTTI
20 // ----------------------------------------------------------------------------
21 // wxDynamicObject class, its instances connect to a 'super class instance'
22 // ----------------------------------------------------------------------------
24 class WXDLLIMPEXP_BASE wxDynamicObject
: public wxObject
26 friend class WXDLLIMPEXP_FWD_BASE wxDynamicClassInfo
;
28 // instantiates this object with an instance of its superclass
29 wxDynamicObject(wxObject
* superClassInstance
, const wxDynamicClassInfo
*info
) ;
30 virtual ~wxDynamicObject();
32 void SetProperty (const wxChar
*propertyName
, const wxAny
&value
);
33 wxAny
GetProperty (const wxChar
*propertyName
) const ;
35 // get the runtime identity of this object
36 wxClassInfo
*GetClassInfo() const
39 return (wxClassInfo
*) m_classInfo
;
41 wxDynamicClassInfo
*nonconst
= const_cast<wxDynamicClassInfo
*>(m_classInfo
);
42 return static_cast<wxClassInfo
*>(nonconst
);
46 wxObject
* GetSuperClassInstance() const
48 return m_superClassInstance
;
51 // removes an existing runtime-property
52 void RemoveProperty( const wxChar
*propertyName
) ;
54 // renames an existing runtime-property
55 void RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
) ;
57 wxObject
*m_superClassInstance
;
58 const wxDynamicClassInfo
*m_classInfo
;
59 struct wxDynamicObjectInternal
;
60 wxDynamicObjectInternal
*m_data
;
63 // ----------------------------------------------------------------------------
64 // String conversion templates supporting older compilers
65 // ----------------------------------------------------------------------------
67 #if wxUSE_FUNC_TEMPLATE_POINTER
68 # define wxTO_STRING(type) wxToStringConverter<type>
69 # define wxTO_STRING_IMP(type)
70 # define wxFROM_STRING(type) wxFromStringConverter<type>
71 # define wxFROM_STRING_IMP(type)
73 # define wxTO_STRING(type) ToString##type
74 # define wxTO_STRING_IMP(type) \
75 inline void ToString##type( const wxAny& data, wxString &result ) \
76 { wxToStringConverter<type>(data, result); }
78 # define wxFROM_STRING(type) FromString##type
79 # define wxFROM_STRING_IMP(type) \
80 inline void FromString##type( const wxString& data, wxAny &result ) \
81 { wxFromStringConverter<type>(data, result); }
84 #include "wx/xtiprop.h"
85 #include "wx/xtictor.h"
87 // ----------------------------------------------------------------------------
88 // wxIMPLEMENT class macros for concrete classes
89 // ----------------------------------------------------------------------------
91 // Single inheritance with one base class
93 #define _DEFAULT_CONSTRUCTOR(name) \
94 wxObject* wxConstructorFor##name() \
97 #define _DEFAULT_CONVERTERS(name) \
98 wxObject* wxVariantOfPtrToObjectConverter##name ( const wxAny &data ) \
99 { return data.As( (name**)NULL ); } \
100 wxAny wxObjectToVariantConverter##name ( wxObject *data ) \
101 { return wxAny( wx_dynamic_cast(name*, data) ); }
103 #define _TYPEINFO_CLASSES(n, toString, fromString ) \
104 wxClassTypeInfo s_typeInfo##n(wxT_OBJECT, &n::ms_classInfo, \
105 toString, fromString, typeid(n).name()); \
106 wxClassTypeInfo s_typeInfoPtr##n(wxT_OBJECT_PTR, &n::ms_classInfo, \
107 toString, fromString, typeid(n*).name());
109 #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit, callback) \
110 _DEFAULT_CONSTRUCTOR(name) \
111 _DEFAULT_CONVERTERS(name) \
113 const wxClassInfo* name::ms_classParents[] = \
114 { &basename::ms_classInfo, NULL }; \
115 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
116 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
117 name::GetPropertiesStatic, name::GetHandlersStatic, name::ms_constructor, \
118 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
119 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
122 #define _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY(name, basename, unit, callback ) \
123 _DEFAULT_CONSTRUCTOR(name) \
124 _DEFAULT_CONVERTERS(name) \
125 void wxVariantToObjectConverter##name ( const wxAny &data, wxObjectFunctor* fn ) \
126 { name o = wxANY_AS(data, name); (*fn)( &o ); } \
128 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo,NULL }; \
129 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
130 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
131 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
132 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
133 wxVariantOfPtrToObjectConverter##name, wxVariantToObjectConverter##name, \
134 wxObjectToVariantConverter##name, callback);
136 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename ) \
137 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, "", NULL ) \
138 _TYPEINFO_CLASSES(name, NULL, NULL) \
139 const wxPropertyInfo *name::GetPropertiesStatic() \
140 { return (wxPropertyInfo*) NULL; } \
141 const wxHandlerInfo *name::GetHandlersStatic() \
142 { return (wxHandlerInfo*) NULL; } \
143 wxCONSTRUCTOR_DUMMY( name )
145 #define wxIMPLEMENT_DYNAMIC_CLASS( name, basename ) \
146 _IMPLEMENT_DYNAMIC_CLASS( name, basename, "", NULL ) \
147 _TYPEINFO_CLASSES(name, NULL, NULL) \
148 wxPropertyInfo *name::GetPropertiesStatic() \
149 { return (wxPropertyInfo*) NULL; } \
150 wxHandlerInfo *name::GetHandlersStatic() \
151 { return (wxHandlerInfo*) NULL; } \
152 wxCONSTRUCTOR_DUMMY( name )
154 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \
155 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, NULL ) \
156 _TYPEINFO_CLASSES(name, NULL, NULL)
158 #define wxIMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK( name, basename, unit, callback )\
159 _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, &callback ) \
160 _TYPEINFO_CLASSES(name, NULL, NULL)
162 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_XTI( name, basename, unit ) \
163 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
164 _TYPEINFO_CLASSES(name, NULL, NULL)
166 #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \
169 _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \
170 _TYPEINFO_CLASSES(name, toString, fromString)
172 // this is for classes that do not derive from wxObject, there are no creators for these
174 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_NO_BASE_XTI( name, unit ) \
175 const wxClassInfo* name::ms_classParents[] = { NULL }; \
176 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
177 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
178 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
180 _TYPEINFO_CLASSES(name, NULL, NULL)
182 // this is for subclasses that still do not derive from wxObject
184 #define wxIMPLEMENT_DYNAMIC_CLASS_NO_WXOBJECT_XTI( name, basename, unit ) \
185 const wxClassInfo* name::ms_classParents[] = { &basename::ms_classInfo, NULL }; \
186 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
187 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
188 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
190 _TYPEINFO_CLASSES(name, NULL, NULL)
193 // Multiple inheritance with two base classes
195 #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \
196 _DEFAULT_CONSTRUCTOR(name) \
197 _DEFAULT_CONVERTERS(name) \
199 const wxClassInfo* name::ms_classParents[] = \
200 { &basename::ms_classInfo,&basename2::ms_classInfo, NULL }; \
201 wxClassInfo name::ms_classInfo(name::ms_classParents, wxT(unit), \
202 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) wxConstructorFor##name, \
203 name::GetPropertiesStatic,name::GetHandlersStatic,name::ms_constructor, \
204 name::ms_constructorProperties, name::ms_constructorPropertiesCount, \
205 wxVariantOfPtrToObjectConverter##name, NULL, wxObjectToVariantConverter##name, \
208 #define wxIMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2) \
209 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, "", NULL) \
210 _TYPEINFO_CLASSES(name, NULL, NULL) \
211 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; } \
212 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
213 wxCONSTRUCTOR_DUMMY( name )
215 #define wxIMPLEMENT_DYNAMIC_CLASS2_XTI( name, basename, basename2, unit) \
216 _IMPLEMENT_DYNAMIC_CLASS2( name, basename, basename2, unit, NULL) \
217 _TYPEINFO_CLASSES(name, NULL, NULL)
221 // ----------------------------------------------------------------------------
222 // wxIMPLEMENT class macros for abstract classes
223 // ----------------------------------------------------------------------------
225 // Single inheritance with one base class
227 #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \
228 _DEFAULT_CONVERTERS(name) \
230 const wxClassInfo* name::ms_classParents[] = \
231 { &basename::ms_classInfo,NULL }; \
232 wxClassInfo name::ms_classInfo(name::ms_classParents, wxEmptyString, \
233 wxT(#name), (int) sizeof(name), (wxObjectConstructorFn) 0, \
234 name::GetPropertiesStatic,name::GetHandlersStatic, 0, 0, \
235 0, wxVariantOfPtrToObjectConverter##name,0, \
236 wxObjectToVariantConverter##name); \
237 _TYPEINFO_CLASSES(name, NULL, NULL)
239 #define wxIMPLEMENT_ABSTRACT_CLASS( name, basename ) \
240 _IMPLEMENT_ABSTRACT_CLASS( name, basename ) \
241 wxHandlerInfo *name::GetHandlersStatic() { return (wxHandlerInfo*) NULL; } \
242 wxPropertyInfo *name::GetPropertiesStatic() { return (wxPropertyInfo*) NULL; }
244 // Multiple inheritance with two base classes
246 #define wxIMPLEMENT_ABSTRACT_CLASS2(name, basename1, basename2) \
247 wxClassInfo name::ms_classInfo(wxT(#name), wxT(#basename1), \
248 wxT(#basename2), (int) sizeof(name), \
249 (wxObjectConstructorFn) 0);
251 // templated streaming, every type that can be converted to wxString
252 // 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__