1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/xti.cpp
3 // Purpose: runtime metadata information (extended class info)
4 // Author: Stefan Csomor
7 // Copyright: (c) 1997 Julian Smart
8 // (c) 2003 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxUSE_EXTENDED_RTTI
22 #include "wx/object.h"
28 #include "wx/xml/xml.h"
29 #include "wx/tokenzr.h"
34 #include "wx/beforestd.h"
38 #include "wx/afterstd.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 wxEnumData::wxEnumData( wxEnumMemberData
* data
)
49 for ( m_count
= 0; m_members
[m_count
].m_name
; m_count
++)
53 bool wxEnumData::HasEnumMemberValue(const wxChar
*name
, int *value
) const
56 for (i
= 0; m_members
[i
].m_name
; i
++ )
58 if (!wxStrcmp(name
, m_members
[i
].m_name
))
61 *value
= m_members
[i
].m_value
;
68 int wxEnumData::GetEnumMemberValue(const wxChar
*name
) const
71 for (i
= 0; m_members
[i
].m_name
; i
++ )
73 if (!wxStrcmp(name
, m_members
[i
].m_name
))
75 return m_members
[i
].m_value
;
81 const wxChar
*wxEnumData::GetEnumMemberName(int value
) const
84 for (i
= 0; m_members
[i
].m_name
; i
++)
85 if (value
== m_members
[i
].m_value
)
86 return m_members
[i
].m_name
;
91 int wxEnumData::GetEnumMemberValueByIndex( int idx
) const
93 // we should cache the count in order to avoid out-of-bounds errors
94 return m_members
[idx
].m_value
;
97 const wxChar
* wxEnumData::GetEnumMemberNameByIndex( int idx
) const
99 // we should cache the count in order to avoid out-of-bounds errors
100 return m_members
[idx
].m_name
;
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 // streamer specializations
112 // for all built-in types
116 template<> void wxStringReadValue(const wxString
&s
, bool &data
)
119 wxSscanf(s
, wxT("%d"), &intdata
);
120 data
= (bool)(intdata
!= 0);
123 template<> void wxStringWriteValue(wxString
&s
, const bool &data
)
125 s
= wxString::Format(wxT("%d"), data
);
130 template<> void wxStringReadValue(const wxString
&s
, char &data
)
133 wxSscanf(s
, wxT("%d"), &intdata
);
134 data
= char(intdata
);
137 template<> void wxStringWriteValue(wxString
&s
, const char &data
)
139 s
= wxString::Format(wxT("%d"), data
);
144 template<> void wxStringReadValue(const wxString
&s
, unsigned char &data
)
147 wxSscanf(s
, wxT("%d"), &intdata
);
148 data
= (unsigned char)(intdata
);
151 template<> void wxStringWriteValue(wxString
&s
, const unsigned char &data
)
153 s
= wxString::Format(wxT("%d"), data
);
158 template<> void wxStringReadValue(const wxString
&s
, int &data
)
160 wxSscanf(s
, wxT("%d"), &data
);
163 template<> void wxStringWriteValue(wxString
&s
, const int &data
)
165 s
= wxString::Format(wxT("%d"), data
);
170 template<> void wxStringReadValue(const wxString
&s
, unsigned int &data
)
172 wxSscanf(s
, wxT("%d"), &data
);
175 template<> void wxStringWriteValue(wxString
&s
, const unsigned int &data
)
177 s
= wxString::Format(wxT("%d"), data
);
182 template<> void wxStringReadValue(const wxString
&s
, long &data
)
184 wxSscanf(s
, wxT("%ld"), &data
);
187 template<> void wxStringWriteValue(wxString
&s
, const long &data
)
189 s
= wxString::Format(wxT("%ld"), data
);
194 template<> void wxStringReadValue(const wxString
&s
, unsigned long &data
)
196 wxSscanf(s
, wxT("%ld"), &data
);
199 template<> void wxStringWriteValue(wxString
&s
, const unsigned long &data
)
201 s
= wxString::Format(wxT("%ld"), data
);
205 template<> void wxStringReadValue(const wxString
&s
, wxLongLong_t
&data
)
207 wxSscanf(s
, wxT("%lld"), &data
);
210 template<> void wxStringWriteValue(wxString
&s
, const wxLongLong_t
&data
)
212 s
= wxString::Format(wxT("%lld"), data
);
215 template<> void wxStringReadValue(const wxString
&s
, wxULongLong_t
&data
)
217 wxSscanf(s
, wxT("%lld"), &data
);
220 template<> void wxStringWriteValue(wxString
&s
, const wxULongLong_t
&data
)
222 s
= wxString::Format(wxT("%lld"), data
);
227 template<> void wxStringReadValue(const wxString
&s
, float &data
)
229 wxSscanf(s
, wxT("%f"), &data
);
232 template<> void wxStringWriteValue(wxString
&s
, const float &data
)
234 s
= wxString::Format(wxT("%f"), data
);
239 template<> void wxStringReadValue(const wxString
&s
, double &data
)
241 wxSscanf(s
, wxT("%lf"), &data
);
244 template<> void wxStringWriteValue(wxString
&s
, const double &data
)
246 s
= wxString::Format(wxT("%lf"), data
);
251 template<> void wxStringReadValue(const wxString
&s
, wxString
&data
)
256 template<> void wxStringWriteValue(wxString
&s
, const wxString
&data
)
265 #if wxUSE_FUNC_TEMPLATE_POINTER
266 #define wxBUILTIN_TYPE_INFO( element, type ) \
268 s_typeInfo##type(element, &wxToStringConverter<type>, \
269 &wxFromStringConverter<type>, typeid(type).name());
271 #define wxBUILTIN_TYPE_INFO( element, type ) \
272 void _toString##element( const wxAny& data, wxString &result ) \
273 { wxToStringConverter<type, data, result); } \
274 void _fromString##element( const wxString& data, wxAny &result ) \
275 { wxFromStringConverter<type, data, result); } \
276 wxBuiltInTypeInfo s_typeInfo##type(element, &_toString##element, \
277 &_fromString##element, typeid(type).name());
280 typedef unsigned char unsigned_char
;
281 typedef unsigned int unsigned_int
;
282 typedef unsigned long unsigned_long
;
284 wxBuiltInTypeInfo
s_typeInfovoid( wxT_VOID
, NULL
, NULL
, typeid(void).name());
285 wxBUILTIN_TYPE_INFO( wxT_BOOL
, bool);
286 wxBUILTIN_TYPE_INFO( wxT_CHAR
, char);
287 wxBUILTIN_TYPE_INFO( wxT_UCHAR
, unsigned_char
);
288 wxBUILTIN_TYPE_INFO( wxT_INT
, int);
289 wxBUILTIN_TYPE_INFO( wxT_UINT
, unsigned_int
);
290 wxBUILTIN_TYPE_INFO( wxT_LONG
, long);
291 wxBUILTIN_TYPE_INFO( wxT_ULONG
, unsigned_long
);
292 wxBUILTIN_TYPE_INFO( wxT_FLOAT
, float);
293 wxBUILTIN_TYPE_INFO( wxT_DOUBLE
, double);
294 wxBUILTIN_TYPE_INFO( wxT_STRING
, wxString
);
297 wxBUILTIN_TYPE_INFO(wxT_LONGLONG
, wxLongLong_t
)
298 wxBUILTIN_TYPE_INFO(wxT_ULONGLONG
, wxULongLong_t
)
301 // this are compiler induced specialization which are never used anywhere
303 wxILLEGAL_TYPE_SPECIALIZATION( char const * )
304 wxILLEGAL_TYPE_SPECIALIZATION( char * )
305 wxILLEGAL_TYPE_SPECIALIZATION( unsigned char * )
306 wxILLEGAL_TYPE_SPECIALIZATION( int * )
307 wxILLEGAL_TYPE_SPECIALIZATION( bool * )
308 wxILLEGAL_TYPE_SPECIALIZATION( long * )
309 wxILLEGAL_TYPE_SPECIALIZATION( wxString
* )
313 template<> void wxStringReadValue(const wxString
&s
, wxRange
&data
)
315 int minValue
, maxValue
;
316 wxSscanf(s
, wxT("%d,%d"), &minValue
, &maxValue
);
317 data
= wxRange(minValue
, maxValue
);
320 template<> void wxStringWriteValue(wxString
&s
, const wxRange
&data
)
322 s
= wxString::Format(wxT("%d,%d"), data
.GetMin() , data
.GetMax());
325 wxCUSTOM_TYPE_INFO(wxRange
, wxToStringConverter
<wxRange
> , wxFromStringConverter
<wxRange
>)
329 wxCOLLECTION_TYPE_INFO( wxString
, wxArrayString
);
331 template<> void wxCollectionToVariantArray( wxArrayString
const &theArray
,
334 wxArrayCollectionToVariantArray( theArray
, value
);
337 wxTypeInfoMap
*wxTypeInfo::ms_typeTable
= NULL
;
339 wxTypeInfo
*wxTypeInfo::FindType(const wxString
& typeName
)
341 wxTypeInfoMap::iterator iter
= ms_typeTable
->find(typeName
);
343 if (iter
== ms_typeTable
->end())
346 return (wxTypeInfo
*)iter
->second
;
349 wxClassTypeInfo::wxClassTypeInfo( wxTypeKind kind
, wxClassInfo
* classInfo
,
350 wxVariant2StringFnc to
,
351 wxString2VariantFnc from
,
352 const wxString
&name
) :
353 wxTypeInfo( kind
, to
, from
, name
)
355 wxASSERT_MSG( kind
== wxT_OBJECT_PTR
|| kind
== wxT_OBJECT
,
356 wxT("Illegal Kind for Enum Type")); m_classInfo
= classInfo
;
359 wxEventSourceTypeInfo::wxEventSourceTypeInfo( int eventType
, wxClassInfo
* eventClass
,
360 wxVariant2StringFnc to
,
361 wxString2VariantFnc from
) :
362 wxTypeInfo ( wxT_DELEGATE
, to
, from
, wxEmptyString
)
364 m_eventClass
= eventClass
;
365 m_eventType
= eventType
;
366 m_lastEventType
= -1;
369 wxEventSourceTypeInfo::wxEventSourceTypeInfo( int eventType
, int lastEventType
,
370 wxClassInfo
* eventClass
,
371 wxVariant2StringFnc to
,
372 wxString2VariantFnc from
) :
373 wxTypeInfo ( wxT_DELEGATE
, to
, from
, wxEmptyString
)
375 m_eventClass
= eventClass
;
376 m_eventType
= eventType
;
377 m_lastEventType
= lastEventType
;
380 void wxTypeInfo::Register()
382 if ( ms_typeTable
== NULL
)
383 ms_typeTable
= new wxTypeInfoMap();
385 if( !m_name
.empty() )
386 (*ms_typeTable
)[m_name
] = this;
389 void wxTypeInfo::Unregister()
391 if( !m_name
.empty() )
392 ms_typeTable
->erase(m_name
);
395 // removing header dependency on string tokenizer
397 void wxSetStringToArray( const wxString
&s
, wxArrayString
&array
)
399 wxStringTokenizer
tokenizer(s
, wxT("| \t\n"), wxTOKEN_STRTOK
);
402 while (tokenizer
.HasMoreTokens())
404 array
.Add(tokenizer
.GetNextToken());
408 // ----------------------------------------------------------------------------
410 // ----------------------------------------------------------------------------
412 void wxPropertyInfo::Insert(wxPropertyInfo
* &iter
)
419 wxPropertyInfo
* i
= iter
;
427 void wxPropertyInfo::Remove()
429 if ( this == m_itsClass
->m_firstProperty
)
431 m_itsClass
->m_firstProperty
= m_next
;
435 wxPropertyInfo
*info
= m_itsClass
->m_firstProperty
;
438 if ( info
->m_next
== this )
440 info
->m_next
= m_next
;
450 // ----------------------------------------------------------------------------
452 // ----------------------------------------------------------------------------
454 void wxHandlerInfo::Insert(wxHandlerInfo
* &iter
)
461 wxHandlerInfo
* i
= iter
;
469 void wxHandlerInfo::Remove()
471 if ( this == m_itsClass
->m_firstHandler
)
473 m_itsClass
->m_firstHandler
= m_next
;
477 wxHandlerInfo
*info
= m_itsClass
->m_firstHandler
;
480 if ( info
->m_next
== this )
482 info
->m_next
= m_next
;
492 // ----------------------------------------------------------------------------
494 // ----------------------------------------------------------------------------
496 bool wxClassInfo::Create(wxObject
*object
, int ParamCount
, wxAny
*Params
) const
498 if ( ParamCount
!= m_constructorPropertiesCount
)
500 // FIXME: shouldn't we just return false and let the caller handle it?
501 wxLogError( _("Illegal Parameter Count for Create Method") );
505 return m_constructor
->Create( object
, Params
);
508 wxObject
*wxClassInfo::ConstructObject(int ParamCount
, wxAny
*Params
) const
510 if ( ParamCount
!= m_constructorPropertiesCount
)
512 // FIXME: shouldn't we just return NULL and let the caller handle this case?
513 wxLogError( _("Illegal Parameter Count for ConstructObject Method") );
517 wxObject
*object
= NULL
;
518 if (!m_constructor
->Create( object
, Params
))
523 bool wxClassInfo::IsKindOf(const wxClassInfo
*info
) const
530 for ( int i
= 0; m_parents
[i
]; ++ i
)
532 if ( m_parents
[i
]->IsKindOf( info
) )
539 const wxPropertyAccessor
*wxClassInfo::FindAccessor(const wxChar
*PropertyName
) const
541 const wxPropertyInfo
* info
= FindPropertyInfo( PropertyName
);
544 return info
->GetAccessor();
549 wxPropertyInfo
*wxClassInfo::FindPropertyInfoInThisClass (const wxChar
*PropertyName
) const
551 wxPropertyInfo
* info
= GetFirstProperty();
555 if ( wxStrcmp( info
->GetName(), PropertyName
) == 0 )
557 info
= info
->GetNext();
563 const wxPropertyInfo
*wxClassInfo::FindPropertyInfo (const wxChar
*PropertyName
) const
565 const wxPropertyInfo
* info
= FindPropertyInfoInThisClass( PropertyName
);
569 const wxClassInfo
** parents
= GetParents();
570 for ( int i
= 0; parents
[i
]; ++ i
)
572 if ( ( info
= parents
[i
]->FindPropertyInfo( PropertyName
) ) != NULL
)
579 wxHandlerInfo
*wxClassInfo::FindHandlerInfoInThisClass (const wxChar
*PropertyName
) const
581 wxHandlerInfo
* info
= GetFirstHandler();
585 if ( wxStrcmp( info
->GetName(), PropertyName
) == 0 )
587 info
= info
->GetNext();
593 const wxHandlerInfo
*wxClassInfo::FindHandlerInfo (const wxChar
*PropertyName
) const
595 const wxHandlerInfo
* info
= FindHandlerInfoInThisClass( PropertyName
);
600 const wxClassInfo
** parents
= GetParents();
601 for ( int i
= 0; parents
[i
]; ++ i
)
603 if ( ( info
= parents
[i
]->FindHandlerInfo( PropertyName
) ) != NULL
)
610 wxObjectStreamingCallback
wxClassInfo::GetStreamingCallback() const
612 if ( m_streamingCallback
)
613 return m_streamingCallback
;
615 wxObjectStreamingCallback retval
= NULL
;
616 const wxClassInfo
** parents
= GetParents();
617 for ( int i
= 0; parents
[i
] && retval
== NULL
; ++ i
)
619 retval
= parents
[i
]->GetStreamingCallback();
624 bool wxClassInfo::BeforeWriteObject( const wxObject
*obj
, wxObjectWriter
*streamer
,
625 wxObjectWriterCallback
*writercallback
, const wxStringToAnyHashMap
&metadata
) const
627 wxObjectStreamingCallback sb
= GetStreamingCallback();
629 return (*sb
)(obj
, streamer
, writercallback
, metadata
);
634 void wxClassInfo::SetProperty(wxObject
*object
, const wxChar
*propertyName
,
635 const wxAny
&value
) const
637 const wxPropertyAccessor
*accessor
;
639 accessor
= FindAccessor(propertyName
);
640 wxASSERT(accessor
->HasSetter());
641 accessor
->SetProperty( object
, value
);
644 wxAny
wxClassInfo::GetProperty(wxObject
*object
, const wxChar
*propertyName
) const
646 const wxPropertyAccessor
*accessor
;
648 accessor
= FindAccessor(propertyName
);
649 wxASSERT(accessor
->HasGetter());
651 accessor
->GetProperty(object
,result
);
655 wxAnyList
wxClassInfo::GetPropertyCollection(wxObject
*object
,
656 const wxChar
*propertyName
) const
658 const wxPropertyAccessor
*accessor
;
660 accessor
= FindAccessor(propertyName
);
661 wxASSERT(accessor
->HasGetter());
663 accessor
->GetPropertyCollection(object
,result
);
667 void wxClassInfo::AddToPropertyCollection(wxObject
*object
, const wxChar
*propertyName
,
668 const wxAny
& value
) const
670 const wxPropertyAccessor
*accessor
;
672 accessor
= FindAccessor(propertyName
);
673 wxASSERT(accessor
->HasAdder());
674 accessor
->AddToPropertyCollection( object
, value
);
677 // void wxClassInfo::GetProperties( wxPropertyInfoMap &map ) const
678 // The map parameter (the name map that is) seems something special
679 // to MSVC and so we use a other name.
680 void wxClassInfo::GetProperties( wxPropertyInfoMap
&infomap
) const
682 const wxPropertyInfo
*pi
= GetFirstProperty();
685 if ( infomap
.find( pi
->GetName() ) == infomap
.end() )
686 infomap
[pi
->GetName()] = (wxPropertyInfo
*) pi
;
691 const wxClassInfo
** parents
= GetParents();
692 for ( int i
= 0; parents
[i
]; ++ i
)
694 parents
[i
]->GetProperties( infomap
);
698 wxObject
* wxClassInfo::AnyToObjectPtr( const wxAny
&data
) const
700 return m_variantOfPtrToObjectConverter(data
);
703 void wxClassInfo::CallOnAny( const wxAny
&data
, wxObjectFunctor
* functor
) const
705 if ( data
.GetTypeInfo()->GetKind() == wxT_OBJECT
)
706 return m_variantToObjectConverter(data
, functor
);
708 return (*functor
)(m_variantOfPtrToObjectConverter(data
));
711 wxAny
wxClassInfo::ObjectPtrToAny( wxObject
* obj
) const
713 return m_objectToVariantConverter(obj
);
716 bool wxClassInfo::NeedsDirectConstruction() const
718 return wx_dynamic_cast(wxObjectAllocator
*, m_constructor
) != NULL
;
721 // ----------------------------------------------------------------------------
722 // wxDynamicObject support
723 // ----------------------------------------------------------------------------
725 // Dynamic Objects are objects that have a real superclass instance and carry their
726 // own attributes in a hash map. Like this it is possible to create the objects and
727 // stream them, as if their class information was already available from compiled data
729 struct wxDynamicObject::wxDynamicObjectInternal
731 wxDynamicObjectInternal() {}
733 wxStringToAnyHashMap m_properties
;
736 typedef list
< wxDynamicObject
* > wxDynamicObjectList
;
738 struct wxDynamicClassInfo::wxDynamicClassInfoInternal
740 wxDynamicObjectList m_dynamicObjects
;
743 // instantiates this object with an instance of its superclass
744 wxDynamicObject::wxDynamicObject(wxObject
* superClassInstance
, const wxDynamicClassInfo
*info
)
746 m_superClassInstance
= superClassInstance
;
748 m_data
= new wxDynamicObjectInternal
;
751 wxDynamicObject::~wxDynamicObject()
753 wx_dynamic_cast(const wxDynamicClassInfo
*, m_classInfo
)->
754 m_data
->m_dynamicObjects
.remove( this );
756 delete m_superClassInstance
;
759 void wxDynamicObject::SetProperty (const wxChar
*propertyName
, const wxAny
&value
)
761 wxASSERT_MSG(m_classInfo
->FindPropertyInfoInThisClass(propertyName
),
762 wxT("Accessing Unknown Property in a Dynamic Object") );
763 m_data
->m_properties
[propertyName
] = value
;
766 wxAny
wxDynamicObject::GetProperty (const wxChar
*propertyName
) const
768 wxASSERT_MSG(m_classInfo
->FindPropertyInfoInThisClass(propertyName
),
769 wxT("Accessing Unknown Property in a Dynamic Object") );
770 return m_data
->m_properties
[propertyName
];
773 void wxDynamicObject::RemoveProperty( const wxChar
*propertyName
)
775 wxASSERT_MSG(m_classInfo
->FindPropertyInfoInThisClass(propertyName
),
776 wxT("Removing Unknown Property in a Dynamic Object") );
777 m_data
->m_properties
.erase( propertyName
);
780 void wxDynamicObject::RenameProperty( const wxChar
*oldPropertyName
,
781 const wxChar
*newPropertyName
)
783 wxASSERT_MSG(m_classInfo
->FindPropertyInfoInThisClass(oldPropertyName
),
784 wxT("Renaming Unknown Property in a Dynamic Object") );
786 wxAny value
= m_data
->m_properties
[oldPropertyName
];
787 m_data
->m_properties
.erase( oldPropertyName
);
788 m_data
->m_properties
[newPropertyName
] = value
;
792 // ----------------------------------------------------------------------------
793 // wxDynamicClassInfo
794 // ----------------------------------------------------------------------------
796 wxDynamicClassInfo::wxDynamicClassInfo( const wxChar
*unitName
,
797 const wxChar
*className
,
798 const wxClassInfo
* superClass
) :
799 wxClassInfo( unitName
, className
, new const wxClassInfo
*[2])
801 GetParents()[0] = superClass
;
802 GetParents()[1] = NULL
;
803 m_data
= new wxDynamicClassInfoInternal
;
806 wxDynamicClassInfo::~wxDynamicClassInfo()
808 delete[] GetParents();
812 wxObject
*wxDynamicClassInfo::AllocateObject() const
814 wxObject
* parent
= GetParents()[0]->AllocateObject();
815 wxDynamicObject
*obj
= new wxDynamicObject( parent
, this );
816 m_data
->m_dynamicObjects
.push_back( obj
);
820 bool wxDynamicClassInfo::Create (wxObject
*object
, int paramCount
, wxAny
*params
) const
822 wxDynamicObject
*dynobj
= wx_dynamic_cast( wxDynamicObject
*, object
);
823 wxASSERT_MSG( dynobj
,
824 wxT("cannot call wxDynamicClassInfo::Create on ")
825 wxT("an object other than wxDynamicObject") );
827 return GetParents()[0]->Create( dynobj
->GetSuperClassInstance(), paramCount
, params
);
830 // get number of parameters for constructor
831 int wxDynamicClassInfo::GetCreateParamCount() const
833 return GetParents()[0]->GetCreateParamCount();
836 // get i-th constructor parameter
837 const wxChar
* wxDynamicClassInfo::GetCreateParamName(int i
) const
839 return GetParents()[0]->GetCreateParamName( i
);
842 void wxDynamicClassInfo::SetProperty(wxObject
*object
, const wxChar
*propertyName
, const wxAny
&value
) const
844 wxDynamicObject
* dynobj
= wx_dynamic_cast(wxDynamicObject
*, object
);
845 wxASSERT_MSG( dynobj
, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") );
846 if ( FindPropertyInfoInThisClass(propertyName
) )
847 dynobj
->SetProperty( propertyName
, value
);
849 GetParents()[0]->SetProperty( dynobj
->GetSuperClassInstance(), propertyName
, value
);
852 wxAny
wxDynamicClassInfo::GetProperty(wxObject
*object
, const wxChar
*propertyName
) const
854 wxDynamicObject
* dynobj
= wx_dynamic_cast(wxDynamicObject
*, object
);
855 wxASSERT_MSG( dynobj
, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") );
856 if ( FindPropertyInfoInThisClass(propertyName
) )
857 return dynobj
->GetProperty( propertyName
);
859 return GetParents()[0]->GetProperty( dynobj
->GetSuperClassInstance(), propertyName
);
862 void wxDynamicClassInfo::AddProperty( const wxChar
*propertyName
, const wxTypeInfo
* typeInfo
)
865 new wxPropertyInfo( m_firstProperty
, this, propertyName
, typeInfo
->GetTypeName(), new wxGenericPropertyAccessor( propertyName
), wxAny() );
868 void wxDynamicClassInfo::AddHandler( const wxChar
*handlerName
, wxObjectEventFunction address
, const wxClassInfo
* eventClassInfo
)
871 new wxHandlerInfo( m_firstHandler
, this, handlerName
, address
, eventClassInfo
);
874 // removes an existing runtime-property
875 void wxDynamicClassInfo::RemoveProperty( const wxChar
*propertyName
)
877 for ( wxDynamicObjectList::iterator iter
= m_data
->m_dynamicObjects
.begin(); iter
!= m_data
->m_dynamicObjects
.end(); ++iter
)
878 (*iter
)->RemoveProperty( propertyName
);
879 delete FindPropertyInfoInThisClass(propertyName
);
882 // removes an existing runtime-handler
883 void wxDynamicClassInfo::RemoveHandler( const wxChar
*handlerName
)
885 delete FindHandlerInfoInThisClass(handlerName
);
888 // renames an existing runtime-property
889 void wxDynamicClassInfo::RenameProperty( const wxChar
*oldPropertyName
, const wxChar
*newPropertyName
)
891 wxPropertyInfo
* pi
= FindPropertyInfoInThisClass(oldPropertyName
);
892 wxASSERT_MSG( pi
,wxT("not existing property") );
893 pi
->m_name
= newPropertyName
;
894 wx_dynamic_cast(wxGenericPropertyAccessor
*, pi
->GetAccessor())->RenameProperty( oldPropertyName
, newPropertyName
);
895 for ( wxDynamicObjectList::iterator iter
= m_data
->m_dynamicObjects
.begin(); iter
!= m_data
->m_dynamicObjects
.end(); ++iter
)
896 (*iter
)->RenameProperty( oldPropertyName
, newPropertyName
);
899 // renames an existing runtime-handler
900 void wxDynamicClassInfo::RenameHandler( const wxChar
*oldHandlerName
, const wxChar
*newHandlerName
)
902 wxASSERT_MSG(FindHandlerInfoInThisClass(oldHandlerName
),wxT("not existing handler") );
903 FindHandlerInfoInThisClass(oldHandlerName
)->m_name
= newHandlerName
;
906 // ----------------------------------------------------------------------------
907 // wxGenericPropertyAccessor
908 // ----------------------------------------------------------------------------
910 struct wxGenericPropertyAccessor::wxGenericPropertyAccessorInternal
915 wxGenericPropertyAccessor::wxGenericPropertyAccessor( const wxString
& propertyName
)
916 : wxPropertyAccessor( NULL
, NULL
, NULL
, NULL
)
918 m_data
= new wxGenericPropertyAccessorInternal
;
919 m_propertyName
= propertyName
;
920 m_getterName
= wxT("Get")+propertyName
;
921 m_setterName
= wxT("Set")+propertyName
;
924 wxGenericPropertyAccessor::~wxGenericPropertyAccessor()
929 void wxGenericPropertyAccessor::SetProperty(wxObject
*object
, const wxAny
&value
) const
931 wxDynamicObject
* dynobj
= wx_dynamic_cast(wxDynamicObject
*, object
);
932 wxASSERT_MSG( dynobj
, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") );
933 dynobj
->SetProperty(m_propertyName
.c_str(), value
);
936 void wxGenericPropertyAccessor::GetProperty(const wxObject
*object
, wxAny
& value
) const
938 const wxDynamicObject
* dynobj
= wx_dynamic_cast( const wxDynamicObject
* , object
);
939 wxASSERT_MSG( dynobj
, wxT("cannot call wxDynamicClassInfo::SetProperty on an object other than wxDynamicObject") );
940 value
= dynobj
->GetProperty( m_propertyName
.c_str() );
943 // ----------------------------------------------------------------------------
944 // wxGenericPropertyAccessor
945 // ----------------------------------------------------------------------------
947 wxString
wxAnyGetAsString( const wxAny
& data
)
949 if ( data
.IsNull() || data
.GetTypeInfo()==NULL
)
950 return wxEmptyString
;
953 data
.GetTypeInfo()->ConvertToString(data
,s
);
957 const wxObject
* wxAnyGetAsObjectPtr( const wxAny
& data
)
959 if ( !data
.IsNull() )
961 const wxClassTypeInfo
* ti
= wx_dynamic_cast(const wxClassTypeInfo
*, data
.GetTypeInfo());
963 return ti
->GetClassInfo()->AnyToObjectPtr(data
);
968 wxObjectFunctor::~wxObjectFunctor()
971 #endif // wxUSE_EXTENDED_RTTI