home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / UOffsetLengthList.cp < prev    next >
Encoding:
Text File  |  1994-02-20  |  2.5 KB  |  116 lines  |  [TEXT/MPS ]

  1. // Copyright © 1992 Peter Speck, speck@dat.ruc.dk. All rights reserved.
  2. // UOffsetLengthList.cp
  3.  
  4. #include "UOffsetLengthList.h"
  5. #include "StreamTools.h"
  6.  
  7. #pragma segment MyArray
  8.  
  9. const long kCurrentOLLVersion = 1;
  10. const long kMinOLLVersion = 1;
  11.  
  12. TOffsetLengthList::TOffsetLengthList()
  13. {
  14. }
  15.  
  16. pascal void TOffsetLengthList::Initialize()
  17. {
  18.     inherited::Initialize();
  19. }
  20.  
  21. void TOffsetLengthList::IOffsetLengthList()
  22. {
  23.     inherited::IDynamicArray(0, sizeof(long) + sizeof(long));
  24. }
  25.  
  26. pascal void TOffsetLengthList::Free()
  27. {
  28.     inherited::Free();
  29. }
  30.  
  31. void TOffsetLengthList::DoRead(TStream *aStream)
  32. {
  33.     long version = aStream->ReadLong();
  34.     MyStreamCheckVersion(version, kMinOLLVersion, kCurrentOLLVersion, "TOffsetLengthList");
  35.     ReadDynamicArray(aStream, this);
  36. }
  37.  
  38. void TOffsetLengthList::DoWrite(TStream *aStream)
  39. {
  40.     aStream->WriteLong(kCurrentOLLVersion);
  41.     WriteDynamicArray(aStream, this);
  42. }
  43.  
  44. void TOffsetLengthList::DoNeedDiskSpace(long &dataForkBytes)
  45. {
  46.     dataForkBytes += sizeof(long); // version
  47.     dataForkBytes += MyStreamSizeOfDynamicArray(this);
  48. }
  49.  
  50. void TOffsetLengthList::InsertLast(const OffsetLength &ol)
  51. {
  52.     InsertElementsBefore(fSize + 1, &ol, 1);
  53. }
  54.  
  55. OffsetLength TOffsetLengthList::At(long index)
  56. {
  57. #if qDebug
  58.     if (index < 1 || index > fSize)
  59.     {
  60.         fprintf(stderr, "Index (%ld) out of range [1, %ld]\n", index, 1, fSize);
  61.         ProgramBreak(gEmptyString);
  62.     }
  63. #endif
  64.     return *OffsetLengthPtr(ComputeAddress(index));
  65. }
  66.  
  67. long TOffsetLengthList::OffsetAt(long index)
  68. {
  69. #if qDebug
  70.     if (index < 1 || index > fSize)
  71.     {
  72.         fprintf(stderr, "Index (%ld) out of range [1, %ld]\n", index, 1, fSize);
  73.         ProgramBreak(gEmptyString);
  74.     }
  75. #endif
  76.     return *LongIntPtr(ComputeAddress(index));
  77. }
  78.  
  79. long TOffsetLengthList::LengthAt(long index)
  80. {
  81. #if qDebug
  82.     if (index < 1 || index > fSize)
  83.     {
  84.         fprintf(stderr, "Index (%ld) out of range [1, %ld]\n", index, 1, fSize);
  85.         ProgramBreak(gEmptyString);
  86.     }
  87. #endif
  88.     return *LongIntPtr(ComputeAddress(index) + 4);
  89. }
  90.  
  91. void TOffsetLengthList::AtPut(long index, const OffsetLength &ol)
  92. {
  93. #if qDebug
  94.     if (index < 1 || index > fSize)
  95.     {
  96.         fprintf(stderr, "Index (%ld) out of range [1, %ld]\n", index, 1, fSize);
  97.         ProgramBreak(gEmptyString);
  98.     }
  99. #endif
  100.     *OffsetLengthPtr(ComputeAddress(index)) = ol;
  101.     // somewhat faster than ReplaceElementsAt()
  102. }
  103.  
  104. void TOffsetLengthList::AtGet(long index, OffsetLength &ol)
  105. {
  106. #if qDebug
  107.     if (index < 1 || index > fSize)
  108.     {
  109.         fprintf(stderr, "Index (%ld) out of range [1, %ld]\n", index, fSize);
  110.         ProgramBreak(gEmptyString); 
  111.     }
  112. #endif
  113.     ol = *OffsetLengthPtr(ComputeAddress(index));
  114.     // somewhat faster than GetElementsAt()
  115. }
  116.