////////////////////////////////////////////////////////////////////////// WriteObect, ReadObject //////////////////////////////////////////////////////////////////////////
| 334 | // WriteObect, ReadObject |
| 335 | /////////////////////////////////////////////////////////////////////////////// |
| 336 | void cSerializerImpl::WriteObject(const iTypedSerializable* pObj) |
| 337 | { |
| 338 | ASSERT(pObj != 0); |
| 339 | //ASSERT(mbInit); // this isn't needed if we are not writing the type array |
| 340 | ASSERT(IsWriting()); |
| 341 | cDebug d("cSerializerImpl::WriteObject"); |
| 342 | //d.TraceDetail("Entering... Archive Offset = %d\n", mpArchive->CurrentPos()); |
| 343 | d.TraceDetail(" Object Type = %s\n", pObj->GetType().AsString()); |
| 344 | // first, we write out the header, which consists of the following: |
| 345 | // int32 refrence into mTypeArray, indicating the object's type |
| 346 | // int32 version of stored data |
| 347 | // int32 size of the chunk (counting from this point; not including the previous int32 |
| 348 | // data the object data |
| 349 | ASSERT(mpArchive != 0); |
| 350 | |
| 351 | |
| 352 | // 5Nov 98 mdb -- I am removing the read and write of type info for this method; it is never used, since |
| 353 | // the object is already created when ReadObject() happens. The only good it might serve is in asserting that |
| 354 | // the input stream is valid, but I can do that with the 0xffffffff size below (asserting that it is the same |
| 355 | // when it is read back in) |
| 356 | /* int i = 0; |
| 357 | for(; i < mTypeArray.size(); i++) |
| 358 | { |
| 359 | if(pObj->GetType() == *mTypeArray[i]) |
| 360 | { |
| 361 | // aha! this is it! |
| 362 | break; |
| 363 | } |
| 364 | } |
| 365 | if(i == mTypeArray.size()) |
| 366 | { |
| 367 | // the type was not registered; |
| 368 | // a debate exists in my mind as to whether this should be an exception or an assertion -- mdb |
| 369 | d.TraceError("Attempt to serialize unregistered type : %s\n", pObj->GetType().AsString()); |
| 370 | ThrowAndAssert(eSerializerUnknownType(pObj->GetType().AsString())); |
| 371 | } |
| 372 | mpArchive->WriteInt32(i); |
| 373 | */ |
| 374 | |
| 375 | mpArchive->WriteInt32(0); // place holder for type array index |
| 376 | mpArchive->WriteInt32(pObj->Version()); |
| 377 | // write a placeholder for the size; we will come back and fill in the right value later... |
| 378 | //int64 sizePos = mpArchive->CurrentPos(); |
| 379 | mpArchive->WriteInt32(0xffffffff); |
| 380 | |
| 381 | // write out the object! |
| 382 | pObj->Write(this); |
| 383 | |
| 384 | // finally, we need to go back and patch up the size... |
| 385 | //int64 returnPos = mpArchive->CurrentPos(); |
| 386 | //mpArchive->Seek(sizePos, cBidirArchive::BEGINNING); |
| 387 | //mpArchive->WriteInt32((int32)(returnPos - sizePos - sizeof(int32))); |
| 388 | //mpArchive->Seek(returnPos, cBidirArchive::BEGINNING); |
| 389 | } |
| 390 | |
| 391 | void cSerializerImpl::ReadObject(iTypedSerializable* pObj) |
| 392 | { |