X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/19d85aac23ef5f4f042bc64bac481ad698ebe5f7..bf2c43c76e2819be443ab1d830ab68d9569d66b1:/src/common/xtistrm.cpp?ds=inline diff --git a/src/common/xtistrm.cpp b/src/common/xtistrm.cpp index 0691af6242..d96db65eb3 100644 --- a/src/common/xtistrm.cpp +++ b/src/common/xtistrm.cpp @@ -4,7 +4,6 @@ // Author: Stefan Csomor // Modified by: // Created: 27/07/03 -// RCS-ID: $Id$ // Copyright: (c) 2003 Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -73,22 +72,22 @@ void wxObjectWriter::ClearObjectContext() } void wxObjectWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo, - wxObjectReaderCallback *persister, const wxString &name, - wxVariantBaseArray &metadata ) + wxObjectWriterCallback *writercallback, const wxString &name, + const wxStringToAnyHashMap &metadata ) { DoBeginWriteTopLevelEntry( name ); - WriteObject( object, classInfo, persister, false, metadata); + WriteObject( object, classInfo, writercallback, false, metadata); DoEndWriteTopLevelEntry( name ); } void wxObjectWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo, - wxObjectReaderCallback *persister, bool isEmbedded, - wxVariantBaseArray &metadata ) + wxObjectWriterCallback *writercallback, bool isEmbedded, + const wxStringToAnyHashMap &metadata ) { - if ( !classInfo->BeforeWriteObject( object, this, persister, metadata) ) + if ( !classInfo->BeforeWriteObject( object, this, writercallback, metadata) ) return; - if ( persister->BeforeWriteObject( this, object, classInfo, metadata) ) + if ( writercallback->BeforeWriteObject( this, object, classInfo, metadata) ) { if ( object == NULL ) DoWriteNullObject(); @@ -108,10 +107,10 @@ void wxObjectWriter::WriteObject(const wxObject *object, const wxClassInfo *clas DoBeginWriteObject( object, classInfo, oid, metadata ); wxObjectWriterInternalPropertiesData data; - WriteAllProperties( object, classInfo, persister, &data ); + WriteAllProperties( object, classInfo, writercallback, &data ); DoEndWriteObject( object, classInfo, oid ); } - persister->AfterWriteObject( this,object, classInfo ); + writercallback->AfterWriteObject( this,object, classInfo ); } } @@ -124,23 +123,22 @@ void wxObjectWriter::FindConnectEntry(const wxEvtHandler * evSource, if ( dynamicEvents ) { - wxList::compatibility_iterator node = dynamicEvents->GetFirst(); - while (node) + for ( wxList::const_iterator node = dynamicEvents->begin(); node != dynamicEvents->end(); ++node ) { - wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)node->GetData(); + wxDynamicEventTableEntry *entry = (wxDynamicEventTableEntry*)(*node); // find the match if ( entry->m_fn && (dti->GetEventType() == entry->m_eventType) && (entry->m_id == -1 ) && - (entry->m_eventSink != NULL ) ) + (entry->m_fn->GetEvtHandler() != NULL ) ) { - sink = entry->m_eventSink; + sink = entry->m_fn->GetEvtHandler(); const wxClassInfo* sinkClassInfo = sink->GetClassInfo(); const wxHandlerInfo* sinkHandler = sinkClassInfo->GetFirstHandler(); while ( sinkHandler ) { - if ( sinkHandler->GetEventFunction() == entry->m_fn ) + if ( sinkHandler->GetEventFunction() == entry->m_fn->GetEvtMethod() ) { handler = sinkHandler; break; @@ -149,12 +147,11 @@ void wxObjectWriter::FindConnectEntry(const wxEvtHandler * evSource, } break; } - node = node->GetNext(); } } } void wxObjectWriter::WriteAllProperties( const wxObject * obj, const wxClassInfo* ci, - wxObjectReaderCallback *persister, + wxObjectWriterCallback *writercallback, wxObjectWriterInternalPropertiesData * data ) { wxPropertyInfoMap map; @@ -166,7 +163,7 @@ void wxObjectWriter::WriteAllProperties( const wxObject * obj, const wxClassInfo const wxPropertyInfo* prop = iter == map.end() ? NULL : iter->second; if ( prop ) { - WriteOneProperty( obj, prop->GetDeclaringClass(), prop, persister, data ); + WriteOneProperty( obj, prop->GetDeclaringClass(), prop, writercallback, data ); } else { @@ -180,7 +177,7 @@ void wxObjectWriter::WriteAllProperties( const wxObject * obj, const wxClassInfo const wxPropertyInfo* prop = iter->second; if ( prop->GetFlags() & wxPROP_OBJECT_GRAPH ) { - WriteOneProperty( obj, prop->GetDeclaringClass(), prop, persister, data ); + WriteOneProperty( obj, prop->GetDeclaringClass(), prop, writercallback, data ); } } } @@ -190,14 +187,36 @@ void wxObjectWriter::WriteAllProperties( const wxObject * obj, const wxClassInfo const wxPropertyInfo* prop = iter->second; if ( !(prop->GetFlags() & wxPROP_OBJECT_GRAPH) ) { - WriteOneProperty( obj, prop->GetDeclaringClass(), prop, persister, data ); + WriteOneProperty( obj, prop->GetDeclaringClass(), prop, writercallback, data ); } } } } +class WXDLLIMPEXP_BASE wxObjectPropertyWriter: public wxObjectWriterFunctor +{ +public: + wxObjectPropertyWriter(const wxClassTypeInfo* cti, + wxObjectWriterCallback *writercallback, + wxObjectWriter* writer, + wxStringToAnyHashMap &props) : + m_cti(cti),m_persister(writercallback),m_writer(writer),m_props(props) + {} + + virtual void operator()(const wxObject *vobj) + { + m_writer->WriteObject( vobj, (vobj ? vobj->GetClassInfo() : m_cti->GetClassInfo() ), + m_persister, m_cti->GetKind()== wxT_OBJECT, m_props ); + } +private: + const wxClassTypeInfo* m_cti; + wxObjectWriterCallback *m_persister; + wxObjectWriter* m_writer; + wxStringToAnyHashMap& m_props; +}; + void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* ci, - const wxPropertyInfo* pi, wxObjectReaderCallback *persister, + const wxPropertyInfo* pi, wxObjectWriterCallback *writercallback, wxObjectWriterInternalPropertiesData *WXUNUSED(data) ) { if ( pi->GetFlags() & wxPROP_DONT_STREAM ) @@ -210,39 +229,39 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION ) { - wxVariantBaseArray data; + wxAnyList data; pi->GetAccessor()->GetPropertyCollection(obj, data); const wxTypeInfo * elementType = wx_dynamic_cast( const wxCollectionTypeInfo*, pi->GetTypeInfo() )->GetElementType(); - for ( size_t i = 0; i < data.GetCount(); ++i ) + if ( !data.empty() ) { - if ( i == 0 ) - DoBeginWriteProperty( pi ); - - DoBeginWriteElement(); - wxVariantBase value = data[i]; - if ( persister->BeforeWriteProperty( this, obj, pi, value ) ) + DoBeginWriteProperty( pi ); + for ( wxAnyList::const_iterator iter = data.begin(); iter != data.end(); ++iter ) { - const wxClassTypeInfo* cti = - wx_dynamic_cast( const wxClassTypeInfo*, elementType ); - if ( cti ) - { - const wxClassInfo* pci = cti->GetClassInfo(); - wxObject *vobj = pci->VariantToInstance( value ); - wxVariantBaseArray md; - WriteObject( vobj, (vobj ? vobj->GetClassInfo() : pci ), - persister, cti->GetKind()== wxT_OBJECT, md ); - } - else + DoBeginWriteElement(); + const wxAny* valptr = *iter; + if ( writercallback->BeforeWriteProperty( this, obj, pi, *valptr ) ) { - DoWriteSimpleType( value ); + const wxClassTypeInfo* cti = + wx_dynamic_cast( const wxClassTypeInfo*, elementType ); + if ( cti ) + { + wxStringToAnyHashMap md; + wxObjectPropertyWriter pw(cti,writercallback,this, md); + + const wxClassInfo* pci = cti->GetClassInfo(); + pci->CallOnAny( *valptr, &pw); + } + else + { + DoWriteSimpleType( *valptr ); + } } + DoEndWriteElement(); } - DoEndWriteElement(); - if ( i == data.GetCount() - 1 ) - DoEndWriteProperty( pi ); - } - } + DoEndWriteProperty( pi ); + } + } else { const wxEventSourceTypeInfo* dti = @@ -256,7 +275,7 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c if ( evSource ) { FindConnectEntry( evSource, dti, sink, handler ); - if ( persister->BeforeWriteDelegate( this, obj, ci, pi, sink, handler ) ) + if ( writercallback->BeforeWriteDelegate( this, obj, ci, pi, sink, handler ) ) { if ( sink != NULL && handler != NULL ) { @@ -269,8 +288,8 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c } else { - wxLogError( _T("Streaming delegates for not already ") - _T("streamed objects not yet supported") ); + wxLogError( wxT("Streaming delegates for not already ") + wxT("streamed objects not yet supported") ); } } } @@ -282,11 +301,12 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c } else { - wxVariantBase value; + wxAny value; pi->GetAccessor()->GetProperty(obj, value); // avoid streaming out void objects - if( value.IsEmpty() ) + // TODO Verify + if( value.IsNull() ) return; if ( pi->GetFlags() & wxPROP_ENUM_STORE_LONG ) @@ -295,7 +315,7 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c wx_dynamic_cast(const wxEnumTypeInfo*, pi->GetTypeInfo() ); if ( eti ) { - eti->ConvertFromLong( value.wxTEMPLATED_MEMBER_CALL(Get, long), value ); + eti->ConvertFromLong( wxANY_AS(value, long ), value ); } else { @@ -305,9 +325,9 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c // avoid streaming out default values if ( pi->GetTypeInfo()->HasStringConverters() && - !pi->GetDefaultValue().IsEmpty() ) + !pi->GetDefaultValue().IsNull() ) // TODO Verify { - if ( value.GetAsString() == pi->GetDefaultValue().GetAsString() ) + if ( wxAnyGetAsString(value) == wxAnyGetAsString(pi->GetDefaultValue()) ) return; } @@ -315,28 +335,28 @@ void wxObjectWriter::WriteOneProperty( const wxObject *obj, const wxClassInfo* c const wxClassTypeInfo* cti = wx_dynamic_cast( const wxClassTypeInfo* , pi->GetTypeInfo() ); - if ( cti && value.GetAsObject() == NULL ) + if ( cti && cti->GetKind() == wxT_OBJECT_PTR && wxAnyGetAsObjectPtr(value) == NULL ) return; - if ( persister->BeforeWriteProperty( this, obj, pi, value ) ) + if ( writercallback->BeforeWriteProperty( this, obj, pi, value ) ) { DoBeginWriteProperty( pi ); if ( cti ) { - const wxClassInfo* pci = cti->GetClassInfo(); - wxObject *vobj = pci->VariantToInstance( value ); - if ( vobj && pi->GetTypeInfo()->HasStringConverters() ) + if ( cti->HasStringConverters() ) { wxString stringValue; cti->ConvertToString( value, stringValue ); - wxVariantBase convertedValue(stringValue); + wxAny convertedValue(stringValue); DoWriteSimpleType( convertedValue ); } else { - wxVariantBaseArray md; - WriteObject( vobj, (vobj ? vobj->GetClassInfo() : pci ), - persister, cti->GetKind()== wxT_OBJECT, md); + wxStringToAnyHashMap md; + wxObjectPropertyWriter pw(cti,writercallback,this, md); + + const wxClassInfo* pci = cti->GetClassInfo(); + pci->CallOnAny(value, &pw); } } else @@ -457,7 +477,7 @@ struct wxObjectRuntimeReaderCallback::wxObjectRuntimeReaderCallbackInternal return NULL; if ( m_objects.find(objectID) == m_objects.end() ) { - wxLogError( _("Passing an unkown object to GetObject") ); + wxLogError( _("Passing an unknown object to GetObject") ); return NULL; } @@ -476,7 +496,7 @@ wxObjectRuntimeReaderCallback::~wxObjectRuntimeReaderCallback() } void wxObjectRuntimeReaderCallback::AllocateObject(int objectID, wxClassInfo *classInfo, - wxVariantBaseArray &WXUNUSED(metadata)) + wxStringToAnyHashMap &WXUNUSED(metadata)) { wxObject *O; O = classInfo->CreateObject(); @@ -486,10 +506,10 @@ void wxObjectRuntimeReaderCallback::AllocateObject(int objectID, wxClassInfo *cl void wxObjectRuntimeReaderCallback::CreateObject(int objectID, const wxClassInfo *classInfo, int paramCount, - wxVariantBase *params, + wxAny *params, int *objectIdValues, const wxClassInfo **objectClassInfos, - wxVariantBaseArray &WXUNUSED(metadata)) + wxStringToAnyHashMap &WXUNUSED(metadata)) { wxObject *o; o = m_data->GetObject(objectID); @@ -506,7 +526,7 @@ void wxObjectRuntimeReaderCallback::CreateObject(int objectID, { o = dyno->GetSuperClassInstance(); } - params[i] = objectClassInfos[i]->InstanceToVariant(o); + params[i] = objectClassInfos[i]->ObjectPtrToAny(o); } } classInfo->Create(o, paramCount, params); @@ -515,10 +535,10 @@ void wxObjectRuntimeReaderCallback::CreateObject(int objectID, void wxObjectRuntimeReaderCallback::ConstructObject(int objectID, const wxClassInfo *classInfo, int paramCount, - wxVariantBase *params, + wxAny *params, int *objectIdValues, const wxClassInfo **objectClassInfos, - wxVariantBaseArray &WXUNUSED(metadata)) + wxStringToAnyHashMap &WXUNUSED(metadata)) { wxObject *o; for ( int i = 0; i < paramCount; ++i ) @@ -534,7 +554,7 @@ void wxObjectRuntimeReaderCallback::ConstructObject(int objectID, { o = dyno->GetSuperClassInstance(); } - params[i] = objectClassInfos[i]->InstanceToVariant(o); + params[i] = objectClassInfos[i]->ObjectPtrToAny(o); } } o = classInfo->ConstructObject(paramCount, params); @@ -552,11 +572,11 @@ void wxObjectRuntimeReaderCallback::DestroyObject(int objectID, wxClassInfo *WXU void wxObjectRuntimeReaderCallback::SetProperty(int objectID, const wxClassInfo *classInfo, const wxPropertyInfo* propertyInfo, - const wxVariantBase &value) + const wxAny &value) { wxObject *o; o = m_data->GetObject(objectID); - classInfo->SetProperty( o, propertyInfo->GetName(), value ); + classInfo->SetProperty( o, propertyInfo->GetName().c_str(), value ); } void wxObjectRuntimeReaderCallback::SetPropertyAsObject(int objectID, @@ -578,8 +598,8 @@ void wxObjectRuntimeReaderCallback::SetPropertyAsObject(int objectID, valo = dynvalo->GetSuperClassInstance(); } - classInfo->SetProperty( o, propertyInfo->GetName(), - valClassInfo->InstanceToVariant(valo) ); + classInfo->SetProperty( o, propertyInfo->GetName().c_str(), + valClassInfo->ObjectPtrToAny(valo) ); } void wxObjectRuntimeReaderCallback::SetConnect(int eventSourceObjectID, @@ -625,11 +645,11 @@ wxObject *wxObjectRuntimeReaderCallback::GetObject(int objectID) void wxObjectRuntimeReaderCallback::AddToPropertyCollection( int objectID, const wxClassInfo *classInfo, const wxPropertyInfo* propertyInfo, - const wxVariantBase &value) + const wxAny &value) { wxObject *o; o = m_data->GetObject(objectID); - classInfo->AddToPropertyCollection( o, propertyInfo->GetName(), value ); + classInfo->AddToPropertyCollection( o, propertyInfo->GetName().c_str(), value ); } void wxObjectRuntimeReaderCallback::AddToPropertyCollectionAsObject(int objectID, @@ -653,13 +673,8 @@ void wxObjectRuntimeReaderCallback::AddToPropertyCollectionAsObject(int objectID valo = dynvalo->GetSuperClassInstance(); } - classInfo->AddToPropertyCollection( o, propertyInfo->GetName(), - valClassInfo->InstanceToVariant(valo) ); + classInfo->AddToPropertyCollection( o, propertyInfo->GetName().c_str(), + valClassInfo->ObjectPtrToAny(valo) ); } -#if TEST_XVARIANT -#include "wx/arrimpl.cpp" -WX_DEFINE_OBJARRAY(wxVariantBaseArray); -#endif - #endif // wxUSE_EXTENDED_RTTI