void SimpleSortedSetData< KeyT, CompareKeyT, AllocatorT >::Serialize( ArchiveT& archive ) { DynArray< ObjectPtr > components; components.Reserve( m_Data->GetSize() ); { DataType::ConstIterator itr = m_Data->Begin(); DataType::ConstIterator end = m_Data->End(); for ( ; itr != end; ++itr ) { ObjectPtr dataElem = Registry::GetInstance()->CreateInstance( Reflect::GetDataClass< KeyT >() ); // downcast to data type Data* dataSer = AssertCast< Data >( dataElem ); // connect to our map data memory address dataSer->ConnectData( const_cast< KeyT* >( &( *itr ) ) ); // serialize to the archive stream HELIUM_VERIFY( components.New( dataSer ) ); } } archive.SerializeArray( components ); DynArray< ObjectPtr >::Iterator itr = components.Begin(); DynArray< ObjectPtr >::Iterator end = components.End(); for ( ; itr != end; ++itr ) { Data* ser = AssertCast< Data >( *itr ); ser->Disconnect(); // might be useful to cache the data object here } }
void SimpleObjectSortedMapData< KeyT, CompareKeyT, AllocatorT >::Serialize( ArchiveT& archive ) { DynArray< ObjectPtr > components; components.Reserve( m_Data->GetSize() * 2 ); { DataType::ConstIterator itr = m_Data->Begin(); DataType::ConstIterator end = m_Data->End(); for ( ; itr != end; ++itr ) { ObjectPtr elem = Registry::GetInstance()->CreateInstance( Reflect::GetDataClass< KeyT >() ); Data* ser = AssertCast< Data >( elem.Ptr() ); ser->ConnectData( const_cast< KeyT* >( &itr->First() ) ); HELIUM_VERIFY( components.New( ser ) ); HELIUM_VERIFY( components.New( itr->Second() ) ); } } archive.SerializeArray( components ); { DynArray< ObjectPtr >::Iterator itr = components.Begin(); DynArray< ObjectPtr >::Iterator end = components.End(); for ( ; itr != end; ++itr ) { Data* ser = AssertCast< Data >( *itr ); ser->Disconnect(); ++itr; // Skip over the object reference. // might be useful to cache the data object here } } }
void SimpleSortedSetData< KeyT, CompareKeyT, AllocatorT >::GetItems( DynArray< DataPtr >& items ) const { items.Clear(); items.Reserve( m_Data->GetSize() ); DataType::ConstIterator itr = m_Data->Begin(); DataType::ConstIterator end = m_Data->End(); for ( ; itr != end; ++itr ) { HELIUM_VERIFY( items.New( Data::Bind( const_cast< KeyT& >( *itr ), m_Instance, m_Field ) ) ); } }