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 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  21 #include "wx/object.h" 
  24 #include "wx/tokenzr.h" 
  25 #include "wx/txtstrm.h" 
  28 #if wxUSE_EXTENDED_RTTI 
  30 #include "wx/xtistrm.h" 
  32 #include "wx/beforestd.h" 
  36 #include "wx/afterstd.h" 
  40 struct wxWriter::wxWriterInternal
 
  42     map
< const wxObject
* , int > m_writtenObjects 
; 
  48     m_data 
= new wxWriterInternal 
; 
  49     m_data
->m_nextId 
= 0 ; 
  57 struct wxWriter::wxWriterInternalPropertiesData
 
  62 void wxWriter::ClearObjectContext() 
  65     m_data 
= new wxWriterInternal() ; 
  66     m_data
->m_nextId 
= 0 ; 
  69 void wxWriter::WriteObject(const wxObject 
*object
, const wxClassInfo 
*classInfo 
, wxPersister 
*persister 
, const wxString 
&name 
, wxxVariantArray 
&metadata 
) 
  71     DoBeginWriteTopLevelEntry( name 
) ; 
  72     WriteObject( object 
, classInfo 
, persister 
, false , metadata
) ; 
  73     DoEndWriteTopLevelEntry( name 
) ; 
  76 void wxWriter::WriteObject(const wxObject 
*object
, const wxClassInfo 
*classInfo 
, wxPersister 
*persister 
, bool isEmbedded
, wxxVariantArray 
&metadata 
) 
  78     if ( !classInfo
->BeforeWriteObject( object 
, this , persister 
, metadata
) ) 
  81     if ( persister
->BeforeWriteObject( this , object 
, classInfo 
, metadata
) ) 
  85         else if ( IsObjectKnown( object 
) ) 
  86             DoWriteRepeatedObject( GetObjectID(object
) ) ; 
  89             int oid 
= m_data
->m_nextId
++ ; 
  91                 m_data
->m_writtenObjects
[object
] = oid 
; 
  93             // in case this object is a wxDynamicObject we also have to insert is superclass 
  94             // instance with the same id, so that object relations are streamed out correctly 
  95             const wxDynamicObject
* dynobj 
= dynamic_cast<const wxDynamicObject 
*>( object 
) ; 
  96             if ( !isEmbedded 
&& dynobj 
) 
  97                 m_data
->m_writtenObjects
[dynobj
->GetSuperClassInstance()] = oid 
; 
  99             DoBeginWriteObject( object 
, classInfo 
, oid 
, metadata 
) ; 
 100             wxWriterInternalPropertiesData data 
; 
 101             WriteAllProperties( object 
, classInfo 
, persister 
, &data 
) ; 
 102             DoEndWriteObject( object 
, classInfo 
, oid  
) ; 
 104         persister
->AfterWriteObject( this ,object 
, classInfo 
) ; 
 108 void wxWriter::FindConnectEntry(const wxEvtHandler 
* evSource
,const wxDelegateTypeInfo
* dti
, const wxObject
* &sink 
, const wxHandlerInfo 
*&handler
) 
 110     wxList 
*dynamicEvents 
= evSource
->GetDynamicEventTable() ; 
 114         wxList::compatibility_iterator node 
= dynamicEvents
->GetFirst(); 
 117             wxDynamicEventTableEntry 
*entry 
= (wxDynamicEventTableEntry
*)node
->GetData(); 
 121                 (dti
->GetEventType() == entry
->m_eventType
) && 
 122                 (entry
->m_id 
== -1 ) && 
 123                 (entry
->m_eventSink 
!= NULL 
) ) 
 125                 sink 
= entry
->m_eventSink 
; 
 126                 const wxClassInfo
* sinkClassInfo 
= sink
->GetClassInfo() ; 
 127                 const wxHandlerInfo
* sinkHandler 
= sinkClassInfo
->GetFirstHandler() ; 
 128                 while ( sinkHandler 
) 
 130                     if ( sinkHandler
->GetEventFunction() == entry
->m_fn 
) 
 132                         handler 
= sinkHandler 
; 
 135                     sinkHandler 
= sinkHandler
->GetNext() ; 
 139             node 
