1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/xti.cpp
3 // Purpose: runtime metadata information (extended class info
4 // Author: Stefan Csomor
8 // Copyright: (c) 1997 Julian Smart
9 // (c) 2003 Stefan Csomor
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
14 #pragma implementation "xti.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
26 #include "wx/object.h"
29 #if wxUSE_EXTENDED_RTTI
32 #include "wx/xml/xml.h"
33 #include "wx/tokenzr.h"
37 #include "wx/beforestd.h"
41 #include "wx/afterstd.h"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 wxEnumData::wxEnumData( wxEnumMemberData
* data
)
52 for ( m_count
= 0; m_members
[m_count
].m_name
; m_count
++)
56 bool wxEnumData::HasEnumMemberValue(const wxChar
*name
, int *value
) const
59 for (i
= 0; m_members
[i
].m_name
; i
++ )
61 if (!wxStrcmp(name
, m_members
[i
].m_name
))
64 *value
= m_members
[i
].m_value
;
71 int wxEnumData::GetEnumMemberValue(const wxChar
*name
) const
74 for (i
= 0; m_members
[i
].m_name
; i
++ )
76 if (!wxStrcmp(name
, m_members
[i
].m_name
))
78 return m_members
[i
].m_value
;
84 const wxChar
*wxEnumData::GetEnumMemberName(int value
) const
87 for (i
= 0; m_members
[i
].m_name
; i
++)
88 if (value
== m_members
[i
].m_value
)
89 return m_members
[i
].m_name
;
94 int wxEnumData::GetEnumMemberValueByIndex( int idx
) const
96 // we should cache the count in order to avoid out-of-bounds errors
97 return m_members
[idx
].m_value
;
100 const wxChar
* wxEnumData::GetEnumMemberNameByIndex( int idx
) const
102 // we should cache the count in order to avoid out-of-bounds errors
103 return m_members
[idx
].m_name
;
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // ----------------------------------------------------------------------------
113 // streamer specializations
114 // for all built-in types
118 template<> void wxStringReadValue(const wxString
&s
, bool &data
)
121 wxSscanf(s
, _T("%d"), &intdata
) ;
122 data
= (bool)intdata
;
125 template<> void wxStringWriteValue(wxString
&s
, const bool &data
)
127 s
= wxString::Format(_T("%d"), data
) ;
132 template<> void wxStringReadValue(const wxString
&s
, char &data
)
135 wxSscanf(s
, _T("%d"), &intdata
) ;
136 data
= char(intdata
) ;
139 template<> void wxStringWriteValue(wxString
&s
, const char &data
)
141 s
= wxString::Format(_T("%d"), data
) ;
146 template<> void wxStringReadValue(const wxString
&s
, unsigned char &data
)
149 wxSscanf(s
, _T("%d"), &intdata
) ;
150 data
= (unsigned char)(intdata
) ;
153 template<> void wxStringWriteValue(wxString
&s
, const unsigned char &data
)
155 s
= wxString::Format(_T("%d"), data
) ;
160 template<> void wxStringReadValue(const wxString
&s
, int &data
)
162 wxSscanf(s
, _T("%d"), &data
) ;
165 template<> void wxStringWriteValue(wxString
&s
, const int &data
)
167 s
= wxString::Format(_T("%d"), data
) ;
172 template<> void wxStringReadValue(const wxString
&s
, unsigned int &data
)
174 wxSscanf(s
, _T("%d"), &data
) ;
177 template<> void wxStringWriteValue(wxString
&s
, const unsigned int &data
)
179 s
= wxString::Format(_T("%d"), data
) ;
184 template<> void wxStringReadValue(const wxString
&s
, long &data
)
186 wxSscanf(s
, _T("%ld"), &data
) ;
189 template<> void wxStringWriteValue(wxString
&s
, const long &data
)
191 s
= wxString::Format(_T("%ld"), data
) ;
196 template<> void wxStringReadValue(const wxString
&s
, unsigned long &data
)
198 wxSscanf(s
, _T("%ld"), &data
) ;
201 template<> void wxStringWriteValue(wxString
&s
, const unsigned long &data
)
203 s
= wxString::Format(_T("%ld"), data
) ;
208 template<> void wxStringReadValue(const wxString
&s
, float &data
)
210 wxSscanf(s
, _T("%f"), &data
) ;
213 template<> void wxStringWriteValue(wxString
&s
, const float &data
)
215 s
= wxString::Format(_T("%f"), data
) ;
220 template<> void wxStringReadValue(const wxString
&s
, double &data
)
222 wxSscanf(s
, _T("%lf"), &data
) ;
225 template<> void wxStringWriteValue(wxString
&s
, const double &data
)
227 s
= wxString::Format(_T("%lf"), data
) ;
232 template<> void wxStringReadValue(const wxString
&s
, wxString
&data
)
237 template<> void wxStringWriteValue(wxString
&s
, const wxString
&data
)
245 wxBuiltInTypeInfo
s_typeInfovoid( wxT_VOID
, NULL
, NULL
, typeid(void).name() ) ;
246 wxBuiltInTypeInfo
s_typeInfobool( wxT_BOOL
, &wxToStringConverter
<bool> , &wxFromStringConverter
<bool>, typeid(bool).name()) ;
247 wxBuiltInTypeInfo
s_typeInfochar( wxT_CHAR
, &wxToStringConverter
<char> , &wxFromStringConverter
<char>, typeid(char).name()) ;
248 wxBuiltInTypeInfo
s_typeInfounsignedchar( wxT_UCHAR
, &wxToStringConverter
< unsigned char > , &wxFromStringConverter
<unsigned char>, typeid(unsigned char).name()) ;
249 wxBuiltInTypeInfo
s_typeInfoint( wxT_INT
, &wxToStringConverter
<int> , &wxFromStringConverter
<int>, typeid(int).name()) ;
250 wxBuiltInTypeInfo
s_typeInfounsignedint( wxT_UINT
, &wxToStringConverter
<unsigned int> , &wxFromStringConverter
<unsigned int>, typeid(unsigned int).name()) ;
251 wxBuiltInTypeInfo
s_typeInfolong( wxT_LONG
, &wxToStringConverter
<long> , &wxFromStringConverter
<long>, typeid(long).name()) ;
252 wxBuiltInTypeInfo
s_typeInfounsignedlong( wxT_ULONG
, &wxToStringConverter
<unsigned long> , &wxFromStringConverter
<unsigned long>, typeid(unsigned long).name()) ;
253 wxBuiltInTypeInfo
s_typeInfofloat( wxT_FLOAT
, &wxToStringConverter
<float> , &wxFromStringConverter
<float>, typeid(float).name()) ;
254 wxBuiltInTypeInfo
s_typeInfodouble( wxT_DOUBLE
, &wxToStringConverter
<double> , &wxFromStringConverter
<double>, typeid(double).name()) ;
255 wxBuiltInTypeInfo
s_typeInfowxString( wxT_STRING
, &wxToStringConverter
<wxString
> , &wxFromStringConverter
<wxString
>, typeid(wxString
).name()) ;
257 // this are compiler induced specialization which are never used anywhere
259 wxILLEGAL_TYPE_SPECIALIZATION( char const * )
260 wxILLEGAL_TYPE_SPECIALIZATION( char * )
261 wxILLEGAL_TYPE_SPECIALIZATION( unsigned char * )
262 wxILLEGAL_TYPE_SPECIALIZATION( int * )
263 wxILLEGAL_TYPE_SPECIALIZATION( bool * )
264 wxILLEGAL_TYPE_SPECIALIZATION( long * )
265 wxILLEGAL_TYPE_SPECIALIZATION( wxString
* )
267 wxCOLLECTION_TYPE_INFO( wxString
, wxArrayString
) ;
269 template<> void wxCollectionToVariantArray( wxArrayString
const &theArray
, wxxVariantArray
&value
)
271 wxArrayCollectionToVariantArray( theArray
, value
) ;
274 wxTypeInfoMap
*wxTypeInfo::ms_typeTable
= NULL
;
276 wxTypeInfo
*wxTypeInfo::FindType(const wxChar
*typeName
)
278 wxTypeInfoMap::iterator iter
= ms_typeTable
->find(typeName
) ;
279 wxASSERT_MSG( iter
!= ms_typeTable
->end() , wxT("lookup for a non-existent type-info") ) ;
280 return (wxTypeInfo
*)iter
->second
;
284 wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
, converterFromString_t from
, const char *name
) :
285 wxTypeInfo( kind
, to
, from
, name
)
286 { wxASSERT_MSG( kind
== wxT_OBJECT_PTR
|| kind
== wxT_OBJECT
, wxT("Illegal Kind for Enum Type")) ; m_classInfo
= classInfo
;}
289 wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
, converterToString_t to
, converterFromString_t from
, const wxString
&name
) :
290 wxTypeInfo( kind
, to
, from
, name
)
291 { wxASSERT_MSG( kind
== wxT_OBJECT_PTR
|| kind
== wxT_OBJECT
, wxT("Illegal Kind for Enum Type")) ; m_classInfo
= classInfo
;}
293 wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType
, wxClassInfo
* eventClass
, converterToString_t to
, converterFromString_t from
) :
294 wxTypeInfo ( wxT_DELEGATE
, to
, from
, wxEmptyString
)
295 { m_eventClass
= eventClass
; m_eventType
= eventType
; m_lastEventType
= -1 ;}
297 wxDelegateTypeInfo::wxDelegateTypeInfo( int eventType
, int lastEventType
, wxClassInfo
* eventClass
, converterToString_t to
, converterFromString_t from
) :
298 wxTypeInfo ( wxT_DELEGATE
, to
, from
, wxEmptyString
)
299 { m_eventClass
= eventClass
; m_eventType
= eventType
; m_lastEventType
= lastEventType
; }
301 void wxTypeInfo::Register()
303 if ( ms_typeTable
== NULL
)
304 ms_typeTable
= new wxTypeInfoMap() ;
306 if( !m_name
.IsEmpty() )
307 (*ms_typeTable
)[m_name
] = this ;
310 void wxTypeInfo::Unregister()
312 if( !m_name
.IsEmpty() )
313 ms_typeTable
->erase(m_name
);
316 // removing header dependancy on string tokenizer
318 void wxSetStringToArray( const wxString
&s
, wxArrayString
&array
)
320 wxStringTokenizer
tokenizer(s
, wxT("| \t\n"), wxTOKEN_STRTOK
);
323 while (tokenizer
.HasMoreTokens())
325 array
.Add(tokenizer
.GetNextToken()) ;
329 // ----------------------------------------------------------------------------
331 // ----------------------------------------------------------------------------
333 wxPropertyInfo::~wxPropertyInfo()
335 if ( this == m_itsClass
->m_firstProperty
)
337 m_itsClass
->m_firstProperty
= m_next
;
341 wxPropertyInfo
*info
= m_itsClass
->m_firstProperty
;
344 if ( info
->m_next
== this )
346 info
->m_next
= m_next
;
355 wxHandlerInfo::~wxHandlerInfo()
357 if ( this == m_itsClass
->m_firstHandler
)
359 m_itsClass
->m_firstHandler
= m_next
;
363 wxHandlerInfo
*info
= m_itsClass
->m_firstHandler
;
366 if ( info
->m_next
== this )
368 info
->m_next
= m_next
;
377 const wxPropertyAccessor
*wxClassInfo::FindAccessor(const wxChar
*PropertyName
) const
379 const wxPropertyInfo
* info
= FindPropertyInfo( PropertyName
) ;
382 return info
->GetAccessor() ;
387 wxPropertyInfo
*wxClassInfo::FindPropertyInfoInThisClass (const wxChar
*PropertyName
) const
389 wxPropertyInfo
* info
= m_firstProperty
;
393 if ( wxStrcmp( info
->GetName() , PropertyName
) == 0 )
395 info
= info
->GetNext() ;
401 const wxPropertyInfo
*wxClassInfo::FindPropertyInfo (const wxChar
*PropertyName
) const
403 const wxPropertyInfo
* info
= FindPropertyInfoInThisClass( PropertyName
) ;
407 const wxClassInfo
** parents
= GetParents() ;
408 for ( int i
= 0 ; parents
[i
] ; ++ i
)
410 if ( ( info
= parents
[i
]->FindPropertyInfo( PropertyName
) ) != NULL
)
417 wxHandlerInfo
*wxClassInfo::FindHandlerInfoInThisClass (const wxChar
*PropertyName
) const
419 wxHandlerInfo
* info
= m_firstHandler
;
423 if ( wxStrcmp( info
->GetName() , PropertyName
) == 0 )
425 info
= info
->GetNext() ;
431 const wxHandlerInfo
*wxClassInfo::FindHandlerInfo (const wxChar
*PropertyName
) const
433 const wxHandlerInfo
* info
= FindHandlerInfoInThisClass( PropertyName
) ;
438 const wxClassInfo
** parents
= GetParents() ;
439 for ( int i
= 0 ; parents
[i
] ; ++ i
)
441 if ( ( info
= parents
[i
]->FindHandlerInfo( PropertyName
) ) != NULL
)
448 wxObjectStreamingCallback
wxClassInfo::GetStreamingCallback() const
450 if ( m_streamingCallback
)
451 return m_streamingCallback
;
453 wxObjectStreamingCallback retval
= NULL
;
454 const wxClassInfo
** parents
= GetParents() ;
455 for ( int i
= 0 ; parents
[i
] && retval
== NULL
; ++ i
)
457 retval
= parents
[i
]->GetStreamingCallback() ;
462 bool wxClassInfo::BeforeWriteObject( const wxObject
*obj
, wxWriter
*streamer
, wxPersister
*persister
, wxxVariantArray
&metadata
) const
464 wxObjectStreamingCallback sb
= GetStreamingCallback() ;
466 return (*sb
)(obj
, streamer
, persister
, metadata
) ;
471 void wxClassInfo::SetProperty(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
&value
) const
473 const wxPropertyAccessor
*accessor
;
475 accessor
= FindAccessor(propertyName
);
476 wxASSERT(accessor
->HasSetter());
477 accessor
->SetProperty( object
, value
) ;
480 wxxVariant
wxClassInfo::GetProperty(wxObject
*object
, const wxChar
*propertyName
) const
482 const wxPropertyAccessor
*accessor
;
484 accessor
= FindAccessor(propertyName
);
485 wxASSERT(accessor
->HasGetter());
487 accessor
->GetProperty(object
,result
);
491 wxxVariantArray
wxClassInfo::GetPropertyCollection(wxObject
*object
, const wxChar
*propertyName
) const
493 const wxPropertyAccessor
*accessor
;
495 accessor
= FindAccessor(propertyName
);
496 wxASSERT(accessor
->HasGetter());
497 wxxVariantArray result
;
498 accessor
->GetPropertyCollection(object
,result
);
502 void wxClassInfo::AddToPropertyCollection(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
& value
) const
504 const wxPropertyAccessor
*accessor
;
506 accessor
= FindAccessor(propertyName
);
507 wxASSERT(accessor
->HasAdder());
508 accessor
->AddToPropertyCollection( object
, value
) ;
511 void wxClassInfo::GetProperties( wxPropertyInfoMap
&map
) const
513 const wxPropertyInfo
*pi
= GetFirstProperty() ;
516 if ( map
.find( pi
->GetName() ) == map
.end() )
517 map
[pi
->GetName()] = (wxPropertyInfo
*) pi
;
522 const wxClassInfo
** parents
= GetParents() ;
523 for ( int i
= 0 ; parents
[i
] ; ++ i
)
525 parents
[i
]->GetProperties( map
) ;
533 wxObject
* wxxVariant::GetAsObject()
535 const wxClassTypeInfo
*ti
= dynamic_cast<const wxClassTypeInfo
*>( m_data
->GetTypeInfo() ) ;
537 return ti
->GetClassInfo()->VariantToInstance(*this) ;
542 // ----------------------------------------------------------------------------
543 // wxDynamicObject support
544 // ----------------------------------------------------------------------------
546 // Dynamic Objects are objects that have a real superclass instance and carry their
547 // own attributes in a hash map. Like this it is possible to create the objects and
548 // stream them, as if their class information was already available from compiled data
550 struct wxDynamicObject::wxDynamicObjectInternal
552 wxDynamicObjectInternal() {}
555 map
<wstring
,wxxVariant
> m_properties
;
557 map
<string
,wxxVariant
> m_properties
;
561 typedef list
< wxDynamicObject
* > wxDynamicObjectList
;
563 struct wxDynamicClassInfo::wxDynamicClassInfoInternal
565 wxDynamicObjectList m_dynamicObjects
;
568 // instantiates this object with an instance of its superclass
569 wxDynamicObject::wxDynamicObject(wxObject
* superClassInstance
, const wxDynamicClassInfo
*info
)
571 m_superClassInstance
= superClassInstance
;
573 m_data
= new wxDynamicObjectInternal
;
576 wxDynamicObject::~wxDynamicObject()
578 dynamic_cast<const wxDynamicClassInfo
*>(m_classInfo
)->m_data
->m_dynamicObjects
.remove( this ) ;
580 delete m_superClassInstance
;
583 void wxDynamicObject::SetProperty (const wxChar
*propertyName
, const wxxVariant
&value
)
585 wxASSERT_MSG(m_classInfo
->FindPropertyInfoInThisClass(propertyName
),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
586 m_data
->m_properties
[propertyName
] = value
;
589 wxxVariant
wxDynamicObject::GetProperty (const wxChar
*propertyName
) const
591 wxASSERT_MSG(m_classInfo
->FindPropertyInfoInThisClass(propertyName
),wxT("Accessing Unknown Property in a Dynamic Object") ) ;
592 return m_data
->m_properties
[propertyName
] ;
595 void wxDynamicObject::RemoveProperty( const wxChar
*propertyName
)
597 wxASSERT_MSG(m_classInfo
->FindPropertyInfoInThisClass(propertyName
),wxT("Removing Unknown Property in a Dynamic Object") ) ;
598 m_data
->m_properties
.erase( propertyName
) ;
601 void wxDynamicObject::RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
)
603 wxASSERT_MSG(m_classInfo
->FindPropertyInfoInThisClass(oldPropertyName
),wxT("Renaming Unknown Property in a Dynamic Object") ) ;
604 wxxVariant value
= m_data
->m_properties
[oldPropertyName
] ;
605 m_data
->m_properties
.erase( oldPropertyName
) ;
606 m_data
->m_properties
[newPropertyName
] = value
;
610 // ----------------------------------------------------------------------------
612 // ----------------------------------------------------------------------------
614 wxDynamicClassInfo::wxDynamicClassInfo( const wxChar
*unitName
, const wxChar
*className
, const wxClassInfo
* superClass
) :
615 wxClassInfo( unitName
, className
, new const wxClassInfo
*[2])
617 GetParents()[0] = superClass
;
618 GetParents()[1] = NULL
;
619 m_data
= new wxDynamicClassInfoInternal
;
622 wxDynamicClassInfo::~wxDynamicClassInfo()
624 delete[] GetParents() ;
628 wxObject
*wxDynamicClassInfo::AllocateObject() const
630 wxObject
* parent
= GetParents()[0]->AllocateObject() ;
631 wxDynamicObject
*obj
= new wxDynamicObject( parent
, this ) ;
632 m_data
->m_dynamicObjects
.push_back( obj
) ;
636 void wxDynamicClassInfo::Create (wxObject
*object
, int paramCount
, wxxVariant
*params
) const
638 wxDynamicObject
*dynobj
= dynamic_cast< wxDynamicObject
*>( object
) ;
639 wxASSERT_MSG( dynobj
, wxT("cannot call wxDynamicClassInfo::Create on an object other than wxDynamicObject") ) ;
640 GetParents()[0]->Create( dynobj
->GetSuperClassInstance() , paramCount
, params
) ;
643 // get number of parameters for constructor
644 int wxDynamicClassInfo::GetCreateParamCount() const
646 return GetParents()[0]->GetCreateParamCount() ;
649 // get i-th constructor parameter
650 const wxChar
* wxDynamicClassInfo::GetCreateParamName(int i
) const
652 return GetParents()[0]->GetCreateParamName( i
) ;
655 void wxDynamicClassInfo::SetProperty(wxObject
*object
, const wxChar
*propertyName
, const wxxVariant
&value
) const
657 wxDynamicObject
* dynobj
= dynamic_cast< wxDynamicObject
* >( object
) ;
658 wxASSERT_MSG( dynobj
, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
659 if ( FindPropertyInfoInThisClass(propertyName
) )
660 dynobj
->SetProperty( propertyName
, value
) ;
662 GetParents()[0]->SetProperty( dynobj
->GetSuperClassInstance() , propertyName
, value
) ;
665 wxxVariant
wxDynamicClassInfo::GetProperty(wxObject
*object
, const wxChar
*propertyName
) const
667 wxDynamicObject
* dynobj
= dynamic_cast< wxDynamicObject
* >( object
) ;
668 wxASSERT_MSG( dynobj
, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
669 if ( FindPropertyInfoInThisClass(propertyName
) )
670 return dynobj
->GetProperty( propertyName
) ;
672 return GetParents()[0]->GetProperty( dynobj
->GetSuperClassInstance() , propertyName
) ;
675 void wxDynamicClassInfo::AddProperty( const wxChar
*propertyName
, const wxTypeInfo
* typeInfo
)
677 new wxPropertyInfo( m_firstProperty
, this , propertyName
, typeInfo
->GetTypeName() , new wxGenericPropertyAccessor( propertyName
) , wxxVariant() ) ;
680 void wxDynamicClassInfo::AddHandler( const wxChar
*handlerName
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
)
682 new wxHandlerInfo( m_firstHandler
, this , handlerName
, address
, eventClassInfo
) ;
685 // removes an existing runtime-property
686 void wxDynamicClassInfo::RemoveProperty( const wxChar
*propertyName
)
688 for ( wxDynamicObjectList::iterator iter
= m_data
->m_dynamicObjects
.begin() ; iter
!= m_data
->m_dynamicObjects
.end() ; ++iter
)
689 (*iter
)->RemoveProperty( propertyName
) ;
690 delete FindPropertyInfoInThisClass(propertyName
) ;
693 // removes an existing runtime-handler
694 void wxDynamicClassInfo::RemoveHandler( const wxChar
*handlerName
)
696 delete FindHandlerInfoInThisClass(handlerName
) ;
699 // renames an existing runtime-property
700 void wxDynamicClassInfo::RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
)
702 wxPropertyInfo
* pi
= FindPropertyInfoInThisClass(oldPropertyName
) ;
703 wxASSERT_MSG( pi
,wxT("not existing property") ) ;
704 pi
->m_name
= newPropertyName
;
705 dynamic_cast<wxGenericPropertyAccessor
*>(pi
->GetAccessor())->RenameProperty( oldPropertyName
, newPropertyName
) ;
706 for ( wxDynamicObjectList::iterator iter
= m_data
->m_dynamicObjects
.begin() ; iter
!= m_data
->m_dynamicObjects
.end() ; ++iter
)
707 (*iter
)->RenameProperty( oldPropertyName
, newPropertyName
) ;
710 // renames an existing runtime-handler
711 void wxDynamicClassInfo::RenameHandler( const wxChar
*oldHandlerName
, const wxChar
*newHandlerName
)
713 wxASSERT_MSG(FindHandlerInfoInThisClass(oldHandlerName
),wxT("not existing handler") ) ;
714 FindHandlerInfoInThisClass(oldHandlerName
)->m_name
= newHandlerName
;
717 // ----------------------------------------------------------------------------
718 // wxGenericPropertyAccessor
719 // ----------------------------------------------------------------------------
721 struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal
726 wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxString
& propertyName
)
727 : wxPropertyAccessor( NULL
, NULL
, NULL
, NULL
)
729 m_data
= new wxGenericPropertyAccessorInternal
;
730 m_propertyName
= propertyName
;
731 m_getterName
= wxT("Get")+propertyName
;
732 m_setterName
= wxT("Set")+propertyName
;
735 wxGenericPropertyAccessor::~wxGenericPropertyAccessor()
739 void wxGenericPropertyAccessor::SetProperty(wxObject
*object
, const wxxVariant
&value
) const
741 wxDynamicObject
* dynobj
= dynamic_cast< wxDynamicObject
* >( object
) ;
742 wxASSERT_MSG( dynobj
, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
743 dynobj
->SetProperty(m_propertyName
, value
) ;
746 void wxGenericPropertyAccessor::GetProperty(const wxObject
*object
, wxxVariant
& value
) const
748 const wxDynamicObject
* dynobj
= dynamic_cast< const wxDynamicObject
* >( object
) ;
749 wxASSERT_MSG( dynobj
, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") ) ;
750 value
= dynobj
->GetProperty( m_propertyName
) ;