struct wxWriter::wxWriterInternalPropertiesData
{
- map< string , int > m_writtenProperties ;
+ char nothing ;
} ;
void wxWriter::ClearObjectContext()
m_data->m_nextId = 0 ;
}
-void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , const wxString &name )
+void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , const wxString &name , wxxVariantArray &metadata )
{
DoBeginWriteTopLevelEntry( name ) ;
- WriteObject( object , classInfo , persister , false ) ;
+ WriteObject( object , classInfo , persister , false , metadata) ;
DoEndWriteTopLevelEntry( name ) ;
}
-void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , bool isEmbedded)
+void wxWriter::WriteObject(const wxObject *object, const wxClassInfo *classInfo , wxPersister *persister , bool isEmbedded, wxxVariantArray &metadata )
{
// hack to avoid writing out embedded windows, these are windows that are constructed as part of other windows, they would
// doubly constructed afterwards
if ( win && win->GetId() < 0 )
return ;
- if ( persister->BeforeWriteObject( this , object , classInfo ) )
+ if ( persister->BeforeWriteObject( this , object , classInfo , metadata) )
{
if ( object == NULL )
DoWriteNullObject() ;
if ( !isEmbedded && dynobj )
m_data->m_writtenObjects[dynobj->GetSuperClassInstance()] = oid ;
- DoBeginWriteObject( object , classInfo , oid ) ;
+ DoBeginWriteObject( object , classInfo , oid , metadata ) ;
wxWriterInternalPropertiesData data ;
WriteAllProperties( object , classInfo , persister , &data ) ;
DoEndWriteObject( object , classInfo , oid ) ;
}
void wxWriter::WriteAllProperties( const wxObject * obj , const wxClassInfo* ci , wxPersister *persister, wxWriterInternalPropertiesData * data )
{
- // in case this object is wxDynamic object we have to hand over the streaming
- // of the properties of the superclasses to the real super class instance
+ wxPropertyInfoMap map ;
+ ci->GetProperties( map ) ;
+ for ( int i = 0 ; i < ci->GetCreateParamCount() ; ++i )
{
- const wxObject *iterobj = obj ;
- const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject* > (iterobj ) ;
- if ( dynobj )
- iterobj = dynobj->GetSuperClassInstance() ;
- const wxClassInfo** parents = ci->GetParents() ;
- for ( int i = 0 ; parents[i] ; ++ i )
+ wxString name = ci->GetCreateParamName(i) ;
+ const wxPropertyInfo* prop = map.find(name)->second ;
+ wxASSERT_MSG( prop , wxT("Create Parameter not found in declared RTTI Parameters") ) ;
+ WriteOneProperty( obj , prop->GetDeclaringClass() , prop , persister , data ) ;
+ map.erase( name ) ;
+ }
+
+ for( wxPropertyInfoMap::iterator iter = map.begin() ; iter != map.end() ; ++iter )
+ {
+ const wxPropertyInfo* prop = iter->second ;
+ if ( prop->GetFlags() & wxPROP_OBJECT_GRAPH )
+ {
+ WriteOneProperty( obj , prop->GetDeclaringClass() , prop , persister , data ) ;
+ }
+ }
+
+ for( wxPropertyInfoMap::iterator iter = map.begin() ; iter != map.end() ; ++iter )
+ {
+ const wxPropertyInfo* prop = iter->second ;
+ if ( !(prop->GetFlags() & wxPROP_OBJECT_GRAPH) )
{
- WriteAllProperties( iterobj , parents[i] , persister , data ) ;
+ WriteOneProperty( obj , prop->GetDeclaringClass() , prop , persister , data ) ;
}
}
+}
+
+void wxWriter::WriteOneProperty( const wxObject *obj , const wxClassInfo* ci , const wxPropertyInfo* pi , wxPersister *persister , wxWriterInternalPropertiesData *data )
+{
+ // make sure that we are picking the correct object for accessing the property
+ const wxDynamicObject* dynobj = dynamic_cast< const wxDynamicObject* > (obj ) ;
+ if ( dynobj && (dynamic_cast<const wxDynamicClassInfo*>(ci) == NULL) )
+ obj = dynobj->GetSuperClassInstance() ;
- const wxPropertyInfo *pi = ci->GetFirstProperty() ;
- while( pi )
+ DoBeginWriteProperty( pi ) ;
+ if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION )
{
- // this property was not written yet in this object and we don't get a veto
- // if ( data->m_writtenProperties.find( pi->GetName() ) == data->m_writtenProperties.end() )
- // we will have to handle property overrides differently
+ wxxVariantArray data ;
+ pi->GetAccessor()->GetPropertyCollection(obj, data) ;
+ const wxTypeInfo * elementType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() )->GetElementType() ;
+ for ( size_t i = 0 ; i < data.GetCount() ; ++i )
{
- data->m_writtenProperties[ pi->GetName() ] = 1 ;
- DoBeginWriteProperty( pi ) ;
- if ( pi->GetTypeInfo()->GetKind() == wxT_COLLECTION )
+ DoBeginWriteElement() ;
+ wxxVariant value = data[i] ;
+ if ( persister->BeforeWriteProperty( this , pi , value ) )
{
- wxxVariantArray data ;
- pi->GetAccessor()->GetPropertyCollection(obj, data) ;
- const wxTypeInfo * elementType = dynamic_cast< const wxCollectionTypeInfo* >( pi->GetTypeInfo() )->GetElementType() ;
- for ( size_t i = 0 ; i < data.GetCount() ; ++i )
+ const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( elementType ) ;
+ if ( cti )
{
- DoBeginWriteElement() ;
- wxxVariant value = data[i] ;
- if ( persister->BeforeWriteProperty( this , pi , value ) )
- {
- const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( elementType ) ;
- if ( cti )
- {
- const wxClassInfo* pci = cti->GetClassInfo() ;
- wxObject *vobj = pci->VariantToInstance( value ) ;
- WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT ) ;
- }
- else
- {
- DoWriteSimpleType( value ) ;
- }
- }
- DoEndWriteElement() ;
+ const wxClassInfo* pci = cti->GetClassInfo() ;
+ wxObject *vobj = pci->VariantToInstance( value ) ;
+ wxxVariantArray md ;
+ WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT , md ) ;
}
- }
- else
- {
- const wxDelegateTypeInfo* dti = dynamic_cast< const wxDelegateTypeInfo* > ( pi->GetTypeInfo() ) ;
- if ( dti )
+ else
{
- const wxObject* sink = NULL ;
- const wxHandlerInfo *handler = NULL ;
+ DoWriteSimpleType( value ) ;
+ }
+ }
+ DoEndWriteElement() ;
+ }
+ }
+ else
+ {
+ const wxDelegateTypeInfo* dti = dynamic_cast< const wxDelegateTypeInfo* > ( pi->GetTypeInfo() ) ;
+ if ( dti )
+ {
+ const wxObject* sink = NULL ;
+ const wxHandlerInfo *handler = NULL ;
- const wxWindow * evSource = dynamic_cast<const wxWindow *>(obj) ;
- wxASSERT_MSG( evSource , wxT("Illegal Object Class (Non-Window) as Event Source") ) ;
+ const wxWindow * evSource = dynamic_cast<const wxWindow *>(obj) ;
+ wxASSERT_MSG( evSource , wxT("Illegal Object Class (Non-Window) as Event Source") ) ;
- FindConnectEntry( evSource , dti , sink , handler ) ;
- if ( persister->BeforeWriteDelegate( this , obj , ci , pi , sink , handler ) )
- {
- if ( sink != NULL && handler != NULL )
- {
- wxASSERT_MSG( IsObjectKnown( sink ) , wxT("Streaming delegates for not already streamed objects not yet supported") ) ;
- DoWriteDelegate( obj , ci , pi , sink , GetObjectID( sink ) , sink->GetClassInfo() , handler ) ;
- }
- }
+ FindConnectEntry( evSource , dti , sink , handler ) ;
+ if ( persister->BeforeWriteDelegate( this , obj , ci , pi , sink , handler ) )
+ {
+ if ( sink != NULL && handler != NULL )
+ {
+ wxASSERT_MSG( IsObjectKnown( sink ) , wxT("Streaming delegates for not already streamed objects not yet supported") ) ;
+ DoWriteDelegate( obj , ci , pi , sink , GetObjectID( sink ) , sink->GetClassInfo() , handler ) ;
}
- else
+ }
+ }
+ else
+ {
+ wxxVariant value ;
+ pi->GetAccessor()->GetProperty(obj, value) ;
+ if ( persister->BeforeWriteProperty( this , pi , value ) )
+ {
+ const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( pi->GetTypeInfo() ) ;
+ if ( cti )
{
- wxxVariant value ;
- pi->GetAccessor()->GetProperty(obj, value) ;
- if ( persister->BeforeWriteProperty( this , pi , value ) )
+ const wxClassInfo* pci = cti->GetClassInfo() ;
+ wxObject *vobj = pci->VariantToInstance( value ) ;
+ wxxVariantArray md ;
+ WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT , md) ;
+ }
+ else
+ {
+ if ( pi->GetFlags() & wxPROP_ENUM_STORE_LONG )
{
- const wxClassTypeInfo* cti = dynamic_cast< const wxClassTypeInfo* > ( pi->GetTypeInfo() ) ;
- if ( cti )
- {
- const wxClassInfo* pci = cti->GetClassInfo() ;
- wxObject *vobj = pci->VariantToInstance( value ) ;
- WriteObject( vobj , (vobj ? vobj->GetClassInfo() : pci ) , persister , cti->GetKind()== wxT_OBJECT ) ;
- }
- else
- {
- DoWriteSimpleType( value ) ;
- }
+ const wxEnumTypeInfo *eti = dynamic_cast<const wxEnumTypeInfo*>( pi->GetTypeInfo() ) ;
+ wxASSERT_MSG( eti , wxT("Type must have enum - long conversion") ) ;
+ eti->ConvertFromLong( value.Get<long>() , value ) ;
}
+ DoWriteSimpleType( value ) ;
}
}
- DoEndWriteProperty( pi ) ;
}
- pi = pi->GetNext() ;
}
- }
+ DoEndWriteProperty( pi ) ;
+}
int wxWriter::GetObjectID(const wxObject *obj)
{
m_data->Pop() ;
}
-void wxXmlWriter::DoBeginWriteObject(const wxObject *WXUNUSED(object), const wxClassInfo *classInfo, int objectID )
+void wxXmlWriter::DoBeginWriteObject(const wxObject *WXUNUSED(object), const wxClassInfo *classInfo, int objectID , wxxVariantArray &metadata )
{
wxXmlNode *pnode;
pnode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("object"));
pnode->AddProperty(wxT("class"), wxString(classInfo->GetClassName()));
pnode->AddProperty(wxT("id"), wxString::Format( "%d" , objectID ) );
+ for ( size_t i = 0 ; i < metadata.GetCount() ; ++i )
+ {
+ pnode->AddProperty( metadata[i].GetName() , metadata[i].GetAsString() ) ;
+ }
m_data->m_current->AddChild(pnode) ;
m_data->Push( pnode ) ;
}
// first make the object know to our internal registry
SetObjectClassInfo( objectID , classInfo ) ;
- callbacks->AllocateObject(objectID, classInfo);
+ wxxVariantArray metadata ;
+ wxXmlProperty *xp = node->GetProperties() ;
+ while ( xp )
+ {
+ if ( xp->GetName() != wxString("class") && xp->GetName() != wxString("id") )
+ {
+ metadata.Add( new wxxVariant( xp->GetValue() , xp->GetName() ) ) ;
+ }
+ xp = xp->GetNext() ;
+ }
+ callbacks->AllocateObject(objectID, classInfo, metadata);
//
// stream back the Create parameters first
{
createParamOids[i] = wxInvalidObjectID ;
createParams[i] = ReadValue( prop , pi->GetTypeInfo() ) ;
+ if( pi->GetFlags() & wxPROP_ENUM_STORE_LONG )
+ {
+ const wxEnumTypeInfo *eti = dynamic_cast<const wxEnumTypeInfo*>( pi->GetTypeInfo() ) ;
+ wxASSERT_MSG( eti , wxT("Type must have enum - long conversion") ) ;
+
+ long realval ;
+ eti->ConvertToLong( createParams[i] , realval ) ;
+ createParams[i] = wxxVariant( realval ) ;
+ }
createClassInfos[i] = NULL ;
}
// got the parameters. Call the Create method
callbacks->CreateObject(objectID, classInfo,
classInfo->GetCreateParamCount(),
- createParams, createParamOids, createClassInfos);
+ createParams, createParamOids, createClassInfos, metadata );
// now stream in the rest of the properties, in the sequence their properties were written in the xml
for ( size_t j = 0 ; j < propertyNames.size() ; ++j )
wxClassInfo* sinkClassInfo = GetObjectClassInfo( sinkOid ) ;
callbacks->SetConnect( objectID , classInfo , dynamic_cast<const wxDelegateTypeInfo*>(pi->GetTypeInfo()) , sinkClassInfo ,
- sinkClassInfo->FindHandlerInfo(handlerName) , sinkOid ) ;
+ sinkClassInfo->FindHandlerInfo(handlerName) , sinkOid ) ;
}
}
delete m_data ;
}
-void wxRuntimeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo)
+void wxRuntimeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo ,
+ wxxVariantArray &metadata)
{
wxObject *O;
O = classInfo->CreateObject();
int paramCount,
wxxVariant *params,
int *objectIdValues,
- const wxClassInfo **objectClassInfos)
+ const wxClassInfo **objectClassInfos ,
+ wxxVariantArray &metadata)
{
wxObject *o;
o = m_data->GetObject(objectID);
// adds an element to a property collection
void wxRuntimeDepersister::AddToPropertyCollection( int objectID ,
- const wxClassInfo *classInfo,
- const wxPropertyInfo* propertyInfo ,
- const wxxVariant &value)
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ const wxxVariant &value)
{
wxObject *o;
o = m_data->GetObject(objectID);
// sets the corresponding property (value is an object)
void wxRuntimeDepersister::AddToPropertyCollectionAsObject(int objectID,
- const wxClassInfo *classInfo,
- const wxPropertyInfo* propertyInfo ,
- int valueObjectId)
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ int valueObjectId)
{
wxObject *o, *valo;
o = m_data->GetObject(objectID);
delete m_data ;
}
-void wxCodeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo)
+void wxCodeDepersister::AllocateObject(int objectID, wxClassInfo *classInfo ,
+ wxxVariantArray &metadata)
{
wxString objectName = wxString::Format( "LocalObject_%d" , objectID ) ;
m_fp->WriteString( wxString::Format( "\t%s *%s = new %s;\n",
int paramCount,
wxxVariant *params,
int *objectIDValues,
- const wxClassInfo **WXUNUSED(objectClassInfos)
+ const wxClassInfo **WXUNUSED(objectClassInfos) ,
+ wxxVariantArray &metadata
)
{
int i;
}
void wxCodeDepersister::AddToPropertyCollection( int objectID ,
- const wxClassInfo *classInfo,
- const wxPropertyInfo* propertyInfo ,
- const wxxVariant &value)
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ const wxxVariant &value)
{
m_fp->WriteString( wxString::Format( "\t%s->%s(%s);\n",
m_data->GetObjectName(objectID),
// sets the corresponding property (value is an object)
void wxCodeDepersister::AddToPropertyCollectionAsObject(int objectID,
- const wxClassInfo *classInfo,
- const wxPropertyInfo* propertyInfo ,
- int valueObjectId)
+ const wxClassInfo *classInfo,
+ const wxPropertyInfo* propertyInfo ,
+ int valueObjectId)
{
// TODO
}