= node
->GetNext(); 
 143 void wxWriter::WriteAllProperties( const wxObject 
* obj 
, const wxClassInfo
* ci 
, wxPersister 
*persister
, wxWriterInternalPropertiesData 
* data 
) 
 145     wxPropertyInfoMap map 
; 
 146     ci
->GetProperties( map 
) ; 
 147     for ( int i 
= 0 ; i 
< ci
->GetCreateParamCount() ; ++i 
) 
 149         wxString name 
= ci
->GetCreateParamName(i
) ; 
 150         const wxPropertyInfo
* prop 
= map
.find(name
)->second 
; 
 153             WriteOneProperty( obj 
, prop
->GetDeclaringClass() , prop 
, persister 
, data 
) ; 
 157             wxLogError( _("Create Parameter not found in declared RTTI Parameters") ) ; 
 161     { // Extra block for broken compilers 
 162         for( wxPropertyInfoMap::iterator iter 
= map
.begin() ; iter 
!= map
.end() ; ++iter 
) 
 164             const wxPropertyInfo
* prop 
= iter
->second 
; 
 165             if ( prop
->GetFlags() & wxPROP_OBJECT_GRAPH 
) 
 167                 WriteOneProperty( obj 
, prop
->GetDeclaringClass() , prop 
, persister 
, data 
) ; 
 171     { // Extra block for broken compilers 
 172         for( wxPropertyInfoMap::iterator iter 
= map
.begin() ; iter 
!= map
.end() ; ++iter 
) 
 174             const wxPropertyInfo
* prop 
= iter
->second 
; 
 175             if ( !(prop
->GetFlags() & wxPROP_OBJECT_GRAPH
) ) 
 177                 WriteOneProperty( obj 
, prop
->GetDeclaringClass() , prop 
, persister 
, data 
) ; 
 183 void wxWriter::WriteOneProperty( const wxObject 
*obj 
, const wxClassInfo
* ci 
, const wxPropertyInfo
* pi 
, wxPersister 
*persister 
, wxWriterInternalPropertiesData 
*WXUNUSED(data
) ) 
 185     if ( pi
->GetFlags() & wxPROP_DONT_STREAM 
) 
 188     // make sure that we are picking the correct object for accessing the property 
 189     const wxDynamicObject
* dynobj 
= dynamic_cast< const wxDynamicObject
* > (obj 
) ; 
 190     if ( dynobj 
&& (dynamic_cast<const wxDynamicClassInfo
*>(ci
) == NULL
) ) 
 191         obj 
= dynobj
->GetSuperClassInstance() ; 
 193     if ( pi
->GetTypeInfo()->GetKind() == wxT_COLLECTION 
) 
 195         wxxVariantArray data 
; 
 196         pi
->GetAccessor()->GetPropertyCollection(obj
, data
) ; 
 197         const wxTypeInfo 
* elementType 
= dynamic_cast< const wxCollectionTypeInfo
* >( pi
->GetTypeInfo() )->GetElementType() ; 
 198         for ( size_t i 
= 0 ; i 
< data
.GetCount() ; ++i 
) 
 201                 DoBeginWriteProperty( pi 
) ; 
 203             DoBeginWriteElement() ; 
 204             wxxVariant value 
= data
[i
] ; 
 205             if ( persister
->BeforeWriteProperty( this , obj
, pi 
, value 
) ) 
 207                 const wxClassTypeInfo
* cti 
= dynamic_cast< const wxClassTypeInfo
* > ( elementType 
) ; 
 210                     const wxClassInfo
* pci 
= cti
->GetClassInfo() ; 
 211                     wxObject 
*vobj 
= pci
->VariantToInstance( value 
) ; 
 213                     WriteObject( vobj 
, (vobj 
? vobj
->GetClassInfo() : pci 
) , persister 
, cti
->GetKind()== wxT_OBJECT 
, md 
) ; 
 217                     DoWriteSimpleType( value 
) ; 
 220             DoEndWriteElement() ; 
 221             if ( i 
== data
.GetCount() - 1 ) 
 222                  DoEndWriteProperty( pi 
) ; 
 227         const wxDelegateTypeInfo
* dti 
= dynamic_cast< const wxDelegateTypeInfo
* > ( pi
->GetTypeInfo() ) ; 
 230             const wxObject
* sink 
= NULL 
; 
 231             const wxHandlerInfo 
*handler 
= NULL 
; 
 233             const wxEvtHandler 
* evSource 
= dynamic_cast<const wxEvtHandler 
*>(obj
) ; 
 236                 FindConnectEntry( evSource 
, dti 
, sink 
, handler 
) ; 
 237                 if ( persister
->BeforeWriteDelegate( this , obj 
, ci 
, pi 
, sink 
, handler 
) ) 
 239                     if ( sink 
!= NULL 
&& handler 
!= NULL 
) 
 241                         DoBeginWriteProperty( pi 
) ; 
 242                         if ( IsObjectKnown( sink 
) ) 
 244                             DoWriteDelegate( obj 
, ci 
, pi 
, sink 
, GetObjectID( sink 
) , sink
->GetClassInfo() , handler 
) ; 
 245                             DoEndWriteProperty( pi 
) ; 
 249                             wxLogError( _("Streaming delegates for not already streamed objects not yet supported") ) ; 
 256                 wxLogError(_("Illegal Object Class (Non-wxEvtHandler) as Event Source") ) ; 
 262             pi
->GetAccessor()->GetProperty(obj
, value
) ; 
 264             // avoid streaming out void objects 
 265             if( value
.IsEmpty() ) 
 268             if ( pi
->GetFlags() & wxPROP_ENUM_STORE_LONG 
) 
 270                 const wxEnumTypeInfo 
*eti 
= dynamic_cast<const wxEnumTypeInfo
*>( pi
->GetTypeInfo() ) ; 
 273                     eti
->ConvertFromLong( value
.wxTEMPLATED_MEMBER_CALL(Get 
, long) , value 
) ; 
 277                     wxLogError( _("Type must have enum - long conversion") ) ; 
 281             // avoid streaming out default values 
 282             if ( pi
->GetTypeInfo()->HasStringConverters() && !pi
->GetDefaultValue().IsEmpty() ) 
 284                 if ( value
.GetAsString() == pi
->GetDefaultValue().GetAsString() ) 
 288             // avoid streaming out null objects 
 289             const wxClassTypeInfo
* cti 
= dynamic_cast< const wxClassTypeInfo
* > ( pi
->GetTypeInfo() ) ; 
 291             if ( cti 
&& value
.GetAsObject() == NULL 
) 
 294             if ( persister
->BeforeWriteProperty( this , obj
, pi 
, value 
) ) 
 296                 DoBeginWriteProperty( pi 
) ; 
 299                     const wxClassInfo
* pci 
= cti
->GetClassInfo() ; 
 300                     wxObject 
*vobj 
= pci
->VariantToInstance( value 
) ; 
 301                     if ( vobj 
&& pi
->GetTypeInfo()->HasStringConverters() ) 
 303                         wxString stringValue 
; 
 304                         cti
->ConvertToString( value 
, stringValue 
) ; 
 305                         wxxVariant 
convertedValue(stringValue
) ; 
 306                         DoWriteSimpleType( convertedValue 
) ; 
 311                         WriteObject( vobj 
, (vobj 
? vobj
->GetClassInfo() : pci 
) , persister 
, cti
->GetKind()== wxT_OBJECT 
, md
) ; 
 316                     DoWriteSimpleType( value 
) ; 
 318                 DoEndWriteProperty( pi 
) ; 
 324 int wxWriter::GetObjectID(const wxObject 
*obj
) 
 326     if ( !IsObjectKnown( obj 
) ) 
 327         return wxInvalidObjectID 
; 
 329     return m_data
->m_writtenObjects
[obj
] ; 
 332 bool wxWriter::IsObjectKnown( const wxObject 
*obj 
) 
 334     return m_data
->m_writtenObjects
.find( obj 
) != m_data
->m_writtenObjects
.end() ; 
 338 // ---------------------------------------------------------------------------- 
 339 // reading objects in 
 340 // ---------------------------------------------------------------------------- 
 342 struct wxReader::wxReaderInternal
 
 344     map
<int,wxClassInfo
*> m_classInfos
; 
 349     m_data 
= new wxReaderInternal
; 
 352 wxReader::~wxReader() 
 357 wxClassInfo
* wxReader::GetObjectClassInfo(int objectID
) 
 359     if ( objectID 
== wxNullObjectID 
|| objectID 
== wxInvalidObjectID 
) 
 361         wxLogError( _("Invalid or Null Object ID passed to GetObjectClassInfo" ) ) ; 
 364     if ( m_data
->m_classInfos
.find(objectID
) == m_data
->m_classInfos
.end() ) 
 366         wxLogError( _("Unknown Object passed to GetObjectClassInfo" ) ) ; 
 369     return m_data
->m_classInfos
[objectID
] ; 
 372 void wxReader::SetObjectClassInfo(int objectID
, wxClassInfo 
*classInfo 
) 
 374     if ( objectID 
== wxNullObjectID 
|| objectID 
== wxInvalidObjectID 
) 
 376         wxLogError( _("Invalid or Null Object ID passed to GetObjectClassInfo" ) ) ; 
 379     if ( m_data
->m_classInfos
.find(objectID
) != m_data
->m_classInfos
.end() ) 
 381         wxLogError( _("Already Registered Object passed to SetObjectClassInfo" ) ) ; 
 384     m_data
->m_classInfos
[objectID
] = classInfo 
; 
 387 bool wxReader::HasObjectClassInfo( int objectID 
) 
 389     if ( objectID 
== wxNullObjectID 
|| objectID 
== wxInvalidObjectID 
) 
 391         wxLogError( _("Invalid or Null Object ID passed to HasObjectClassInfo" ) ) ; 
 394     return m_data
->m_classInfos
.find(objectID
) != m_data
->m_classInfos
.end() ; 
 398 // ---------------------------------------------------------------------------- 
 400 // ---------------------------------------------------------------------------- 
 403 Reading components has not to be extended for components 
 404 as properties are always sought by typeinfo over all levels 
 405 and create params are always toplevel class only 
 409 // ---------------------------------------------------------------------------- 
 410 // depersisting to memory 
 411 // ---------------------------------------------------------------------------- 
 413 struct wxRuntimeDepersister::wxRuntimeDepersisterInternal
 
 415     map
<int,wxObject 
*> m_objects
; 
 417     void SetObject(int objectID
, wxObject 
*obj 
) 
 419         if ( m_objects
.find(objectID
) != m_objects
.end() ) 
 421             wxLogError( _("Passing a already registered object to SetObject") ) ; 
 424         m_objects
[objectID
] = obj 
; 
 426     wxObject
* GetObject( int objectID 
) 
 428         if ( objectID 
== wxNullObjectID 
) 
 430         if ( m_objects
.find(objectID
) == m_objects
.end() ) 
 432             wxLogError( _("Passing an unkown object to GetObject") ) ; 
 436         return m_objects
[objectID
] ; 
 440 wxRuntimeDepersister::wxRuntimeDepersister() 
 442     m_data 
= new wxRuntimeDepersisterInternal() ; 
 445 wxRuntimeDepersister::~wxRuntimeDepersister() 
 450 void wxRuntimeDepersister::AllocateObject(int objectID
, wxClassInfo 
*classInfo 
, 
 451                                           wxxVariantArray 
&WXUNUSED(metadata
)) 
 454     O 
= classInfo
->CreateObject(); 
 455     m_data
->SetObject(objectID
, O
); 
 458 void wxRuntimeDepersister::CreateObject(int objectID
, 
 459                                         const wxClassInfo 
*classInfo
, 
 463                                         const wxClassInfo 
**objectClassInfos 
, 
 464                                         wxxVariantArray 
&WXUNUSED(metadata
)) 
 467     o 
= m_data
->GetObject(objectID
); 
 468     for ( int i 
= 0 ; i 
< paramCount 
; ++i 
) 
 470         if ( objectIdValues
[i
] != wxInvalidObjectID 
) 
 473             o 
= m_data
->GetObject(objectIdValues
[i
]); 
 474             // if this is a dynamic object and we are asked for another class 
 475             // than wxDynamicObject we cast it down manually. 
 476             wxDynamicObject 
*dyno 
= dynamic_cast< wxDynamicObject 
* > (o
) ; 
 477             if ( dyno
!=NULL 
&& (objectClassInfos
[i
] != dyno
->GetClassInfo()) ) 
 479                 o 
= dyno
->GetSuperClassInstance() ; 
 481             params
[i
] = objectClassInfos
[i
]->InstanceToVariant(o
) ; 
 484     classInfo
->Create(o
, paramCount
, params
); 
 487 void wxRuntimeDepersister::ConstructObject(int objectID
, 
 488                                         const wxClassInfo 
*classInfo
, 
 492                                         const wxClassInfo 
**objectClassInfos 
, 
 493                                         wxxVariantArray 
&WXUNUSED(metadata
)) 
 496     for ( int i 
= 0 ; i 
< paramCount 
; ++i 
) 
 498         if ( objectIdValues
[i
] != wxInvalidObjectID 
) 
 501             o 
= m_data
->GetObject(objectIdValues
[i
]); 
 502             // if this is a dynamic object and we are asked for another class 
 503             // than wxDynamicObject we cast it down manually. 
 504             wxDynamicObject 
*dyno 
= dynamic_cast< wxDynamicObject 
* > (o
) ; 
 505             if ( dyno
!=NULL 
&& (objectClassInfos
[i
] != dyno
->GetClassInfo()) ) 
 507                 o 
= dyno
->GetSuperClassInstance() ; 
 509             params
[i
] = objectClassInfos
[i
]->InstanceToVariant(o
) ; 
 512     o 
= classInfo
->ConstructObject(paramCount
, params
); 
 513     m_data
->SetObject(objectID
, o
); 
 517 void wxRuntimeDepersister::DestroyObject(int objectID
, wxClassInfo 
*WXUNUSED(classInfo
)) 
 520     o 
= m_data
->GetObject(objectID
); 
 524 void wxRuntimeDepersister::SetProperty(int objectID
, 
 525                                        const wxClassInfo 
*classInfo
, 
 526                                        const wxPropertyInfo
* propertyInfo
, 
 527                                        const wxxVariant 
&value
) 
 530     o 
= m_data
->GetObject(objectID
); 
 531     classInfo
->SetProperty( o 
, propertyInfo
->GetName() , value 
) ; 
 534 void wxRuntimeDepersister::SetPropertyAsObject(int objectID
, 
 535                                                const wxClassInfo 
*classInfo
, 
 536                                                const wxPropertyInfo
* propertyInfo
, 
 540     o 
= m_data
->GetObject(objectID
); 
 541     valo 
= m_data
->GetObject(valueObjectId
); 
 542     const wxClassInfo
* valClassInfo 
= (dynamic_cast<const wxClassTypeInfo
*>(propertyInfo
->GetTypeInfo()))->GetClassInfo() ; 
 543     // if this is a dynamic object and we are asked for another class 
 544     // than wxDynamicObject we cast it down manually. 
 545     wxDynamicObject 
*dynvalo 
= dynamic_cast< wxDynamicObject 
* > (valo
) ; 
 546     if ( dynvalo
!=NULL  
&& (valClassInfo 
!= dynvalo
->GetClassInfo()) ) 
 548         valo 
= dynvalo
->GetSuperClassInstance() ; 
 551     classInfo
->SetProperty( o 
, propertyInfo
->GetName() , valClassInfo
->InstanceToVariant(valo
) ) ; 
 554 void wxRuntimeDepersister::SetConnect(int eventSourceObjectID
, 
 555                                       const wxClassInfo 
*WXUNUSED(eventSourceClassInfo
), 
 556                                       const wxPropertyInfo 
*delegateInfo 
, 
 557                                       const wxClassInfo 
*WXUNUSED(eventSinkClassInfo
) , 
 558                                       const wxHandlerInfo
* handlerInfo 
, 
 559                                       int eventSinkObjectID 
) 
 561     wxEvtHandler 
*ehsource 
= dynamic_cast< wxEvtHandler
* >( m_data
->GetObject( eventSourceObjectID 
) ) ; 
 562     wxEvtHandler 
*ehsink 
= dynamic_cast< wxEvtHandler 
*>(m_data
->GetObject(eventSinkObjectID
) ) ; 
 564     if ( ehsource 
&& ehsink 
) 
 566         const wxDelegateTypeInfo 
*delegateTypeInfo 
= dynamic_cast<const wxDelegateTypeInfo
*>(delegateInfo
->GetTypeInfo()); 
 567         if( delegateTypeInfo 
&& delegateTypeInfo
->GetLastEventType() == -1 ) 
 569             ehsource
->Connect( -1 , delegateTypeInfo
->GetEventType() , 
 570                 handlerInfo
->GetEventFunction() , NULL 
/*user data*/ , 
 575             for ( wxEventType iter 
= delegateTypeInfo
->GetEventType() ; iter 
<= delegateTypeInfo
->GetLastEventType() ; ++iter 
) 
 577                 ehsource
->Connect( -1 , iter 
, 
 578                     handlerInfo
->GetEventFunction() , NULL 
/*user data*/ , 
 585 wxObject 
*wxRuntimeDepersister::GetObject(int objectID
) 
 587     return m_data
->GetObject( objectID 
) ; 
 590 // adds an element to a property collection 
 591 void wxRuntimeDepersister::AddToPropertyCollection( int objectID 
, 
 592                                                    const wxClassInfo 
*classInfo
, 
 593                                                    const wxPropertyInfo
* propertyInfo 
, 
 594                                                    const wxxVariant 
&value
) 
 597     o 
= m_data
->GetObject(objectID
); 
 598     classInfo
->AddToPropertyCollection( o 
, propertyInfo
->GetName() , value 
) ; 
 601 // sets the corresponding property (value is an object) 
 602 void wxRuntimeDepersister::AddToPropertyCollectionAsObject(int objectID
, 
 603                                                            const wxClassInfo 
*classInfo
, 
 604                                                            const wxPropertyInfo
* propertyInfo 
, 
 608     o 
= m_data
->GetObject(objectID
); 
 609     valo 
= m_data
->GetObject(valueObjectId
); 
 610     const wxCollectionTypeInfo 
* collectionTypeInfo 
= dynamic_cast< const wxCollectionTypeInfo 
* >(propertyInfo
->GetTypeInfo() ) ; 
 611     const wxClassInfo
* valClassInfo 
= (dynamic_cast<const wxClassTypeInfo
*>(collectionTypeInfo
->GetElementType()))->GetClassInfo() ; 
 612     // if this is a dynamic object and we are asked for another class 
 613     // than wxDynamicObject we cast it down manually. 
 614     wxDynamicObject 
*dynvalo 
= dynamic_cast< wxDynamicObject 
* > (valo
) ; 
 615     if ( dynvalo
!=NULL  
&& (valClassInfo 
!= dynvalo
->GetClassInfo()) ) 
 617         valo 
= dynvalo
->GetSuperClassInstance() ; 
 620     classInfo
->AddToPropertyCollection( o 
, propertyInfo
->GetName() , valClassInfo
->InstanceToVariant(valo
) ) ; 
 623 // ---------------------------------------------------------------------------- 
 624 // depersisting to code 
 625 // ---------------------------------------------------------------------------- 
 627 struct wxCodeDepersister::wxCodeDepersisterInternal
 
 630     map
<int,wstring
> m_objectNames 
; 
 632     map
<int,string
> m_objectNames 
; 
 635     void SetObjectName(int objectID
, const wxString 
&name 
) 
 637         if ( m_objectNames
.find(objectID
) != m_objectNames
.end() ) 
 639             wxLogError( _("Passing a already registered object to SetObjectName") ) ; 
 642         m_objectNames
[objectID
] = (const wxChar 
*)name
; 
 645     wxString 
GetObjectName( int objectID 
) 
 647         if ( objectID 
== wxNullObjectID 
) 
 650         if ( m_objectNames
.find(objectID
) == m_objectNames
.end() ) 
 652             wxLogError( _("Passing an unkown object to GetObject") ) ; 
 653             return wxEmptyString 
; 
 655         return wxString( m_objectNames
[objectID
].c_str() ) ; 
 659 wxCodeDepersister::wxCodeDepersister(wxTextOutputStream 
*out
) 
 662     m_data 
= new wxCodeDepersisterInternal 
; 
 665 wxCodeDepersister::~wxCodeDepersister() 
 670 void wxCodeDepersister::AllocateObject(int objectID
, wxClassInfo 
*classInfo 
, 
 671                                        wxxVariantArray 
&WXUNUSED(metadata
)) 
 673     wxString objectName 
= wxString::Format( wxT("LocalObject_%d") , objectID 
) ; 
 674     m_fp
->WriteString( wxString::Format( wxT("\t%s *%s = new %s;\n"), 
 675         classInfo
->GetClassName(), 
 677         classInfo
->GetClassName()) ); 
 678     m_data
->SetObjectName( objectID 
, objectName 
) ; 
 681 void wxCodeDepersister::DestroyObject(int objectID
, wxClassInfo 
*WXUNUSED(classInfo
)) 
 683     m_fp
->WriteString( wxString::Format( wxT("\tdelete %s;\n"), 
 684         m_data
->GetObjectName( objectID
).c_str() ) ); 
 687 wxString 
wxCodeDepersister::ValueAsCode( const wxxVariant 
¶m 
) 
 690     const wxTypeInfo
* type 
= param
.GetTypeInfo() ; 
 691     if ( type
->GetKind() == wxT_CUSTOM 
) 
 693         const wxCustomTypeInfo
* cti 
= dynamic_cast<const wxCustomTypeInfo
*>(type
) ; 
 696             value
.Printf( wxT("%s(%s)"), cti
->GetTypeName().c_str(),param
.GetAsString().c_str() ); 
 700             wxLogError ( _("Internal error, illegal wxCustomTypeInfo") ) ; 
 703     else if ( type
->GetKind() == wxT_STRING 
) 
 705         value
.Printf( wxT("\"%s\""),param
.GetAsString().c_str() ); 
 709         value
.Printf( wxT("%s"), param
.GetAsString().c_str() ); 
 714 void wxCodeDepersister::CreateObject(int objectID
, 
 715                                      const wxClassInfo 
*WXUNUSED(classInfo
), 
 719                                      const wxClassInfo 
**WXUNUSED(objectClassInfos
) , 
 720                                      wxxVariantArray 
&WXUNUSED(metadata
) 
 724     m_fp
->WriteString( wxString::Format( wxT("\t%s->Create("), m_data
->GetObjectName(objectID
).c_str() ) ); 
 725     for (i 
= 0; i 
< paramCount
; i
++) 
 727         if ( objectIDValues
[i
] != wxInvalidObjectID 
) 
 728             m_fp
->WriteString( wxString::Format( wxT("%s"), m_data
->GetObjectName( objectIDValues
[i
] ).c_str() ) ); 
 731             m_fp
->WriteString( wxString::Format( wxT("%s"), ValueAsCode(params
[i
]).c_str() ) ); 
 733         if (i 
< paramCount 
- 1) 
 734             m_fp
->WriteString( wxT(", ")); 
 736     m_fp
->WriteString( wxT(");\n") ); 
 739 void wxCodeDepersister::ConstructObject(int objectID
, 
 740                                      const wxClassInfo 
*classInfo
, 
 744                                      const wxClassInfo 
**WXUNUSED(objectClassInfos
) , 
 745                                      wxxVariantArray 
&WXUNUSED(metadata
) 
 748     wxString objectName 
= wxString::Format( wxT("LocalObject_%d") , objectID 
) ; 
 749     m_fp
->WriteString( wxString::Format( wxT("\t%s *%s = new %s("), 
 750         classInfo
->GetClassName(), 
 752         classInfo
->GetClassName()) ); 
 753     m_data
->SetObjectName( objectID 
, objectName 
) ; 
 756     for (i 
= 0; i 
< paramCount
; i
++) 
 758         if ( objectIDValues
[i
] != wxInvalidObjectID 
) 
 759             m_fp
->WriteString( wxString::Format( wxT("%s"), m_data
->GetObjectName( objectIDValues
[i
] ).c_str() ) ); 
 762             m_fp
->WriteString( wxString::Format( wxT("%s"), ValueAsCode(params
[i
]).c_str() ) ); 
 764         if (i 
< paramCount 
- 1) 
 765             m_fp
->WriteString( wxT(", ") ); 
 767     m_fp
->WriteString( wxT(");\n") ); 
 770 void wxCodeDepersister::SetProperty(int objectID
, 
 771                                     const wxClassInfo 
*WXUNUSED(classInfo
), 
 772                                     const wxPropertyInfo
* propertyInfo
, 
 773                                     const wxxVariant 
&value
) 
 775     m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"), 
 776         m_data
->GetObjectName(objectID
).c_str(), 
 777         propertyInfo
->GetAccessor()->GetSetterName().c_str(), 
 778         ValueAsCode(value
).c_str()) ); 
 781 void wxCodeDepersister::SetPropertyAsObject(int objectID
, 
 782                                             const wxClassInfo 
*WXUNUSED(classInfo
), 
 783                                             const wxPropertyInfo
* propertyInfo
, 
 786     if ( propertyInfo
->GetTypeInfo()->GetKind() == wxT_OBJECT 
) 
 787         m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(*%s);\n"), 
 788         m_data
->GetObjectName(objectID
).c_str(), 
 789         propertyInfo
->GetAccessor()->GetSetterName().c_str(), 
 790         m_data
->GetObjectName( valueObjectId
).c_str() ) ); 
 792         m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"), 
 793         m_data
->GetObjectName(objectID
).c_str(), 
 794         propertyInfo
->GetAccessor()->GetSetterName().c_str(), 
 795         m_data
->GetObjectName( valueObjectId
).c_str() ) ); 
 798 void wxCodeDepersister::AddToPropertyCollection( int objectID 
, 
 799                                                 const wxClassInfo 
*WXUNUSED(classInfo
), 
 800                                                 const wxPropertyInfo
* propertyInfo 
, 
 801                                                 const wxxVariant 
&value
) 
 803     m_fp
->WriteString( wxString::Format( wxT("\t%s->%s(%s);\n"), 
 804         m_data
->GetObjectName(objectID
).c_str(), 
 805         propertyInfo
->GetAccessor()->GetAdderName().c_str(), 
 806         ValueAsCode(value
).c_str()) ); 
 809 // sets the corresponding property (value is an object) 
 810 void wxCodeDepersister::AddToPropertyCollectionAsObject(int WXUNUSED(objectID
), 
 811                                                         const wxClassInfo 
*WXUNUSED(classInfo
), 
 812                                                         const wxPropertyInfo
* WXUNUSED(propertyInfo
) , 
 813                                                         int WXUNUSED(valueObjectId
)) 
 818 void wxCodeDepersister::SetConnect(int eventSourceObjectID
, 
 819                                    const wxClassInfo 
*WXUNUSED(eventSourceClassInfo
), 
 820                                    const wxPropertyInfo 
*delegateInfo 
, 
 821                                    const wxClassInfo 
*eventSinkClassInfo 
, 
 822                                    const wxHandlerInfo
* handlerInfo 
, 
 823                                    int eventSinkObjectID 
) 
 825     wxString ehsource 
= m_data
->GetObjectName( eventSourceObjectID 
) ; 
 826     wxString ehsink 
= m_data
->GetObjectName(eventSinkObjectID
) ; 
 827     wxString ehsinkClass 
= eventSinkClassInfo
->GetClassName() ; 
 828     const wxDelegateTypeInfo 
*delegateTypeInfo 
= dynamic_cast<const wxDelegateTypeInfo
*>(delegateInfo
->GetTypeInfo()); 
 829     if ( delegateTypeInfo 
) 
 831         int eventType 
= delegateTypeInfo
->GetEventType() ; 
 832         wxString handlerName 
= handlerInfo
->GetName() ; 
 834         m_fp
->WriteString( wxString::Format(  wxT("\t%s->Connect( %s->GetId() , %d , (wxObjectEventFunction)(wxEventFunction) & %s::%s , NULL , %s ) ;") , 
 835             ehsource
.c_str() , ehsource
.c_str() , eventType 
, ehsinkClass
.c_str() , handlerName
.c_str() , ehsink
.c_str() ) ); 
 839         wxLogError(_("delegate has no type info")); 
 843 #include "wx/arrimpl.cpp" 
 845 WX_DEFINE_OBJARRAY(wxxVariantArray
);