]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: wx/wxt2.h | |
3 | // Purpose: runtime metadata information (extended class info) | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: Francesco Montorsi | |
6 | // Created: 27/07/03 | |
7 | // Copyright: (c) 1997 Julian Smart | |
8 | // (c) 2003 Stefan Csomor | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_XTI2H__ | |
12 | #define _WX_XTI2H__ | |
13 | ||
14 | // ---------------------------------------------------------------------------- | |
15 | // second part of xti headers, is included from object.h | |
16 | // ---------------------------------------------------------------------------- | |
17 | ||
18 | #if wxUSE_EXTENDED_RTTI | |
19 | ||
20 | // ---------------------------------------------------------------------------- | |
21 | // wxDynamicObject class, its instances connect to a 'super class instance' | |
22 | // ---------------------------------------------------------------------------- | |
23 | ||
24 | class WXDLLIMPEXP_BASE wxDynamicObject : public wxObject | |
25 | { | |
26 | friend class WXDLLIMPEXP_FWD_BASE wxDynamicClassInfo ; | |
27 | public: | |
28 | // instantiates this object with an instance of its superclass | |
29 | wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info) ; | |
30 | virtual ~wxDynamicObject(); | |
31 | ||
32 | void SetProperty (const wxChar *propertyName, const wxAny &value); | |
33 | wxAny GetProperty (const wxChar *propertyName) const ; | |
34 | ||
35 | // get the runtime identity of this object | |
36 | wxClassInfo *GetClassInfo() const | |
37 | { | |
38 | #ifdef _MSC_VER | |
39 | return (wxClassInfo*) m_classInfo; | |
40 | #else | |
41 | wxDynamicClassInfo *nonconst = const_cast<wxDynamicClassInfo *>(m_classInfo); | |
42 | return static_cast<wxClassInfo *>(nonconst); | |
43 | #endif | |
44 | } | |
45 | ||
46 | wxObject* GetSuperClassInstance() const | |
47 | { | |
48 | return m_superClassInstance ; | |
49 | } | |
50 | private : | |
51 | // removes an existing runtime-property | |
52 | void RemoveProperty( const wxChar *propertyName ) ; | |
53 | ||
54 | // renames an existing runtime-property | |
55 | void RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName ) ; | |
56 | ||
57 | wxObject *m_superClassInstance ; | |
58 | const wxDynamicClassInfo *m_classInfo; | |
59 | struct wxDynamicObjectInternal; | |
60 | wxDynamicObjectInternal *m_data; | |
61 | }; | |
62 | ||
63 | // ---------------------------------------------------------------------------- | |
64 | // String conversion templates supporting older compilers | |
65 | // ---------------------------------------------------------------------------- | |
66 | ||
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) | |
72 | #else | |
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); } | |
77 | ||
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); } | |
82 | #endif | |
83 | ||
84 | #include "wx/xtiprop.h" | |
85 | #include "wx/xtictor.h" | |
86 | ||
87 | // ---------------------------------------------------------------------------- | |
88 | // wxIMPLEMENT class macros for concrete classes | |
89 | // ---------------------------------------------------------------------------- | |
90 | ||
91 | // Single inheritance with one base class | |
92 | ||
93 | #define _DEFAULT_CONSTRUCTOR(name) \ | |
94 | wxObject* wxConstructorFor##name() \ | |
95 | { return new name; } | |
96 | ||
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) ); } | |
102 | ||
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()); | |
108 | ||
109 | #define _IMPLEMENT_DYNAMIC_CLASS(name, basename, unit, callback) \ | |
110 | _DEFAULT_CONSTRUCTOR(name) \ | |
111 | _DEFAULT_CONVERTERS(name) \ | |
112 | \ | |
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, \ | |
120 | callback); | |
121 | ||
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 ); } \ | |
127 | \ | |
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); | |
135 | ||
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 ) | |
144 | ||
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 ) | |
153 | ||
154 | #define wxIMPLEMENT_DYNAMIC_CLASS_XTI( name, basename, unit ) \ | |
155 | _IMPLEMENT_DYNAMIC_CLASS( name, basename, unit, NULL ) \ | |
156 | _TYPEINFO_CLASSES(name, NULL, NULL) | |
157 | ||
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) | |
161 | ||
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) | |
165 | ||
166 | #define wxIMPLEMENT_DYNAMIC_CLASS_WITH_COPY_AND_STREAMERS_XTI( name, basename, \ | |
167 | unit, toString, \ | |
168 | fromString ) \ | |
169 | _IMPLEMENT_DYNAMIC_CLASS_WITH_COPY( name, basename, unit, NULL ) \ | |
170 | _TYPEINFO_CLASSES(name, toString, fromString) | |
171 | ||
172 | // this is for classes that do not derive from wxObject, there are no creators for these | |
173 | ||
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, \ | |
179 | 0, 0, 0 ); \ | |
180 | _TYPEINFO_CLASSES(name, NULL, NULL) | |
181 | ||
182 | // this is for subclasses that still do not derive from wxObject | |
183 | ||
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, \ | |
189 | 0, 0, 0 ); \ | |
190 | _TYPEINFO_CLASSES(name, NULL, NULL) | |
191 | ||
192 | ||
193 | // Multiple inheritance with two base classes | |
194 | ||
195 | #define _IMPLEMENT_DYNAMIC_CLASS2(name, basename, basename2, unit, callback) \ | |
196 | _DEFAULT_CONSTRUCTOR(name) \ | |
197 | _DEFAULT_CONVERTERS(name) \ | |
198 | \ | |
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, \ | |
206 | callback); | |
207 | ||
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 ) | |
214 | ||
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) | |
218 | ||
219 | ||
220 | ||
221 | // ---------------------------------------------------------------------------- | |
222 | // wxIMPLEMENT class macros for abstract classes | |
223 | // ---------------------------------------------------------------------------- | |
224 | ||
225 | // Single inheritance with one base class | |
226 | ||
227 | #define _IMPLEMENT_ABSTRACT_CLASS(name, basename) \ | |
228 | _DEFAULT_CONVERTERS(name) \ | |
229 | \ | |
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) | |
238 | ||
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; } | |
243 | ||
244 | // Multiple inheritance with two base classes | |
245 | ||
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); | |
250 | ||
251 | // templated streaming, every type that can be converted to wxString | |
252 | // must have their specialization for these methods | |
253 | ||
254 | template<typename T> | |
255 | void wxStringReadValue( const wxString &s, T &data ); | |
256 | ||
257 | template<typename T> | |
258 | void wxStringWriteValue( wxString &s, const T &data); | |
259 | ||
260 | template<typename T> | |
261 | void wxToStringConverter( const wxAny &v, wxString &s ) | |
262 | { wxStringWriteValue(s, wxANY_AS(v, T)); } | |
263 | ||
264 | template<typename T> | |
265 | void wxFromStringConverter( const wxString &s, wxAny &v) | |
266 | { T d; wxStringReadValue(s, d); v = wxAny(d); } | |
267 | ||
268 | // -------------------------------------------------------------------------- | |
269 | // Collection Support | |
270 | // -------------------------------------------------------------------------- | |
271 | ||
272 | template<typename iter, typename collection_t > void wxListCollectionToAnyList( | |
273 | const collection_t& coll, wxAnyList &value ) | |
274 | { | |
275 | for ( iter current = coll.GetFirst(); current; | |
276 | current = current->GetNext() ) | |
277 | { | |
278 | value.Append( new wxAny(current->GetData()) ); | |
279 | } | |
280 | } | |
281 | ||
282 | template<typename collection_t> void wxArrayCollectionToVariantArray( | |
283 | const collection_t& coll, wxAnyList &value ) | |
284 | { | |
285 | for( size_t i = 0; i < coll.GetCount(); i++ ) | |
286 | { | |
287 | value.Append( new wxAny(coll[i]) ); | |
288 | } | |
289 | } | |
290 | ||
291 | #endif | |
292 | ||
293 | #endif // _WX_XTIH2__ |