| 177 | } |
| 178 | |
| 179 | void Object::SaveContext::save( const Object *toSave, IndexedIO *container, const IndexedIO::EntryID &name ) |
| 180 | { |
| 181 | if ( !toSave ) |
| 182 | { |
| 183 | throw Exception( "Error trying to save NULL pointer object!" ); |
| 184 | } |
| 185 | |
| 186 | SavedObjects::const_iterator it = m_savedObjects->find( toSave ); |
| 187 | if( it!=m_savedObjects->end() ) |
| 188 | { |
| 189 | container->write( name, &(it->second[0]), it->second.size() ); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | bool rootObject = ( m_savedObjects->size() == 0 ); |
| 194 | if ( rootObject ) |
| 195 | { |
| 196 | if ( container->hasEntry( name ) ) |
| 197 | { |
| 198 | container->remove( name ); |
| 199 | } |
| 200 | } |
| 201 | IndexedIOPtr nameIO = container->createSubdirectory( name ); |
| 202 | |
| 203 | IndexedIO::EntryIDList pathParts; |
| 204 | nameIO->path( pathParts ); |
| 205 | (*m_savedObjects)[toSave] = pathParts; |
| 206 | |
| 207 | nameIO->write( g_typeEntry, toSave->typeName() ); |
| 208 | |
| 209 | IndexedIOPtr dataIO = nameIO->createSubdirectory( g_dataEntry ); |
| 210 | dataIO->removeAll(); |
| 211 | |
| 212 | SaveContext context( dataIO, m_savedObjects ); |
| 213 | toSave->save( &context ); |
| 214 | |
| 215 | // Objects saved on a file can be committed to disk to free memory. |
| 216 | if ( rootObject ) |
| 217 | { |
| 218 | nameIO->commit(); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | ////////////////////////////////////////////////////////////////////////////////////////// |
| 224 | // load context stuff |
nothing calls this directly
no test coverage detected