| 40 | } |
| 41 | |
| 42 | void SimObjectMemento::save( SimObject *object ) |
| 43 | { |
| 44 | // Cleanup any existing state data. |
| 45 | dFree( mState ); |
| 46 | mObjectName = String::EmptyString; |
| 47 | |
| 48 | // Use a stream to save the state. |
| 49 | MemStream stream( 256 ); |
| 50 | |
| 51 | U32 writeFlags = 0; |
| 52 | SimDataBlock* db = dynamic_cast<SimDataBlock*>(object); |
| 53 | if( !db ) |
| 54 | stream.write( sizeof( "return " ) - 1, "return " ); |
| 55 | else |
| 56 | { |
| 57 | mIsDatablock = true; |
| 58 | |
| 59 | // Cull the datablock name from the output so that |
| 60 | // we can easily replace it in case the datablock's name |
| 61 | // is already taken when we call restore(). We can't use the same |
| 62 | // setup as with non-datablock classes as the return semantics |
| 63 | // are not the same. |
| 64 | |
| 65 | writeFlags |= SimObject::NoName; |
| 66 | } |
| 67 | |
| 68 | object->write( stream, 0, writeFlags ); |
| 69 | stream.write( (UTF8)0 ); |
| 70 | |
| 71 | // Steal the data away from the stream. |
| 72 | mState = (UTF8*)stream.takeBuffer(); |
| 73 | mObjectName = object->getName(); |
| 74 | } |
| 75 | |
| 76 | SimObject *SimObjectMemento::restore() const |
| 77 | { |
nothing calls this directly
no test coverage detected