| 501 | } |
| 502 | |
| 503 | bool cBlockRecordArray::IsClassValid() const |
| 504 | { |
| 505 | ASSERT(mpBlockFile != 0); |
| 506 | cDebug d("cBlockRecordArray::AssertValid"); |
| 507 | if (!mbInit) |
| 508 | { |
| 509 | // if we haven't been initialized yet, then I assume that we are valid... |
| 510 | // |
| 511 | return true; |
| 512 | } |
| 513 | |
| 514 | // |
| 515 | // get the block we need and a reference into the index array.... |
| 516 | // |
| 517 | try |
| 518 | { |
| 519 | cBlockFile::Block* pBlock = mpBlockFile->GetBlock(mBlockNum); |
| 520 | tIndexArray& array = util_GetIndexArray(pBlock); |
| 521 | // |
| 522 | // make sure that the num items and available space make sense... |
| 523 | // |
| 524 | BRA_ASSERT((mNumItems >= 0) && (mNumItems <= MAX_RECORDS)); |
| 525 | BRA_ASSERT((mSpaceAvailable >= 0) && (mSpaceAvailable <= MAX_DATA_SIZE)); |
| 526 | // |
| 527 | // assert that the top index points to a valid value... |
| 528 | // |
| 529 | if (mNumItems != 0) |
| 530 | { |
| 531 | BRA_ASSERT(array.maRecordIndex[mNumItems - 1].GetMainIndex() != INVALID_INDEX); |
| 532 | BRA_ASSERT(array.maRecordIndex[mNumItems - 1].GetOffset() != -1); |
| 533 | } |
| 534 | |
| 535 | int prevOff = 0; |
| 536 | int i; |
| 537 | for (i = 0; i < mNumItems; i++) |
| 538 | { |
| 539 | BRA_ASSERT(array.maRecordIndex[i].GetOffset() >= prevOff); |
| 540 | prevOff = array.maRecordIndex[i].GetOffset(); |
| 541 | } |
| 542 | // make sure the guard byte is there... |
| 543 | // |
| 544 | BRA_ASSERT(array.maRecordIndex[i].GetOffset() == -1); |
| 545 | // |
| 546 | // make sure the final offset is less than the highest record index offset. |
| 547 | // |
| 548 | BRA_ASSERT((int8*)&array.maRecordIndex[i] < util_OffsetToAddr(pBlock, prevOff)); |
| 549 | // |
| 550 | // TODO -- is there anything else that is worth checking? |
| 551 | } |
| 552 | catch (eArchive& e) |
| 553 | { |
| 554 | d.TraceError("*** cBlockFile::GetBlock threw an eArchive: %d %s\n", e.GetID(), e.GetMsg().c_str()); |
| 555 | BRA_ASSERT(false); |
| 556 | } |
| 557 | // if we got here, then everything worked ok. |
| 558 | // |
| 559 | return true; |
| 560 | } |