Esempio n. 1
0
IndexedIOPtr Object::SaveContext::container( const std::string &typeName, unsigned int ioVersion )
{
	IndexedIOPtr typeIO = m_ioInterface->subdirectory( typeName, IndexedIO::CreateIfMissing );
	typeIO->write( g_ioVersionEntry, ioVersion );
	IndexedIOPtr dataIO = typeIO->subdirectory( g_dataEntry, IndexedIO::CreateIfMissing );
	dataIO->removeAll();
	return dataIO;
}
Esempio n. 2
0
void Object::SaveContext::save( const Object *toSave, IndexedIO *container, const IndexedIO::EntryID &name )
{
	if ( !toSave )
	{
		throw Exception( "Error trying to save NULL pointer object!" );
	}

	SavedObjectMap::const_iterator it = m_savedObjects->find( toSave );
	if( it!=m_savedObjects->end() )
	{
		container->write( name, &(it->second[0]), it->second.size() );
	}
	else
	{
		bool rootObject = ( m_savedObjects->size() == 0 );
		if ( rootObject )
		{
			if ( container->hasEntry( name ) )
			{
				container->remove( name );
			}
		}
		IndexedIOPtr nameIO = container->createSubdirectory( name );

		IndexedIO::EntryIDList pathParts;
		nameIO->path( pathParts );
		(*m_savedObjects)[toSave] = pathParts;

		nameIO->write( g_typeEntry, toSave->typeName() );

		IndexedIOPtr dataIO = nameIO->createSubdirectory( g_dataEntry );
		dataIO->removeAll();

		SaveContext context( dataIO, m_savedObjects );
		toSave->save( &context );

		// Objects saved on a file can be committed to disk to free memory.
		if ( rootObject )
		{
			nameIO->commit();
		}
	}
}