switching to registry based type info
[wxWidgets.git] / src / common / xti.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/xti.cpp
3 // Purpose: runtime metadata information (extended class info
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 27/07/03
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
14 #pragma implementation "xti.h"
15 #endif
16
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WX_PRECOMP
25 #include "wx/hash.h"
26 #include "wx/object.h"
27 #endif
28
29 #if wxUSE_EXTENDED_RTTI
30
31 #include "wx/xti.h"
32 #include "wx/xml/xml.h"
33 #include "wx/tokenzr.h"
34 #include "wx/list.h"
35 #include <string.h>
36
37 #include "wx/beforestd.h"
38 #include <map>
39 #include <string>
40 #include "wx/afterstd.h"
41
42 using namespace std ;
43
44 // ----------------------------------------------------------------------------
45 // Enum Support
46 // ----------------------------------------------------------------------------
47
48 wxEnumData::wxEnumData( wxEnumMemberData* data )
49 {
50 m_members = data ;
51 for ( m_count = 0; m_members[m_count].m_name ; m_count++)
52 {} ;
53 }
54
55 bool wxEnumData::HasEnumMemberValue(const wxChar *name, int *value)
56 {
57 int i;
58 for (i = 0; m_members[i].m_name ; i++ )
59 {
60 if (!strcmp(name, m_members[i].m_name))
61 {
62 if ( value )
63 *value = m_members[i].m_value;
64 return true ;
65 }
66 }
67 return false ;
68 }
69
70 int wxEnumData::GetEnumMemberValue(const wxChar *name)
71 {
72 int i;
73 for (i = 0; m_members[i].m_name ; i++ )
74 {
75 if (!strcmp(name, m_members[i].m_name))
76 {
77 return m_members[i].m_value;
78 }
79 }
80 return 0 ;
81 }
82
83 const wxChar *wxEnumData::GetEnumMemberName(int value)
84 {
85 int i;
86 for (i = 0; m_members[i].m_name ; i++)
87 if (value == m_members[i].m_value)
88 return m_members[i].m_name;
89
90 return wxT("") ;
91 }
92
93 int wxEnumData::GetEnumMemberValueByIndex( int idx )
94 {
95 // we should cache the count in order to avoid out-of-bounds errors
96 return m_members[idx].m_value ;
97 }
98
99 const char * wxEnumData::GetEnumMemberNameByIndex( int idx )
100 {
101 // we should cache the count in order to avoid out-of-bounds errors
102 return m_members[idx].m_name ;
103 }
104
105 // ----------------------------------------------------------------------------
106 // Type Information
107 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
109 // value streaming
110 // ----------------------------------------------------------------------------
111
112 // streamer specializations
113 // for all built-in types
114
115 // bool
116
117 template<> void wxStringReadValue(const wxString &s , bool &data )
118 {
119 int intdata ;
120 wxSscanf(s, _T("%d"), &intdata ) ;
121 data = bool(intdata) ;
122 }
123
124 template<> void wxStringWriteValue(wxString &s , const bool &data )
125 {
126 s = wxString::Format("%d", data ) ;
127 }
128
129 // char
130
131 template<> void wxStringReadValue(const wxString &s , char &data )
132 {
133 int intdata ;
134 wxSscanf(s, _T("%d"), &intdata ) ;
135 data = char(intdata) ;
136 }
137
138 template<> void wxStringWriteValue(wxString &s , const char &data )
139 {
140 s = wxString::Format("%d", data ) ;
141 }
142
143 // unsigned char
144
145 template<> void wxStringReadValue(const wxString &s , unsigned char &data )
146 {
147 int intdata ;
148 wxSscanf(s, _T("%d"), &intdata ) ;
149 data = (unsigned char)(intdata) ;
150 }
151
152 template<> void wxStringWriteValue(wxString &s , const unsigned char &data )
153 {
154 s = wxString::Format("%d", data ) ;
155 }
156
157 // int
158
159 template<> void wxStringReadValue(const wxString &s , int &data )
160 {
161 wxSscanf(s, _T("%d"), &data ) ;
162 }
163
164 template<> void wxStringWriteValue(wxString &s , const int &data )
165 {
166 s = wxString::Format("%d", data ) ;
167 }
168
169 // unsigned int
170
171 template<> void wxStringReadValue(const wxString &s , unsigned int &data )
172 {
173 wxSscanf(s, _T("%d"), &data ) ;
174 }
175
176 template<> void wxStringWriteValue(wxString &s , const unsigned int &data )
177 {
178 s = wxString::Format("%d", data ) ;
179 }
180
181 // long
182
183 template<> void wxStringReadValue(const wxString &s , long &data )
184 {
185 wxSscanf(s, _T("%ld"), &data ) ;
186 }
187
188 template<> void wxStringWriteValue(wxString &s , const long &data )
189 {
190 s = wxString::Format("%ld", data ) ;
191 }
192
193 // unsigned long
194
195 template<> void wxStringReadValue(const wxString &s , unsigned long &data )
196 {
197 wxSscanf(s, _T("%ld"), &data ) ;
198 }
199
200 template<> void wxStringWriteValue(wxString &s , const unsigned long &data )
201 {
202 s = wxString::Format("%ld", data ) ;
203 }
204
205 // float
206
207 template<> void wxStringReadValue(const wxString &s , float &data )
208 {
209 wxSscanf(s, _T("%f"), &data ) ;
210 }
211
212 template<> void wxStringWriteValue(wxString &s , const float &data )
213 {
214 s = wxString::Format("%f", data ) ;
215 }
216
217 // double
218
219 template<> void wxStringReadValue(const wxString &s , double &data )
220 {
221 wxSscanf(s, _T("%lf"), &data ) ;
222 }
223
224 template<> void wxStringWriteValue(wxString &s , const double &data )
225 {
226 s = wxString::Format("%lf", data ) ;
227 }
228
229 // wxString
230
231 template<> void wxStringReadValue(const wxString &s , wxString &data )
232 {
233 data = s ;
234 }
235
236 template<> void wxStringWriteValue(wxString &s , const wxString &data )
237 {
238 s = data ;
239 }
240
241 // built-ins
242 //
243
244 wxBuiltInTypeInfo s_typeInfovoid( wxT_VOID , NULL , NULL , typeid(void).name() ) ;
245 wxBuiltInTypeInfo s_typeInfobool( wxT_BOOL , &wxToStringConverter<bool> , &wxFromStringConverter<bool>, typeid(bool).name()) ;
246 wxBuiltInTypeInfo s_typeInfochar( wxT_CHAR , &wxToStringConverter<char> , &wxFromStringConverter<char>, typeid(char).name()) ;
247 wxBuiltInTypeInfo s_typeInfounsignedchar( wxT_UCHAR , &wxToStringConverter< unsigned char > , &wxFromStringConverter<unsigned char>, typeid(unsigned char).name()) ;
248 wxBuiltInTypeInfo s_typeInfoint( wxT_INT , &wxToStringConverter<int> , &wxFromStringConverter<int>, typeid(int).name()) ;
249 wxBuiltInTypeInfo s_typeInfounsignedint( wxT_UINT , &wxToStringConverter<unsigned int> , &wxFromStringConverter<unsigned int>, typeid(unsigned int).name()) ;
250 wxBuiltInTypeInfo s_typeInfolong( wxT_LONG , &wxToStringConverter<long> , &wxFromStringConverter<long>, typeid(long).name()) ;
251 wxBuiltInTypeInfo s_typeInfounsignedlong( wxT_ULONG , &wxToStringConverter<unsigned long> , &wxFromStringConverter<unsigned long>, typeid(unsigned long).name()) ;
252 wxBuiltInTypeInfo s_typeInfofloat( wxT_FLOAT , &wxToStringConverter<float> , &wxFromStringConverter<float>, typeid(float).name()) ;
253 wxBuiltInTypeInfo s_typeInfodouble( wxT_DOUBLE , &wxToStringConverter<double> , &wxFromStringConverter<double>, typeid(double).name()) ;
254 wxBuiltInTypeInfo s_typeInfowxString( wxT_STRING , &wxToStringConverter<wxString> , &wxFromStringConverter<wxString>, typeid(wxString).name()) ;
255
256 // this are compiler induced specialization which are never used anywhere
257
258 WX_ILLEGAL_TYPE_SPECIALIZATION( char const * )
259 WX_ILLEGAL_TYPE_SPECIALIZATION( char * )
260 WX_ILLEGAL_TYPE_SPECIALIZATION( unsigned char * )
261 WX_ILLEGAL_TYPE_SPECIALIZATION( int * )
262 WX_ILLEGAL_TYPE_SPECIALIZATION( bool * )
263 WX_ILLEGAL_TYPE_SPECIALIZATION( long * )
264 WX_ILLEGAL_TYPE_SPECIALIZATION( wxString * )
265
266 WX_COLLECTION_TYPE_INFO( wxString , wxArrayString ) ;
267
268 template<> void wxCollectionToVariantArray( wxArrayString const &theArray, wxxVariantArray &value)
269 {
270 wxArrayCollectionToVariantArray( theArray , value ) ;
271 }
272
273 wxTypeInfoMap *wxTypeInfo::sm_typeTable = NULL ;
274
275 wxTypeInfo *wxTypeInfo::FindType(const wxChar *typeName)
276 {
277 wxTypeInfoMap::iterator iter = sm_typeTable->find(typeName) ;
278 wxASSERT_MSG( iter != sm_typeTable->end() , wxT("lookup for a non-existent type-info") ) ;
279 return (wxTypeInfo *)iter->second;
280 }
281
282 wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind , wxClassInfo* classInfo , converterToString_t to , converterFromString_t from , const wxString &name) :
283 wxTypeInfo( kind , to , from , name)
284 { wxASSERT_MSG( kind == wxT_OBJECT_PTR || kind == wxT_OBJECT , wxT("Illegal Kind for Enum Type")) ; m_classInfo = classInfo ;}
285
286 wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType , wxClassInfo* eventClass , converterToString_t to , converterFromString_t from ) :
287 wxTypeInfo ( wxT_DELEGATE , to , from , wxEmptyString )
288 { m_eventClass = eventClass ; m_eventType = eventType ;}
289
290 void wxTypeInfo::Register()
291 {
292 if ( sm_typeTable == NULL )
293 sm_typeTable = new wxTypeInfoMap() ;
294
295 if( !m_name.IsEmpty() )
296 (*sm_typeTable)[m_name] = this ;
297 }
298
299 void wxTypeInfo::Unregister()
300 {
301 if( !m_name.IsEmpty() )
302 sm_typeTable->erase(m_name);
303 }
304
305 // removing header dependancy on string tokenizer
306
307 void wxSetStringToArray( const wxString &s , wxArrayString &array )
308 {
309 wxStringTokenizer tokenizer(s, wxT("| \t\n"), wxTOKEN_STRTOK);
310 wxString flag;
311 array.Clear() ;
312 while (tokenizer.HasMoreTokens())
313 {
314 array.Add(tokenizer.GetNextToken()) ;
315 }
316 }
317
318 // ----------------------------------------------------------------------------
319 // wxClassInfo
320 // ----------------------------------------------------------------------------
321
322 wxPropertyInfo::~wxPropertyInfo()
323 {
324 if ( this == m_itsClass->m_firstProperty )
325 {
326 m_itsClass->m_firstProperty = m_next;
327 }
328 else
329 {
330 wxPropertyInfo *info = m_itsClass->m_firstProperty;
331 while (info)
332 {
333 if ( info->m_next == this )
334 {
335 info->m_next = m_next;
336 break;
337 }
338
339 info = info->m_next;
340 }
341 }
342 }
343
344 wxHandlerInfo::~wxHandlerInfo()
345 {
346 if ( this == m_itsClass->m_firstHandler )
347 {
348 m_itsClass->m_firstHandler = m_next;
349 }
350 else
351 {
352 wxHandlerInfo *info = m_itsClass->m_firstHandler;
353 while (info)
354 {
355 if ( info->m_next == this )
356 {
357 info->m_next = m_next;
358 break;
359 }
360
361 info = info->m_next;
362 }
363 }
364 }
365
366 const wxPropertyAccessor *wxClassInfo::FindAccessor(const char *PropertyName) const
367 {
368 const wxPropertyInfo* info = FindPropertyInfo( PropertyName ) ;
369
370 if ( info )
371 return info->GetAccessor() ;
372
373 return NULL ;
374 }
375
376 wxPropertyInfo *wxClassInfo::FindPropertyInfoInThisClass (const char *PropertyName) const
377 {
378 wxPropertyInfo* info = m_firstProperty ;
379
380 while( info )
381 {
382 if ( strcmp( info->GetName() , PropertyName ) == 0 )
383 return info ;
384 info = info->GetNext() ;
385 }
386
387 return 0;
388 }
389
390 const wxPropertyInfo *wxClassInfo::FindPropertyInfo (const char *PropertyName) const
391 {
392 const wxPropertyInfo* info = FindPropertyInfoInThisClass( PropertyName ) ;
393 if ( info )
394 return info ;
395
396 const wxClassInfo** parents = GetParents() ;
397 for ( int i = 0 ; parents[i] ; ++ i )
398 {
399 if ( ( info = parents[i]->FindPropertyInfo( PropertyName ) ) != NULL )
400 return info ;
401 }
402
403 return 0;
404 }
405
406 wxHandlerInfo *wxClassInfo::FindHandlerInfoInThisClass (const char *PropertyName) const
407 {
408 wxHandlerInfo* info = m_firstHandler ;
409
410 while( info )
411 {
412 if ( strcmp( info->GetName() , PropertyName ) == 0 )
413 return info ;
414 info = info->GetNext() ;
415 }
416
417 return 0;
418 }
419
420 const wxHandlerInfo *wxClassInfo::FindHandlerInfo (const char *PropertyName) const
421 {
422 const wxHandlerInfo* info = FindHandlerInfoInThisClass( PropertyName ) ;
423
424 if ( info )
425 return info ;
426
427 const wxClassInfo** parents = GetParents() ;
428 for ( int i = 0 ; parents[i] ; ++ i )
429 {
430 if ( ( info = parents[i]->FindHandlerInfo( PropertyName ) ) != NULL )
431 return info ;
432 }
433
434 return 0;
435 }
436
437 wxObjectStreamingCallback wxClassInfo::GetStreamingCallback() const
438 {
439 if ( m_streamingCallback )
440 return m_streamingCallback ;
441
442 wxObjectStreamingCallback retval = NULL ;
443 const wxClassInfo** parents = GetParents() ;
444 for ( int i = 0 ; parents[i] && retval == NULL ; ++ i )
445 {
446 retval = parents[i]->GetStreamingCallback() ;
447 }
448 return retval ;
449 }
450
451 bool wxClassInfo::BeforeWriteObject( const wxObject *obj, wxWriter *streamer , wxPersister *persister , wxxVariantArray &metadata) const
452 {
453 wxObjectStreamingCallback sb = GetStreamingCallback() ;
454 if ( sb )
455 return (*sb)(obj , streamer , persister , metadata ) ;
456
457 return true ;
458 }
459
460 void wxClassInfo::SetProperty(wxObject *object, const char *propertyName, const wxxVariant &value) const
461 {
462 const wxPropertyAccessor *accessor;
463
464 accessor = FindAccessor(propertyName);
465 wxASSERT(accessor->HasSetter());
466 accessor->SetProperty( object , value ) ;
467 }
468
469 wxxVariant wxClassInfo::GetProperty(wxObject *object, const char *propertyName) const
470 {
471 const wxPropertyAccessor *accessor;
472
473 accessor = FindAccessor(propertyName);
474 wxASSERT(accessor->HasGetter());
475 wxxVariant result ;
476 accessor->GetProperty(object,result);
477 return result ;
478 }
479
480 wxxVariantArray wxClassInfo::GetPropertyCollection(wxObject *object, const wxChar *propertyName) const
481 {
482 const wxPropertyAccessor *accessor;
483
484 accessor = FindAccessor(propertyName);
485 wxASSERT(accessor->HasGetter());
486 wxxVariantArray result ;
487 accessor->GetPropertyCollection(object,result);
488 return result ;
489 }
490
491 void wxClassInfo::AddToPropertyCollection(wxObject *object, const wxChar *propertyName , const wxxVariant& value) const
492 {
493 const wxPropertyAccessor *accessor;
494
495 accessor = FindAccessor(propertyName);
496 wxASSERT(accessor->HasAdder());
497 accessor->AddToPropertyCollection( object , value ) ;
498 }
499
500 void wxClassInfo::GetProperties( wxPropertyInfoMap &map ) const
501 {
502 const wxPropertyInfo *pi = GetFirstProperty() ;
503 while( pi )
504 {
505 if ( map.find( pi->GetName() ) == map.end() )
506 map[pi->GetName()] = (wxPropertyInfo*) pi ;
507
508 pi = pi->GetNext() ;
509 }
510
511 const wxClassInfo** parents = GetParents() ;
512 for ( int i = 0 ; parents[i] ; ++ i )
513 {
514 parents[i]->GetProperties( map ) ;
515 }
516 }
517
518 /*
519 VARIANT TO OBJECT
520 */
521
522 wxObject* wxxVariant::GetAsObject()
523 {
524 const wxClassTypeInfo *ti = dynamic_cast<const wxClassTypeInfo*>( m_data->GetTypeInfo() ) ;
525 if ( ti )
526 return ti->GetClassInfo()->VariantToInstance(*this) ;
527 else
528 return NULL ;
529 }
530
531 // ----------------------------------------------------------------------------
532 // wxDynamicObject support
533 // ----------------------------------------------------------------------------
534 //
535 // Dynamic Objects are objects that have a real superclass instance and carry their
536 // own attributes in a hash map. Like this it is possible to create the objects and
537 // stream them, as if their class information was already available from compiled data
538
539 struct wxDynamicObject::wxDynamicObjectInternal
540 {
541 map<string,wxxVariant> m_properties ;
542 } ;
543
544 // instantiates this object with an instance of its superclass
545 wxDynamicObject::wxDynamicObject(wxObject* superClassInstance, const wxDynamicClassInfo *info)
546 {
547 m_superClassInstance = superClassInstance ;
548 m_classInfo = info ;
549 m_data = new wxDynamicObjectInternal ;
550 }
551
552 wxDynamicObject::~wxDynamicObject()
553 {
554 delete m_data ;
555 delete m_superClassInstance ;
556 }
557
558 void wxDynamicObject::SetProperty (const wxChar *propertyName, const wxxVariant &value)
559 {
560 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
561 m_data->m_properties[propertyName] = value ;
562 }
563
564 wxxVariant wxDynamicObject::GetProperty (const wxChar *propertyName) const
565 {
566 wxASSERT_MSG(m_classInfo->FindPropertyInfoInThisClass(propertyName),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
567 return m_data->m_properties[propertyName] ;
568 }
569
570 // ----------------------------------------------------------------------------
571 // wxDynamiClassInfo
572 // ----------------------------------------------------------------------------
573
574 wxDynamicClassInfo::wxDynamicClassInfo( const wxChar *unitName, const wxChar *className , const wxClassInfo* superClass ) :
575 wxClassInfo( unitName, className , new const wxClassInfo*[2])
576 {
577 GetParents()[0] = superClass ;
578 GetParents()[1] = NULL ;
579 }
580
581 wxDynamicClassInfo::~wxDynamicClassInfo()
582 {
583 delete[] GetParents() ;
584 }
585
586 wxObject *wxDynamicClassInfo::AllocateObject() const
587 {
588 wxObject* parent = GetParents()[0]->AllocateObject() ;
589 return new wxDynamicObject( parent , this ) ;
590 }
591
592 void wxDynamicClassInfo::Create (wxObject *object, int paramCount, wxxVariant *params) const
593 {
594 wxDynamicObject *dynobj = dynamic_cast< wxDynamicObject *>( object ) ;
595 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::Create on an object other than wxDynamicObject") ) ;
596 GetParents()[0]->Create( dynobj->GetSuperClassInstance() , paramCount , params ) ;
597 }
598
599 // get number of parameters for constructor
600 int wxDynamicClassInfo::GetCreateParamCount() const
601 {
602 return GetParents()[0]->GetCreateParamCount() ;
603 }
604
605 // get i-th constructor parameter
606 const wxChar* wxDynamicClassInfo::GetCreateParamName(int i) const
607 {
608 return GetParents()[0]->GetCreateParamName( i ) ;
609 }
610
611 void wxDynamicClassInfo::SetProperty(wxObject *object, const char *propertyName, const wxxVariant &value) const
612 {
613 wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
614 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
615 if ( FindPropertyInfoInThisClass(propertyName) )
616 dynobj->SetProperty( propertyName , value ) ;
617 else
618 GetParents()[0]->SetProperty( dynobj->GetSuperClassInstance() , propertyName , value ) ;
619 }
620
621 wxxVariant wxDynamicClassInfo::GetProperty(wxObject *object, const char *propertyName) const
622 {
623 wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
624 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
625 if ( FindPropertyInfoInThisClass(propertyName) )
626 return dynobj->GetProperty( propertyName ) ;
627 else
628 return GetParents()[0]->GetProperty( dynobj->GetSuperClassInstance() , propertyName ) ;
629 }
630
631 void wxDynamicClassInfo::AddProperty( const wxChar *propertyName , const wxTypeInfo* typeInfo )
632 {
633 new wxPropertyInfo( m_firstProperty , this , propertyName , typeInfo->GetTypeName() , new wxGenericPropertyAccessor( propertyName ) , wxxVariant() ) ;
634 }
635
636 void wxDynamicClassInfo::AddHandler( const wxChar *handlerName , wxObjectEventFunction address , const wxClassInfo* eventClassInfo )
637 {
638 new wxHandlerInfo( m_firstHandler , this , handlerName , address , eventClassInfo ) ;
639 }
640
641 // removes an existing runtime-property
642 void wxDynamicClassInfo::RemoveProperty( const wxChar *propertyName )
643 {
644 delete FindPropertyInfoInThisClass(propertyName) ;
645 }
646
647 // removes an existing runtime-handler
648 void wxDynamicClassInfo::RemoveHandler( const wxChar *handlerName )
649 {
650 delete FindHandlerInfoInThisClass(handlerName) ;
651 }
652
653 // renames an existing runtime-property
654 void wxDynamicClassInfo::RenameProperty( const wxChar *oldPropertyName , const wxChar *newPropertyName )
655 {
656 wxPropertyInfo* pi = FindPropertyInfoInThisClass(oldPropertyName) ;
657 wxASSERT_MSG( pi ,wxT("not existing property") ) ;
658 pi->m_name = newPropertyName ;
659 dynamic_cast<wxGenericPropertyAccessor*>(pi->GetAccessor())->RenameProperty( oldPropertyName , newPropertyName ) ;
660 }
661
662 // renames an existing runtime-handler
663 void wxDynamicClassInfo::RenameHandler( const wxChar *oldHandlerName , const wxChar *newHandlerName )
664 {
665 wxASSERT_MSG(FindHandlerInfoInThisClass(oldHandlerName),wxT("not existing handler") ) ;
666 FindHandlerInfoInThisClass(oldHandlerName)->m_name = newHandlerName ;
667 }
668
669 // ----------------------------------------------------------------------------
670 // wxGenericPropertyAccessor
671 // ----------------------------------------------------------------------------
672
673 struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal
674 {
675 char filler ;
676 } ;
677
678 wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxString& propertyName )
679 : wxPropertyAccessor( NULL , NULL , NULL , NULL )
680 {
681 m_data = new wxGenericPropertyAccessorInternal ;
682 m_propertyName = propertyName ;
683 m_getterName = wxT("Get")+propertyName ;
684 m_setterName = wxT("Set")+propertyName ;
685 }
686
687 wxGenericPropertyAccessor::~wxGenericPropertyAccessor()
688 {
689 delete m_data ;
690 }
691 void wxGenericPropertyAccessor::SetProperty(wxObject *object, const wxxVariant &value) const
692 {
693 wxDynamicObject* dynobj = dynamic_cast< wxDynamicObject * >( object ) ;
694 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
695 dynobj->SetProperty(m_propertyName , value ) ;
696 }
697
698 void wxGenericPropertyAccessor::GetProperty(const wxObject *object, wxxVariant& value) const
699 {
700 const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject * >( object ) ;
701 wxASSERT_MSG( dynobj , wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
702 value = dynobj->GetProperty( m_propertyName ) ;
703 }
704 #endif