1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/xtistrm.cpp
3 // Purpose: streaming runtime metadata information
4 // Author: Stefan Csomor
8 // Copyright: (c) 2003 Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "xtistrm.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
25 #include "wx/object.h"
28 #include "wx/tokenzr.h"
29 #include "wx/txtstrm.h"
32 #if wxUSE_EXTENDED_RTTI
34 #include "wx/xtistrm.h"
36 #include "wx/beforestd.h"
40 #include "wx/afterstd.h"
44 struct wxWriter::wxWriterInternal
46 map
< const wxObject
* , int > m_writtenObjects
;
52 m_data
= new wxWriterInternal
;
53 m_data
->m_nextId
= 0 ;
61 struct wxWriter::wxWriterInternalPropertiesData
66 void wxWriter::ClearObjectContext()
69 m_data
= new wxWriterInternal() ;
70 m_data
->m_nextId
= 0 ;
73 void wxWriter::WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, wxPersister
*persister
, const wxString
&name
, wxxVariantArray
&metadata
)
75 DoBeginWriteTopLevelEntry( name
) ;
76 WriteObject( object
, classInfo
, persister
, false , metadata
) ;
77 DoEndWriteTopLevelEntry( name
) ;
80 void wxWriter::WriteObject(const wxObject
*object
, const wxClassInfo
*classInfo
, wxPersister
*persister
, bool isEmbedded
, wxxVariantArray
&metadata
)
82 if ( !classInfo
->BeforeWriteObject( object
, this , persister
, metadata
) )
85 if ( persister
->BeforeWriteObject( this , object
, classInfo
, metadata
) )
89 else if ( IsObjectKnown( object
) )
90 DoWriteRepeatedObject( GetObjectID(object
) ) ;
93 int oid
= m_data
->m_nextId
++ ;
95 m_data
->m_writtenObjects
[object
] = oid
;
97 // in case this object is a wxDynamicObject we also have to insert is superclass
98 // instance with the same id, so that object relations are streamed out correctly
99 const wxDynamicObject
* dynobj
= dynamic_cast<const wxDynamicObject
*>( object
) ;
100 if ( !isEmbedded
&& dynobj
)
101 m_data
->m_writtenObjects
[dynobj
->GetSuperClassInstance()] = oid
;
103 DoBeginWriteObject( object
, classInfo
, oid
, metadata
) ;
104 wxWriterInternalPropertiesData data
;
105 WriteAllProperties( object
, classInfo
, persister
, &data
) ;
106 DoEndWriteObject( object
, classInfo
, oid
) ;
108 persister
->AfterWriteObject( this ,object
, classInfo
) ;
112 void wxWriter::FindConnectEntry(const wxEvtHandler
* evSource
,const wxDelegateTypeInfo
* dti
, const wxObject
* &sink
, const wxHandlerInfo
*&handler
)
114 wxList
*dynamicEvents
= evSource
->GetDynamicEventTable() ;
118 wxList::compatibility_iterator node
= dynamicEvents
->GetFirst();
121 wxDynamicEventTableEntry
*entry
= (wxDynamicEventTableEntry
*)node
->GetData();
125 (dti
->GetEventType() == entry
->m_eventType
) &&
126 (entry
->m_id
== -1 ) &&
127 (entry
->m_eventSink
!= NULL
) )
129 sink
= entry
->m_eventSink
;
130 const wxClassInfo
* sinkClassInfo
= sink
->GetClassInfo() ;
131 const wxHandlerInfo
* sinkHandler
= sinkClassInfo
->GetFirstHandler() ;
132 while ( sinkHandler
)
134 if ( sinkHandler
->GetEventFunction() == entry
->m_fn
)
136 handler
= sinkHandler
;
139 sinkHandler
= sinkHandler
->GetNext() ;
143 node
= node
->GetNext();
147 void wxWriter::WriteAllProperties( const wxObject
* obj
, const wxClassInfo
* ci
, wxPersister
*persister
, wxWriterInternalPropertiesData
* data
)
149 wxPropertyInfoMap map
;
150 ci
->GetProperties( map
) ;
151 for ( int i
= 0 ; i
< ci
->GetCreateParamCount() ; ++i
)
153 wxString name
= ci
->GetCreateParamName(i
) ;
154 const wxPropertyInfo
* prop
= map
.find(name
)->second
;
157 WriteOneProperty( obj
, prop
->GetDeclaringClass() , prop
, persister
, data
) ;
161 wxLogError( _("Create Parameter not found in declared RTTI Parameters") ) ;
165 { // Extra block for broken compilers
166 for( wxPropertyInfoMap::iterator iter
= map
.begin() ; iter
!= map
.end() ; ++iter
)
168 const wxPropertyInfo
* prop
= iter
->second
;
169 if ( prop
->GetFlags() & wxPROP_OBJECT_GRAPH
)
171 WriteOneProperty( obj
, prop
->GetDeclaringClass() , prop
, persister
, data
) ;
175 { // Extra block for broken compilers
176 for( wxPropertyInfoMap::iterator iter
= map
.begin() ; iter
!= map
.end() ; ++iter
)
178 const wxPropertyInfo
* prop
= iter
->second
;
179 if ( !(prop
->GetFlags() & wxPROP_OBJECT_GRAPH
) )
181 WriteOneProperty( obj
, prop
->GetDeclaringClass() , prop
, persister
, data
) ;
187 void wxWriter::WriteOneProperty( const wxObject
*obj
, const wxClassInfo
* ci
, const wxPropertyInfo
* pi
, wxPersister
*persister
, wxWriterInternalPropertiesData
*WXUNUSED(data
) )
189 if ( pi
->GetFlags() & wxPROP_DONT_STREAM
)
192 // make sure that we are picking the correct object for accessing the property
193 const wxDynamicObject
* dynobj
= dynamic_cast< const wxDynamicObject
* > (obj
) ;
194 if ( dynobj
&& (dynamic_cast<const wxDynamicClassInfo
*>(ci
) == NULL
) )
195 obj
= dynobj
->GetSuperClassInstance() ;
197 if ( pi
->GetTypeInfo()->GetKind() == wxT_COLLECTION
)
199 wxxVariantArray data
;
200 pi
->GetAccessor()->GetPropertyCollection(obj
, data
) ;
201 const wxTypeInfo
* elementType
= dynamic_cast< const wxCollectionTypeInfo
* >( pi
->GetTypeInfo() )->GetElementType() ;
202 for ( size_t i
= 0 ; i
< data
.GetCount() ; ++i
)
205 DoBeginWriteProperty( pi
) ;
207 DoBeginWriteElement() ;
208 wxxVariant value
= data
[i
] ;
209 if ( persister
->BeforeWriteProperty( this , obj
, pi
, value
) )
211 const wxClassTypeInfo
* cti
= dynamic_cast< const wxClassTypeInfo
* > ( elementType
) ;
214 const wxClassInfo
* pci
= cti
->GetClassInfo() ;
215 wxObject
*vobj
= pci
->VariantToInstance( value
) ;
217 WriteObject( vobj
, (vobj
? vobj
->GetClassInfo() : pci
) , persister
, cti
->GetKind()== wxT_OBJECT
, md
) ;
221 DoWriteSimpleType( value
) ;
224 DoEndWriteElement() ;
225 if ( i
== data
.GetCount() - 1 )
226 DoEndWriteProperty( pi
) ;
231 const wxDelegateTypeInfo
* dti
= dynamic_cast< const wxDelegateTypeInfo
* > ( pi
->GetTypeInfo() ) ;
234 const wxObject
* sink
= NULL
;
235 const wxHandlerInfo
*handler
= NULL
;
237 const wxEvtHandler
* evSource
= dynamic_cast<const wxEvtHandler
*>(obj
) ;
240 FindConnectEntry( evSource
, dti
, sink
, handler
) ;
241 if ( persister
->BeforeWriteDelegate( this , obj
, ci
, pi
, sink
, handler
) )
243 if ( sink
!= NULL
&& handler
!= NULL
)
245 DoBeginWriteProperty( pi
) ;
246 if ( IsObjectKnown( sink
) )
248 DoWriteDelegate( obj
, ci
, pi
, sink
, GetObjectID( sink
) , sink
->GetClassInfo() , handler
) ;
249 DoEndWriteProperty( pi
) ;
253 wxLogError( _("Streaming delegates for not already streamed objects not yet supported") ) ;
260 wxLogError(_("Illegal Object Class (Non-wxEvtHandler) as Event Source") ) ;
266 pi
->GetAccessor()->GetProperty(obj
, value
) ;
268 // avoid streaming out void objects
269 if( value
.IsEmpty() )
272 if ( pi
->GetFlags() & wxPROP_ENUM_STORE_LONG
)
274 const wxEnumTypeInfo
*eti
= dynamic_cast<const wxEnumTypeInfo
*>( pi
->GetTypeInfo() ) ;
277 eti
->ConvertFromLong( value
.wxTEMPLATED_MEMBER_CALL(Get
, long) , value
) ;
281 wxLogError( _("Type must have enum - long conversion") ) ;
285 // avoid streaming out default values
286 if ( pi
->GetTypeInfo()->HasStringConverters() && !pi
->GetDefaultValue().IsEmpty() )
288 if ( value
.GetAsString() == pi
->GetDefaultValue().GetAsString() )
292 // avoid streaming out null objects
293 const wxClassTypeInfo
* cti
= dynamic_cast< const wxClassTypeInfo
* > ( pi
->GetTypeInfo() ) ;
295 if ( cti
&& value
.GetAsObject() == NULL
)
298 if ( persister
->BeforeWriteProperty( this , obj
, pi
, value
) )
300 DoBeginWriteProperty( pi
) ;
303 const wxClassInfo
* pci
= cti
->GetClassInfo() ;
304 wxObject
*vobj
= pci
->VariantToInstance( value
) ;
305 if ( vobj
&& pi
->GetTypeInfo()->HasStringConverters() )
307 wxString stringValue
;
308 cti
->ConvertToString( value
, stringValue
) ;
309 wxxVariant
convertedValue(stringValue
) ;
310 DoWriteSimpleType( convertedValue
) ;
315 WriteObject( vobj
, (vobj
? vobj
->GetClassInfo() : pci
) , persister
, cti
->GetKind()== wxT_OBJECT
, md
) ;
320 DoWriteSimpleType( value
) ;
322 DoEndWriteProperty( pi
) ;
328 int wxWriter::GetObjectID(const wxObject
*obj
)
330 if ( !IsObjectKnown( obj
) )
331 return wxInvalidObjectID
;
333 return m_data
->m_writtenObjects
[obj
] ;
336 bool wxWriter::IsObjectKnown( const wxObject
*obj
)
338 return m_data
->m_writtenObjects
.find( obj
) != m_data
->m_writtenObjects
.end() ;
342 // ----------------------------------------------------------------------------
343 // reading objects in
344 // ----------------------------------------------------------------------------
346 struct wxReader::wxReaderInternal
348 map
<int,wxClassInfo
*> m_classInfos
;
353 m_data
= new wxReaderInternal
;
356 wxReader::~wxReader()
361 wxClassInfo
* wxReader::GetObjectClassInfo(int objectID
)
363 if ( objectID
== wxNullObjectID
|| objectID
== wxInvalidObjectID
)
365 wxLogError( _("Invalid or Null Object ID passed to GetObjectClassInfo" ) ) ;
368 if ( m_data
->m_classInfos
.find(objectID
) == m_data
->m_classInfos
.end() )
370 wxLogError( _("Unknown Object passed to GetObjectClassInfo" ) ) ;
373 return m_data
->m_classInfos
[objectID
] ;
376 void wxReader::SetObjectClassInfo(int objectID
, wxClassInfo
*classInfo
)
378 if ( objectID
== wxNullObjectID
|| objectID
== wxInvalidObjectID
)
380 wxLogError( _("Invalid or Null Object ID passed to GetObjectClassInfo" ) ) ;
383 if ( m_data
->m_classInfos
.find(objectID
) != m_data
->m_classInfos
.end() )
385 wxLogError( _("Already Registered Object passed to SetObjectClassInfo" ) ) ;
388 m_data
->m_classInfos
[objectID
] = classInfo
;
391 bool wxReader::HasObjectClassInfo( int objectID
)
393 if ( objectID
== wxNullObjectID
|| objectID
== wxInvalidObjectID
)
395 wxLogError( _("Invalid or Null Object ID passed to HasObjectClassInfo" ) ) ;
398 return m_data
->m_classInfos
.find(objectID
) != m_data
->m_classInfos
.end() ;
402 // ----------------------------------------------------------------------------
404 // ----------------------------------------------------------------------------
407 Reading components has not to be extended for components
408 as properties are always sought by typeinfo over all levels
409 and create params are always toplevel class only
413 // ----------------------------------------------------------------------------
414 // depersisting to memory
415 // ----------------------------------------------------------------------------
417 struct wxRuntimeDepersister::wxRuntimeDepersisterInternal
419 map
<int,wxObject
*> m_objects
;
421 void SetObject(int objectID
, wxObject
*obj
)
423 if ( m_objects
.find(objectID
) != m_objects
.end() )
425 wxLogError( _("Passing a already registered object to SetObject") ) ;
428 m_objects
[objectID
] = obj
;
430 wxObject
* GetObject( int objectID
)
432 if ( objectID
== wxNullObjectID
)
434 if ( m_objects
.find(objectID
) == m_objects
.end() )
436 wxLogError( _("Passing an unkown object to GetObject") ) ;
440 return m_objects
[objectID
] ;
444 wxRuntimeDepersister::wxRuntimeDepersister()
446 m_data
= new wxRuntimeDepersisterInternal() ;
449 wxRuntimeDepersister::~wxRuntimeDepersister()
454 void wxRuntimeDepersister::AllocateObject(int objectID
, wxClassInfo
*classInfo
,
455 wxxVariantArray
&WXUNUSED(metadata
))
458 O
= classInfo
->CreateObject();
459 m_data
->SetObject(objectID
, O
);
462 void wxRuntimeDepersister::CreateObject(int objectID
,
463 const wxClassInfo
*classInfo
,
467 const wxClassInfo
**objectClassInfos
,
468 wxxVariantArray
&WXUNUSED(metadata
))
471 o
= m_data
->GetObject(objectID
);
472 for ( int i
= 0 ; i
< paramCount
; ++i
)
474 if ( objectIdValues
[i
] != wxInvalidObjectID
)
477 o
= m_data
->GetObject(objectIdValues
[i
]);
478 // if this is a dynamic object and we are asked for another class
479 // than wxDynamicObject we cast it down manually.
480 wxDynamicObject
*dyno
= dynamic_cast< wxDynamicObject
* > (o
) ;
481 if ( dyno
!=NULL
&& (objectClassInfos
[i
] != dyno
->GetClassInfo()) )
483 o
= dyno
->GetSuperClassInstance() ;
485 params
[i
] = objectClassInfos
[i
]->InstanceToVariant(o
) ;
488 classInfo
->Create(o
, paramCount
, params
);
491 void wxRuntimeDepersister::ConstructObject(int objectID
,
492 const wxClassInfo
*classInfo
,
496 const wxClassInfo
**objectClassInfos
,
497 wxxVariantArray
&WXUNUSED(metadata
))
500 for ( int i
= 0 ; i
< paramCount
; ++i
)
502 if ( objectIdValues
[i
] != wxInvalidObjectID
)
505 o
= m_data
->GetObject(objectIdValues
[i
]);
506 // if this is a dynamic object and we are asked for another class
507 // than wxDynamicObject we cast it down manually.
508 wxDynamicObject
*dyno
= dynamic_cast< wxDynamicObject
* > (o
) ;
509 if ( dyno
!=NULL
&& (objectClassInfos
[i
] != dyno
->GetClassInfo()) )
511 o
= dyno
->GetSuperClassInstance() ;
513 params
[i
] = objectClassInfos
[i
]->InstanceToVariant(o
) ;
516 o
= classInfo
->ConstructObject(paramCount
, params
);
517 m_data
->SetObject(objectID
, o
);
521 void wxRuntimeDepersister::DestroyObject(int objectID
, wxClassInfo
*WXUNUSED(classInfo
))
524 o
= m_data
->GetObject(objectID
);
528 void wxRuntimeDepersister::SetProperty(int objectID
,
529 const wxClassInfo
*classInfo
,
530 const wxPropertyInfo
* propertyInfo
,
531 const wxxVariant
&value
)
534 o
= m_data
->GetObject(objectID
);
535 classInfo
->SetProperty( o
, propertyInfo
->GetName() , value
) ;
538 void wxRuntimeDepersister::SetPropertyAsObject(int objectID
,
539 const wxClassInfo
*classInfo
,
540 const wxPropertyInfo
* propertyInfo
,
544 o
= m_data
->GetObject(objectID
);
545 valo
= m_data
->GetObject(valueObjectId
);
546 const wxClassInfo
* valClassInfo
= (dynamic_cast<const wxClassTypeInfo
*>(propertyInfo
->GetTypeInfo()))->GetClassInfo() ;
547 // if this is a dynamic object and we are asked for another class
548 // than wxDynamicObject we cast it down manually.
549 wxDynamicObject
*dynvalo
= dynamic_cast< wxDynamicObject
* > (valo
) ;
550 if ( dynvalo
!=NULL
&& (valClassInfo
!= dynvalo
->GetClassInfo()) )
552 valo
= dynvalo
->GetSuperClassInstance() ;
555 classInfo
->SetProperty( o
, propertyInfo
->GetName() , valClassInfo
->InstanceToVariant(valo
) ) ;
558 void wxRuntimeDepersister::SetConnect(int eventSourceObjectID
,
559 const wxClassInfo
*WXUNUSED(eventSourceClassInfo
),
560 const wxPropertyInfo
*delegateInfo
,
561 const wxClassInfo
*WXUNUSED(eventSinkClassInfo
) ,
562 const wxHandlerInfo
* handlerInfo
,
563 int eventSinkObjectID
)
565 wxEvtHandler
*ehsource
= dynamic_cast< wxEvtHandler
* >( m_data
->GetObject( eventSourceObjectID
) ) ;
566 wxEvtHandler
*ehsink
= dynamic_cast< wxEvtHandler
*>(m_data
->GetObject(eventSinkObjectID
) ) ;
568 if ( ehsource
&& ehsink
)
570 const wxDelegateTypeInfo
*delegateTypeInfo
= dynamic_cast<const wxDelegateTypeInfo
*>(delegateInfo
->GetTypeInfo());
571 if( delegateTypeInfo
&& delegateTypeInfo
->GetLastEventType() == -1 )
573 ehsource
->Connect( -1 , delegateTypeInfo
->GetEventType() ,
574 handlerInfo
->GetEventFunction() , NULL
/*user data*/ ,
579 for ( wxEventType iter
= delegateTypeInfo
->GetEventType() ; iter
<= delegateTypeInfo
->GetLastEventType() ; ++iter
)
581 ehsource
->Connect( -1 , iter
,
582 handlerInfo
->GetEventFunction() , NULL
/*user data*/ ,
589 wxObject
*wxRuntimeDepersister::GetObject(int objectID
)
591 return m_data
->GetObject( objectID
) ;
594 // adds an element to a property collection
595 void wxRuntimeDepersister::AddToPropertyCollection( int objectID
,
596 const wxClassInfo
*classInfo
,
597 const wxPropertyInfo
* propertyInfo
,
598 const wxxVariant
&value
)
601 o
= m_data
->GetObject(objectID
);
602 classInfo
->AddToPropertyCollection( o
, propertyInfo
->GetName() , value
) ;
605 // sets the corresponding property (value is an object)
606 void wxRuntimeDepersister::AddToPropertyCollectionAsObject(int objectID
,
607 const wxClassInfo
*classInfo
,
608 const wxPropertyInfo
* propertyInfo
,
612 o
= m_data
->GetObject(objectID
);
613 valo
= m_data
->GetObject(valueObjectId
);
614 const wxCollectionTypeInfo
* collectionTypeInfo
= dynamic_cast< const wxCollectionTypeInfo
* >(propertyInfo
->GetTypeInfo() ) ;
615 const wxClassInfo
* valClassInfo
= (dynamic_cast<const wxClassTypeInfo
*>(collectionTypeInfo
->GetElementType()))->GetClassInfo() ;
616 // if this is a dynamic object and we are asked for another class
617 // than wxDynamicObject we cast it down manually.
618 wxDynamicObject
*dynvalo
= dynamic_cast< wxDynamicObject
* > (valo
) ;
619 if ( dynvalo
!=NULL
&& (valClassInfo
!= dynvalo
->GetClassInfo()) )
621 valo
= dynvalo
->GetSuperClassInstance() ;
624 classInfo
->AddToPropertyCollection( o
, propertyInfo
->GetName() , valClassInfo
->InstanceToVariant(valo
) ) ;
627 // ----------------------------------------------------------------------------
628 // depersisting to code
629 // ----------------------------------------------------------------------------
631 struct wxCodeDepersister::wxCodeDepersisterInternal
634 map
<int,wstring
> m_objectNames
;
636 map
<int,string
> m_objectNames
;
639 void SetObjectName(int objectID
, const wxString
&name
)
641 if ( m_objectNames
.find(objectID
) != m_objectNames
.end() )
643 wxLogError( _("Passing a already registered object to SetObjectName") ) ;
646 m_objectNames
[objectID
] = (const wxChar
*)name
;
649 wxString
GetObjectName( int objectID
)
651 if ( objectID
== wxNullObjectID
)
654 if ( m_objectNames
.find(objectID
) == m_objectNames
.end() )
656 wxLogError( _("Passing an unkown object to GetObject") ) ;
657 return wxEmptyString
;
659 return wxString( m_objectNames
[objectID
].c_str() ) ;
663 wxCodeDepersister::wxCodeDepersister(wxTextOutputStream
*out
)
666 m_data
= new wxCodeDepersisterInternal
;
669 wxCodeDepersister::~wxCodeDepersister()
674 void wxCodeDepersister::AllocateObject(int objectID
, wxClassInfo
*classInfo
,
675 wxxVariantArray
&WXUNUSED(metadata
))
677 wxString objectName
= wxString::Format( wxT("LocalObject_%d") , objectID
) ;
678 m_fp
->WriteString( wxString::Format( wxT("\t%s *%s = new %s;\n"),
679 classInfo
->GetClassName(),
681 classInfo
->GetClassName()) );
682 m_data
->SetObjectName( objectID
, objectName
) ;
685 void wxCodeDepersister::DestroyObject(int objectID
, wxClassInfo
*WXUNUSED(classInfo
))
687 m_fp
->WriteString( wxString::Format( wxT("\tdelete %s;\n"),
688 m_data
->GetObjectName( objectID
).c_str() ) );
691 wxString
wxCodeDepersister::ValueAsCode( const wxxVariant
¶m
)
694 const wxTypeInfo
* type
= param
.GetTypeInfo() ;
695 if ( type
->GetKind() == wxT_CUSTOM
)
697 const wxCustomTypeInfo
* cti
= dynamic_cast<const wxCustomTypeInfo
*>(type
) ;
700 value
.Printf( wxT("%s(%s)"), cti
->GetTypeName().c_str(),param
.GetAsString().c_str() );
704 wxLogError ( _("Internal error, illegal wxCustomTypeInfo") ) ;
707 else if ( type
->GetKind() == wxT_STRING
)
709 value
.Printf( wxT("\"%s\""),param
.GetAsString().c_str() );
713 value
.Printf( wxT("%s"), param
.GetAsString().c_str() );
718 void wxCodeDepersister::CreateObject(int objectID
,
719 const wxClassInfo
*WXUNUSED(classInfo
),
723 const wxClassInfo
**WXUNUSED(objectClassInfos
) ,
724 wxxVariantArray
&WXUNUSED(metadata
)
728 m_fp
->WriteString( wxString::Format( wxT("\t%s->Create("), m_data
->GetObjectName(objectID
).c_str() ) );
729 for (i
= 0; i
< paramCount
; i
++)
731 if ( objectIDValues
[i
] != wxInvalidObjectID
)
732 m_fp
->WriteString( wxString::Format( wxT("%s"), m_data
->GetObjectName( objectIDValues
[i
] ).c_str() ) );
735 m_fp
->WriteString( wxString::Format( wxT("%s"), ValueAsCode(params
[i
]).c_str() ) );
737 if (i
< paramCount
- 1)
738 m_fp
->WriteString( wxT(", "));
740 m_fp
->WriteString( wxT(");\n") );
743 void wxCodeDepersister::ConstructObject(int objectID
,
744 const wxClassInfo
*classInfo
,
748 const wxClassInfo
**WXUNUSED(objectClassInfos
) ,
749 wxxVariantArray
&WXUNUSED(metadata
)
752 wxString objectName
= wxString::Format( wxT("LocalObject_%d") , objectID
) ;
753 m_fp
->WriteString( wxString::Format( wxT("\t%s *%s = new %s("),
754 classInfo
->GetClassName(),
756 classInfo
->GetClassName()) );
757 m_data
->SetObjectName( objectID
, objectName
) ;
760 for (i
= 0; i
< paramCount
; i
++)
762 if ( objectIDValues
[i
] != wxInvalidObjectID
)
763 m_fp
->WriteString( wxString::Format( wxT("%s"), m_data
->GetObjectName( objectIDValues
[i
] ).c_str() ) );
766 m_fp
->WriteString( wxString::Format( wxT("%s"), ValueAsCode(params
[i
]).c_str() ) );
768 if (i
< paramCount
- 1)
769 m_fp
->WriteString( wxT(", ") );
771 m_fp
->WriteString( wxT(");\n") );
774 void wxCodeDepersister::SetProperty(int objectID
,
775 const wxClassInfo
*WXUNUSED(classInfo
),
776 const wxPropertyInfo
* propertyInfo
,
777 const wxxVariant
&value
)
779 m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
780 m_data
->GetObjectName(objectID
).c_str(),
781 propertyInfo
->GetAccessor()->GetSetterName().c_str(),
782 ValueAsCode(value
).c_str()) );
785 void wxCodeDepersister::SetPropertyAsObject(int objectID
,
786 const wxClassInfo
*WXUNUSED(classInfo
),
787 const wxPropertyInfo
* propertyInfo
,
790 if ( propertyInfo
->GetTypeInfo()->GetKind() == wxT_OBJECT
)
791 m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(*%s);\n"),
792 m_data
->GetObjectName(objectID
).c_str(),
793 propertyInfo
->GetAccessor()->GetSetterName().c_str(),
794 m_data
->GetObjectName( valueObjectId
).c_str() ) );
796 m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
797 m_data
->GetObjectName(objectID
).c_str(),
798 propertyInfo
->GetAccessor()->GetSetterName().c_str(),
799 m_data
->GetObjectName( valueObjectId
).c_str() ) );
802 void wxCodeDepersister::AddToPropertyCollection( int objectID
,
803 const wxClassInfo
*WXUNUSED(classInfo
),
804 const wxPropertyInfo
* propertyInfo
,
805 const wxxVariant
&value
)
807 m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
808 m_data
->GetObjectName(objectID
).c_str(),
809 propertyInfo
->GetAccessor()->GetAdderName().c_str(),
810 ValueAsCode(value
).c_str()) );
813 // sets the corresponding property (value is an object)
814 void wxCodeDepersister::AddToPropertyCollectionAsObject(int WXUNUSED(objectID
),
815 const wxClassInfo
*WXUNUSED(classInfo
),
816 const wxPropertyInfo
* WXUNUSED(propertyInfo
) ,
817 int WXUNUSED(valueObjectId
))
822 void wxCodeDepersister::SetConnect(int eventSourceObjectID
,
823 const wxClassInfo
*WXUNUSED(eventSourceClassInfo
),
824 const wxPropertyInfo
*delegateInfo
,
825 const wxClassInfo
*eventSinkClassInfo
,
826 const wxHandlerInfo
* handlerInfo
,
827 int eventSinkObjectID
)
829 wxString ehsource
= m_data
->GetObjectName( eventSourceObjectID
) ;
830 wxString ehsink
= m_data
->GetObjectName(eventSinkObjectID
) ;
831 wxString ehsinkClass
= eventSinkClassInfo
->GetClassName() ;
832 const wxDelegateTypeInfo
*delegateTypeInfo
= dynamic_cast<const wxDelegateTypeInfo
*>(delegateInfo
->GetTypeInfo());
833 if ( delegateTypeInfo
)
835 int eventType
= delegateTypeInfo
->GetEventType() ;
836 wxString handlerName
= handlerInfo
->GetName() ;
838 m_fp
->WriteString( wxString::Format( wxT("\t%s->Connect( %s->GetId() , %d , (wxObjectEventFunction)(wxEventFunction) & %s::%s , NULL , %s ) ;") ,
839 ehsource
.c_str() , ehsource
.c_str() , eventType
, ehsinkClass
.c_str() , handlerName
.c_str() , ehsink
.c_str() ) );
843 wxLogError(_("delegate has no type info"));
847 #include <wx/arrimpl.cpp>
849 WX_DEFINE_OBJARRAY(wxxVariantArray
);