This approach is really good. It is much easier to debug and if you have to
use serialization this is the way to go in my opinion. Thanks G.
"Giovanni Dicanio" <giovanni.dicanio@invalid.com> ha scritto nel messaggio
news:%23qhkpp1gIHA.4164@TK2MSFTNGP05.phx.gbl...
So, I think you should write a customized version (template
specialization) of SerializeElements for your particular class
CPlanetAspect,
Another approach could be to not call CArchive.Serialize. Instead, you
could do the serialization yourself, implementing a custom serialization
something like this (not tested):
void SaveToArchive( const CArray<CPlanetData> & data, CArchive & ar )
{
ASSERT( ar.IsStoring() );
// Write number of planets
int count = data.GetCount();
ar << count;
// Write each planet data to archive
for ( int i = 0; i < count; i++ )
{
data.GetAt( i ).Serialize( ar );
}
}
Similar for loading (first you read the data count, then set array size,
and load each planet data into it):
void LoadFromArchive( CArray< CPlanetData > & data, CArchive & ar )
{
ASSERT( ar.IsLoading() );
// Read number of planets
int count;
ar >> count;
// Make room in output array
data.SetSize( count );
// Read each planet data from archive
for ( int i = 0; i < count; i++ )
{
data.GetAt(i).Serialize( ar );
}
}
Giovanni