| 505 | } |
| 506 | |
| 507 | bool ClumpletWriter::upgradeVersion() |
| 508 | { |
| 509 | // Sanity check |
| 510 | if (!kindList) |
| 511 | { |
| 512 | return false; |
| 513 | } |
| 514 | |
| 515 | // Check for required version - use highmost one |
| 516 | const KindList* newest = kindList; |
| 517 | for (const KindList* itr = kindList; itr->tag != EndOfList; ++itr) |
| 518 | { |
| 519 | if (itr->tag > newest->tag) |
| 520 | { |
| 521 | newest = itr; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | if (getBufferLength() && newest->tag <= getBufferTag()) |
| 526 | { |
| 527 | return false; |
| 528 | } |
| 529 | |
| 530 | // Copy data to new clumplet writer |
| 531 | FB_SIZE_T newPos = 0; |
| 532 | ClumpletWriter newPb(newest->kind, sizeLimit, newest->tag); |
| 533 | const FB_SIZE_T currentPosition = cur_offset; |
| 534 | for(rewind(); !isEof(); moveNext()) |
| 535 | { |
| 536 | if (currentPosition == cur_offset) |
| 537 | { |
| 538 | newPos = newPb.cur_offset; |
| 539 | } |
| 540 | newPb.insertClumplet(getClumplet()); |
| 541 | newPb.moveNext(); |
| 542 | } |
| 543 | |
| 544 | // Return it to current clumplet writer in new format |
| 545 | dynamic_buffer.clear(); |
| 546 | kind = newest->kind; |
| 547 | dynamic_buffer.push(newPb.dynamic_buffer.begin(), newPb.dynamic_buffer.getCount()); |
| 548 | |
| 549 | // Set pointer to correct position |
| 550 | if (newPos) |
| 551 | { |
| 552 | cur_offset = newPos; |
| 553 | } |
| 554 | else |
| 555 | { |
| 556 | rewind(); |
| 557 | } |
| 558 | |
| 559 | return true; |
| 560 | } |
| 561 | |
| 562 | void ClumpletWriter::insertClumplet(const SingleClumplet& clumplet) |
| 563 | { |