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") ) ;
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 for( wxPropertyInfoMap::iterator iter
= map
.begin() ; iter
!= map
.end() ; ++iter
)
177 const wxPropertyInfo
* prop
= iter
->second
;
178 if ( !(prop
->GetFlags() & wxPROP_OBJECT_GRAPH
) )
180 WriteOneProperty( obj
, prop
->GetDeclaringClass() , prop
, persister
, data
) ;
185 void wxWriter::WriteOneProperty( const wxObject
*obj
, const wxClassInfo
* ci
, const wxPropertyInfo
* pi
, wxPersister
*persister
, wxWriterInternalPropertiesData
*WXUNUSED(data
) )
187 if ( pi
->GetFlags() & wxPROP_DONT_STREAM
)
190 // make sure that we are picking the correct object for accessing the property
191 const wxDynamicObject
* dynobj
= dynamic_cast< const wxDynamicObject
* > (obj
) ;
192 if ( dynobj
&& (dynamic_cast<const wxDynamicClassInfo
*>(ci
) == NULL
) )
193 obj
= dynobj
->GetSuperClassInstance() ;
195 if ( pi
->GetTypeInfo()->GetKind() == wxT_COLLECTION
)
197 wxxVariantArray data
;
198 pi
->GetAccessor()->GetPropertyCollection(obj
, data
) ;
199 const wxTypeInfo
* elementType
= dynamic_cast< const wxCollectionTypeInfo
* >( pi
->GetTypeInfo() )->GetElementType() ;
200 for ( size_t i
= 0 ; i
< data
.GetCount() ; ++i
)
203 DoBeginWriteProperty( pi
) ;
205 DoBeginWriteElement() ;
206 wxxVariant value
= data
[i
] ;
207 if ( persister
->BeforeWriteProperty( this , obj
, pi
, value
) )
209 const wxClassTypeInfo
* cti
= dynamic_cast< const wxClassTypeInfo
* > ( elementType
) ;
212 const wxClassInfo
* pci
= cti
->GetClassInfo() ;
213 wxObject
*vobj
= pci
->VariantToInstance( value
) ;
215 WriteObject( vobj
, (vobj
? vobj
->GetClassInfo() : pci
) , persister
, cti
->GetKind()== wxT_OBJECT
, md
) ;
219 DoWriteSimpleType( value
) ;
222 DoEndWriteElement() ;
223 if ( i
== data
.GetCount() - 1 )
224 DoEndWriteProperty( pi
) ;
229 const wxDelegateTypeInfo
* dti
= dynamic_cast< const wxDelegateTypeInfo
* > ( pi
->GetTypeInfo() ) ;
232 const wxObject
* sink
= NULL
;
233 const wxHandlerInfo
*handler
= NULL
;
235 const wxEvtHandler
* evSource
= dynamic_cast<const wxEvtHandler
*>(obj
) ;
238 FindConnectEntry( evSource
, dti
, sink
, handler
) ;
239 if ( persister
->BeforeWriteDelegate( this , obj
, ci
, pi
, sink
, handler
) )
241 if ( sink
!= NULL
&& handler
!= NULL
)
243 DoBeginWriteProperty( pi
) ;
244 if ( IsObjectKnown( sink
) )
246 DoWriteDelegate( obj
, ci
, pi
, sink
, GetObjectID( sink
) , sink
->GetClassInfo() , handler
) ;
247 DoEndWriteProperty( pi
) ;
251 wxLogError( _("Streaming delegates for not already streamed objects not yet supported") ) ;
258 wxLogError(_("Illegal Object Class (Non-wxEvtHandler) as Event Source") ) ;
264 pi
->GetAccessor()->GetProperty(obj
, value
) ;
266 // avoid streaming out void objects
267 if( value
.IsEmpty() )
270 if ( pi
->GetFlags() & wxPROP_ENUM_STORE_LONG
)
272 const wxEnumTypeInfo
*eti
= dynamic_cast<const wxEnumTypeInfo
*>( pi
->GetTypeInfo() ) ;
275 eti
->ConvertFromLong( value
.wxTEMPLATED_MEMBER_CALL(Get
, long) , value
) ;
279 wxLogError( _("Type must have enum - long conversion") ) ;
283 // avoid streaming out default values
284 if ( pi
->GetTypeInfo()->HasStringConverters() && !pi
->GetDefaultValue().IsEmpty() )
286 if ( value
.GetAsString() == pi
->GetDefaultValue().GetAsString() )
290 // avoid streaming out null objects
291 const wxClassTypeInfo
* cti
= dynamic_cast< const wxClassTypeInfo
* > ( pi
->GetTypeInfo() ) ;
293 if ( cti
&& value
.GetAsObject() == NULL
)
296 if ( persister
->BeforeWriteProperty( this , obj
, pi
, value
) )
298 DoBeginWriteProperty( pi
) ;
301 const wxClassInfo
* pci
= cti
->GetClassInfo() ;
302 wxObject
*vobj
= pci
->VariantToInstance( value
) ;
303 if ( vobj
&& pi
->GetTypeInfo()->HasStringConverters() )
305 wxString stringValue
;
306 cti
->ConvertToString( value
, stringValue
) ;
307 wxxVariant
convertedValue(stringValue
) ;
308 DoWriteSimpleType( convertedValue
) ;
313 WriteObject( vobj
, (vobj
? vobj
->GetClassInfo() : pci
) , persister
, cti
->GetKind()== wxT_OBJECT
, md
) ;
318 DoWriteSimpleType( value
) ;
320 DoEndWriteProperty( pi
) ;
326 int wxWriter::GetObjectID(const wxObject
*obj
)
328 if ( !IsObjectKnown( obj
) )
329 return wxInvalidObjectID
;
331 return m_data
->m_writtenObjects
[obj
] ;
334 bool wxWriter::IsObjectKnown( const wxObject
*obj
)
336 return m_data
->m_writtenObjects
.find( obj
) != m_data
->m_writtenObjects
.end() ;
340 // ----------------------------------------------------------------------------
341 // reading objects in
342 // ----------------------------------------------------------------------------
344 struct wxReader::wxReaderInternal
346 map
<int,wxClassInfo
*> m_classInfos
;
351 m_data
= new wxReaderInternal
;
354 wxReader::~wxReader()
359 wxClassInfo
* wxReader::GetObjectClassInfo(int objectID
)
361 if ( objectID
== wxNullObjectID
|| objectID
== wxInvalidObjectID
)
363 wxLogError( _("Invalid or Null Object ID passed to GetObjectClassInfo" ) ) ;
366 if ( m_data
->m_classInfos
.find(objectID
) == m_data
->m_classInfos
.end() )
368 wxLogError( _("Unknown Object passed to GetObjectClassInfo" ) ) ;
371 return m_data
->m_classInfos
[objectID
] ;
374 void wxReader::SetObjectClassInfo(int objectID
, wxClassInfo
*classInfo
)
376 if ( objectID
== wxNullObjectID
|| objectID
== wxInvalidObjectID
)
378 wxLogError( _("Invalid or Null Object ID passed to GetObjectClassInfo" ) ) ;
381 if ( m_data
->m_classInfos
.find(objectID
) != m_data
->m_classInfos
.end() )
383 wxLogError( _("Already Registered Object passed to SetObjectClassInfo" ) ) ;
386 m_data
->m_classInfos
[objectID
] = classInfo
;
389 bool wxReader::HasObjectClassInfo( int objectID
)
391 if ( objectID
== wxNullObjectID
|| objectID
== wxInvalidObjectID
)
393 wxLogError( _("Invalid or Null Object ID passed to HasObjectClassInfo" ) ) ;
396 return m_data
->m_classInfos
.find(objectID
) != m_data
->m_classInfos
.end() ;
400 // ----------------------------------------------------------------------------
402 // ----------------------------------------------------------------------------
405 Reading components has not to be extended for components
406 as properties are always sought by typeinfo over all levels
407 and create params are always toplevel class only
411 // ----------------------------------------------------------------------------
412 // depersisting to memory
413 // ----------------------------------------------------------------------------
415 struct wxRuntimeDepersister::wxRuntimeDepersisterInternal
417 map
<int,wxObject
*> m_objects
;
419 void SetObject(int objectID
, wxObject
*obj
)
421 if ( m_objects
.find(objectID
) != m_objects
.end() )
423 wxLogError( _("Passing a already registered object to SetObject") ) ;
426 m_objects
[objectID
] = obj
;
428 wxObject
* GetObject( int objectID
)
430 if ( objectID
== wxNullObjectID
)
432 if ( m_objects
.find(objectID
) == m_objects
.end() )
434 wxLogError( _("Passing an unkown object to GetObject") ) ;
438 return m_objects
[objectID
] ;
442 wxRuntimeDepersister::wxRuntimeDepersister()
444 m_data
= new wxRuntimeDepersisterInternal() ;
447 wxRuntimeDepersister::~wxRuntimeDepersister()
452 void wxRuntimeDepersister::AllocateObject(int objectID
, wxClassInfo
*classInfo
,
453 wxxVariantArray
&WXUNUSED(metadata
))
456 O
= classInfo
->CreateObject();
457 m_data
->SetObject(objectID
, O
);
460 void wxRuntimeDepersister::CreateObject(int objectID
,
461 const wxClassInfo
*classInfo
,
465 const wxClassInfo
**objectClassInfos
,
466 wxxVariantArray
&WXUNUSED(metadata
))
469 o
= m_data
->GetObject(objectID
);
470 for ( int i
= 0 ; i
< paramCount
; ++i
)
472 if ( objectIdValues
[i
] != wxInvalidObjectID
)
475 o
= m_data
->GetObject(objectIdValues
[i
]);
476 // if this is a dynamic object and we are asked for another class
477 // than wxDynamicObject we cast it down manually.
478 wxDynamicObject
*dyno
= dynamic_cast< wxDynamicObject
* > (o
) ;
479 if ( dyno
!=NULL
&& (objectClassInfos
[i
] != dyno
->GetClassInfo()) )
481 o
= dyno
->GetSuperClassInstance() ;
483 params
[i
] = objectClassInfos
[i
]->InstanceToVariant(o
) ;
486 classInfo
->Create(o
, paramCount
, params
);
489 void wxRuntimeDepersister::ConstructObject(int objectID
,
490 const wxClassInfo
*classInfo
,
494 const wxClassInfo
**objectClassInfos
,
495 wxxVariantArray
&WXUNUSED(metadata
))
498 for ( int i
= 0 ; i
< paramCount
; ++i
)
500 if ( objectIdValues
[i
] != wxInvalidObjectID
)
503 o
= m_data
->GetObject(objectIdValues
[i
]);
504 // if this is a dynamic object and we are asked for another class
505 // than wxDynamicObject we cast it down manually.
506 wxDynamicObject
*dyno
= dynamic_cast< wxDynamicObject
* > (o
) ;
507 if ( dyno
!=NULL
&& (objectClassInfos
[i
] != dyno
->GetClassInfo()) )
509 o
= dyno
->GetSuperClassInstance() ;
511 params
[i
] = objectClassInfos
[i
]->InstanceToVariant(o
) ;
514 o
= classInfo
->ConstructObject(paramCount
, params
);
515 m_data
->SetObject(objectID
, o
);
519 void wxRuntimeDepersister::DestroyObject(int objectID
, wxClassInfo
*WXUNUSED(classInfo
))
522 o
= m_data
->GetObject(objectID
);
526 void wxRuntimeDepersister::SetProperty(int objectID
,
527 const wxClassInfo
*classInfo
,
528 const wxPropertyInfo
* propertyInfo
,
529 const wxxVariant
&value
)
532 o
= m_data
->GetObject(objectID
);
533 classInfo
->SetProperty( o
, propertyInfo
->GetName() , value
) ;
536 void wxRuntimeDepersister::SetPropertyAsObject(int objectID
,
537 const wxClassInfo
*classInfo
,
538 const wxPropertyInfo
* propertyInfo
,
542 o
= m_data
->GetObject(objectID
);
543 valo
= m_data
->GetObject(valueObjectId
);
544 const wxClassInfo
* valClassInfo
= (dynamic_cast<const wxClassTypeInfo
*>(propertyInfo
->GetTypeInfo()))->GetClassInfo() ;
545 // if this is a dynamic object and we are asked for another class
546 // than wxDynamicObject we cast it down manually.
547 wxDynamicObject
*dynvalo
= dynamic_cast< wxDynamicObject
* > (valo
) ;
548 if ( dynvalo
!=NULL
&& (valClassInfo
!= dynvalo
->GetClassInfo()) )
550 valo
= dynvalo
->GetSuperClassInstance() ;
553 classInfo
->SetProperty( o
, propertyInfo
->GetName() , valClassInfo
->InstanceToVariant(valo
) ) ;
556 void wxRuntimeDepersister::SetConnect(int eventSourceObjectID
,
557 const wxClassInfo
*WXUNUSED(eventSourceClassInfo
),
558 const wxPropertyInfo
*delegateInfo
,
559 const wxClassInfo
*WXUNUSED(eventSinkClassInfo
) ,
560 const wxHandlerInfo
* handlerInfo
,
561 int eventSinkObjectID
)
563 wxEvtHandler
*ehsource
= dynamic_cast< wxEvtHandler
* >( m_data
->GetObject( eventSourceObjectID
) ) ;
564 wxEvtHandler
*ehsink
= dynamic_cast< wxEvtHandler
*>(m_data
->GetObject(eventSinkObjectID
) ) ;
566 if ( ehsource
&& ehsink
)
568 const wxDelegateTypeInfo
*delegateTypeInfo
= dynamic_cast<const wxDelegateTypeInfo
*>(delegateInfo
->GetTypeInfo());
569 if( delegateTypeInfo
&& delegateTypeInfo
->GetLastEventType() == -1 )
571 ehsource
->Connect( -1 , delegateTypeInfo
->GetEventType() ,
572 handlerInfo
->GetEventFunction() , NULL
/*user data*/ ,
577 for ( wxEventType iter
= delegateTypeInfo
->GetEventType() ; iter
<= delegateTypeInfo
->GetLastEventType() ; ++iter
)
579 ehsource
->Connect( -1 , iter
,
580 handlerInfo
->GetEventFunction() , NULL
/*user data*/ ,
587 wxObject
*wxRuntimeDepersister::GetObject(int objectID
)
589 return m_data
->GetObject( objectID
) ;
592 // adds an element to a property collection
593 void wxRuntimeDepersister::AddToPropertyCollection( int objectID
,
594 const wxClassInfo
*classInfo
,
595 const wxPropertyInfo
* propertyInfo
,
596 const wxxVariant
&value
)
599 o
= m_data
->GetObject(objectID
);
600 classInfo
->AddToPropertyCollection( o
, propertyInfo
->GetName() , value
) ;
603 // sets the corresponding property (value is an object)
604 void wxRuntimeDepersister::AddToPropertyCollectionAsObject(int objectID
,
605 const wxClassInfo
*classInfo
,
606 const wxPropertyInfo
* propertyInfo
,
610 o
= m_data
->GetObject(objectID
);
611 valo
= m_data
->GetObject(valueObjectId
);
612 const wxCollectionTypeInfo
* collectionTypeInfo
= dynamic_cast< const wxCollectionTypeInfo
* >(propertyInfo
->GetTypeInfo() ) ;
613 const wxClassInfo
* valClassInfo
= (dynamic_cast<const wxClassTypeInfo
*>(collectionTypeInfo
->GetElementType()))->GetClassInfo() ;
614 // if this is a dynamic object and we are asked for another class
615 // than wxDynamicObject we cast it down manually.
616 wxDynamicObject
*dynvalo
= dynamic_cast< wxDynamicObject
* > (valo
) ;
617 if ( dynvalo
!=NULL
&& (valClassInfo
!= dynvalo
->GetClassInfo()) )
619 valo
= dynvalo
->GetSuperClassInstance() ;
622 classInfo
->AddToPropertyCollection( o
, propertyInfo
->GetName() , valClassInfo
->InstanceToVariant(valo
) ) ;
625 // ----------------------------------------------------------------------------
626 // depersisting to code
627 // ----------------------------------------------------------------------------
629 struct wxCodeDepersister::wxCodeDepersisterInternal
632 map
<int,wstring
> m_objectNames
;
634 map
<int,string
> m_objectNames
;
637 void SetObjectName(int objectID
, const wxString
&name
)
639 if ( m_objectNames
.find(objectID
) != m_objectNames
.end() )
641 wxLogError( _("Passing a already registered object to SetObjectName") ) ;
644 m_objectNames
[objectID
] = (const wxChar
*)name
;
647 wxString
GetObjectName( int objectID
)
649 if ( objectID
== wxNullObjectID
)
652 if ( m_objectNames
.find(objectID
) == m_objectNames
.end() )
654 wxLogError( _("Passing an unkown object to GetObject") ) ;
655 return wxEmptyString
;
657 return wxString( m_objectNames
[objectID
].c_str() ) ;
661 wxCodeDepersister::wxCodeDepersister(wxTextOutputStream
*out
)
664 m_data
= new wxCodeDepersisterInternal
;
667 wxCodeDepersister::~wxCodeDepersister()
672 void wxCodeDepersister::AllocateObject(int objectID
, wxClassInfo
*classInfo
,
673 wxxVariantArray
&WXUNUSED(metadata
))
675 wxString objectName
= wxString::Format( wxT("LocalObject_%d") , objectID
) ;
676 m_fp
->WriteString( wxString::Format( wxT("\t%s *%s = new %s;\n"),
677 classInfo
->GetClassName(),
679 classInfo
->GetClassName()) );
680 m_data
->SetObjectName( objectID
, objectName
) ;
683 void wxCodeDepersister::DestroyObject(int objectID
, wxClassInfo
*WXUNUSED(classInfo
))
685 m_fp
->WriteString( wxString::Format( wxT("\tdelete %s;\n"),
686 m_data
->GetObjectName( objectID
).c_str() ) );
689 wxString
wxCodeDepersister::ValueAsCode( const wxxVariant
¶m
)
692 const wxTypeInfo
* type
= param
.GetTypeInfo() ;
693 if ( type
->GetKind() == wxT_CUSTOM
)
695 const wxCustomTypeInfo
* cti
= dynamic_cast<const wxCustomTypeInfo
*>(type
) ;
698 value
.Printf( wxT("%s(%s)"), cti
->GetTypeName().c_str(),param
.GetAsString().c_str() );
702 wxLogError ( _("Internal error, illegal wxCustomTypeInfo") ) ;
705 else if ( type
->GetKind() == wxT_STRING
)
707 value
.Printf( wxT("\"%s\""),param
.GetAsString().c_str() );
711 value
.Printf( wxT("%s"), param
.GetAsString().c_str() );
716 void wxCodeDepersister::CreateObject(int objectID
,
717 const wxClassInfo
*WXUNUSED(classInfo
),
721 const wxClassInfo
**WXUNUSED(objectClassInfos
) ,
722 wxxVariantArray
&WXUNUSED(metadata
)
726 m_fp
->WriteString( wxString::Format( wxT("\t%s->Create("), m_data
->GetObjectName(objectID
).c_str() ) );
727 for (i
= 0; i
< paramCount
; i
++)
729 if ( objectIDValues
[i
] != wxInvalidObjectID
)
730 m_fp
->WriteString( wxString::Format( wxT("%s"), m_data
->GetObjectName( objectIDValues
[i
] ).c_str() ) );
733 m_fp
->WriteString( wxString::Format( wxT("%s"), ValueAsCode(params
[i
]).c_str() ) );
735 if (i
< paramCount
- 1)
736 m_fp
->WriteString( wxT(", "));
738 m_fp
->WriteString( wxT(");\n") );
741 void wxCodeDepersister::ConstructObject(int objectID
,
742 const wxClassInfo
*classInfo
,
746 const wxClassInfo
**WXUNUSED(objectClassInfos
) ,
747 wxxVariantArray
&WXUNUSED(metadata
)
750 wxString objectName
= wxString::Format( wxT("LocalObject_%d") , objectID
) ;
751 m_fp
->WriteString( wxString::Format( wxT("\t%s *%s = new %s("),
752 classInfo
->GetClassName(),
754 classInfo
->GetClassName()) );
755 m_data
->SetObjectName( objectID
, objectName
) ;
758 for (i
= 0; i
< paramCount
; i
++)
760 if ( objectIDValues
[i
] != wxInvalidObjectID
)
761 m_fp
->WriteString( wxString::Format( wxT("%s"), m_data
->GetObjectName( objectIDValues
[i
] ).c_str() ) );
764 m_fp
->WriteString( wxString::Format( wxT("%s"), ValueAsCode(params
[i
]).c_str() ) );
766 if (i
< paramCount
- 1)
767 m_fp
->WriteString( wxT(", ") );
769 m_fp
->WriteString( wxT(");\n") );
772 void wxCodeDepersister::SetProperty(int objectID
,
773 const wxClassInfo
*WXUNUSED(classInfo
),
774 const wxPropertyInfo
* propertyInfo
,
775 const wxxVariant
&value
)
777 m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
778 m_data
->GetObjectName(objectID
).c_str(),
779 propertyInfo
->GetAccessor()->GetSetterName().c_str(),
780 ValueAsCode(value
).c_str()) );
783 void wxCodeDepersister::SetPropertyAsObject(int objectID
,
784 const wxClassInfo
*WXUNUSED(classInfo
),
785 const wxPropertyInfo
* propertyInfo
,
788 if ( propertyInfo
->GetTypeInfo()->GetKind() == wxT_OBJECT
)
789 m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(*%s);\n"),
790 m_data
->GetObjectName(objectID
).c_str(),
791 propertyInfo
->GetAccessor()->GetSetterName().c_str(),
792 m_data
->GetObjectName( valueObjectId
).c_str() ) );
794 m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
795 m_data
->GetObjectName(objectID
).c_str(),
796 propertyInfo
->GetAccessor()->GetSetterName().c_str(),
797 m_data
->GetObjectName( valueObjectId
).c_str() ) );
800 void wxCodeDepersister::AddToPropertyCollection( int objectID
,
801 const wxClassInfo
*WXUNUSED(classInfo
),
802 const wxPropertyInfo
* propertyInfo
,
803 const wxxVariant
&value
)
805 m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"),
806 m_data
->GetObjectName(objectID
).c_str(),
807 propertyInfo
->GetAccessor()->GetAdderName().c_str(),
808 ValueAsCode(value
).c_str()) );
811 // sets the corresponding property (value is an object)
812 void wxCodeDepersister::AddToPropertyCollectionAsObject(int WXUNUSED(objectID
),
813 const wxClassInfo
*WXUNUSED(classInfo
),
814 const wxPropertyInfo
* WXUNUSED(propertyInfo
) ,
815 int WXUNUSED(valueObjectId
))
820 void wxCodeDepersister::SetConnect(int eventSourceObjectID
,
821 const wxClassInfo
*WXUNUSED(eventSourceClassInfo
),
822 const wxPropertyInfo
*delegateInfo
,
823 const wxClassInfo
*eventSinkClassInfo
,
824 const wxHandlerInfo
* handlerInfo
,
825 int eventSinkObjectID
)
827 wxString ehsource
= m_data
->GetObjectName( eventSourceObjectID
) ;
828 wxString ehsink
= m_data
->GetObjectName(eventSinkObjectID
) ;
829 wxString ehsinkClass
= eventSinkClassInfo
->GetClassName() ;
830 const wxDelegateTypeInfo
*delegateTypeInfo
= dynamic_cast<const wxDelegateTypeInfo
*>(delegateInfo
->GetTypeInfo());
831 if ( delegateTypeInfo
)
833 int eventType
= delegateTypeInfo
->GetEventType() ;
834 wxString handlerName
= handlerInfo
->GetName() ;
836 m_fp
->WriteString( wxString::Format( wxT("\t%s->Connect( %s->GetId() , %d , (wxObjectEventFunction)(wxEventFunction) & %s::%s , NULL , %s ) ;") ,
837 ehsource
.c_str() , ehsource
.c_str() , eventType
, ehsinkClass
.c_str() , handlerName
.c_str() , ehsink
.c_str() ) );
841 wxLogError(_("delegate has no type info"));
845 #include <wx/arrimpl.cpp>
847 WX_DEFINE_OBJARRAY(wxxVariantArray
);