home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C++ / Applications / Nuntius 1.2 / src / Nuntius / UDynDynArray.h < prev    next >
Encoding:
Text File  |  1994-03-06  |  3.1 KB  |  105 lines  |  [TEXT/MPS ]

  1. // Copyright © 1993 Peter Speck, speck@dat.ruc.dk. All rights reserved.
  2. // UDynDynArray.h
  3.  
  4. #define __UDYNDYNARRAY__
  5.  
  6. #ifndef __UPTROBJECT__
  7. #include "UPtrObject.h"
  8. #endif
  9.  
  10. // PDynDynArray is an array, in which the elements can have different size
  11.  
  12. class CChunkyHandle
  13. {
  14.     private:
  15.         Handle fHandleH;
  16.         long fSize;
  17.         long fAllocSize;
  18.         long fChunk;
  19.         Boolean fHandleIsLocked;
  20.         
  21.     public:
  22.         CChunkyHandle();
  23.         void IChunkyHandle(long chunk);
  24.         ~CChunkyHandle();
  25.  
  26.         void SizeToFit();
  27.         void DeleteAll(); // does not SizeToFit
  28.         void SetNeededSize(long needed);
  29.         void DeltaSize(long delta);
  30.         long GetSize() { return fSize; }
  31.         long GetAllocSize() { return fAllocSize; }
  32.         Ptr PtrAtOffset(long offset) { return  *fHandleH + offset; }
  33.         void MakeGap(long offset, long gaplen);
  34.         void DeleteGap(long offset, long gaplen);
  35.         void AppendChar(char ch);
  36.         
  37.         Boolean LockHandle(Boolean newLock, Boolean moveHigh); // returns old lock state
  38.         void DoRead(TStream *aStream);
  39.         void DoWrite(TStream *aStream);
  40.         long NeededDiskSpace();
  41.  
  42.         void DebugDump(Boolean verbose);
  43.         Boolean SanityCheck();
  44. };
  45.  
  46. class PDynDynArray : public PPtrObject
  47. {
  48.     public:
  49.         virtual Boolean LockDataHandle(Boolean newLock, Boolean moveHigh = false); // returns old lock state
  50.  
  51.         virtual ArrayIndex CreateNewElement(ArrayIndex size);
  52.         virtual void InsertLast(const void *elementPtr, long size);
  53.         virtual void DeleteElementAt(ArrayIndex index);
  54.         virtual void DeleteAll();
  55.         virtual void Specify(PDynDynArray *arrayToCopy);
  56.  
  57.         virtual ArrayIndex GetSize();
  58.         virtual long GetDataAllocSize();
  59.         virtual void SizeAllocToFit();
  60.         Ptr ComputeAddress(ArrayIndex index); // OBS: Pointer into an unlocked handle!
  61.         virtual void GetElementsAt(ArrayIndex index, void* elementPtr, ArrayIndex count);
  62.         virtual void SetElementSize(ArrayIndex index, long newElementSize);
  63.         virtual long GetElementSize(ArrayIndex index);
  64.         virtual void ReplaceElementsAt(ArrayIndex index,
  65.                                           const void *elementPtr, ArrayIndex count);
  66.         virtual void InsertElementBefore(ArrayIndex index);
  67.         virtual void InsertElementBefore(ArrayIndex index, const void *elementPtr, long size);
  68.  
  69.         virtual void DoRead(TStream *aStream);
  70.         virtual void DoWrite(TStream *aStream);
  71.         virtual long NeededDiskSpace();
  72.         
  73.         virtual void DebugDump(Boolean verbose);
  74.         virtual Boolean SanityCheck();
  75.  
  76.         PDynDynArray();
  77.         void IDynDynArray(long allocChunk);
  78.         virtual ~PDynDynArray();
  79.     private:
  80.         CChunkyHandle fIndex;
  81.         CChunkyHandle fData;
  82.         
  83.         long GetIndexOffset(ArrayIndex index);
  84.         long GetElementOffset(ArrayIndex index);
  85.         ArrayIndex MySize() { return fIndex.GetSize() >> 3; } // 2 longs for each item
  86. };
  87.  
  88. class PString255Array : public PDynDynArray
  89. {
  90.     public:
  91.         virtual void Append(const CStr255 &s);
  92.         virtual void GetStringAt(ArrayIndex index, CStr255 &s);
  93.         virtual void ReplaceStringAt(ArrayIndex index, CStr255 &s);
  94.         virtual void InsertStringBefore(ArrayIndex index, CStr255 &s);
  95.         
  96.         PString255Array();
  97.         void IString255Array(long allocChunk);
  98.         ~PString255Array();
  99.     private:
  100.         long StringSize(const CStr255 &s);
  101. };
  102.  
  103. PDynDynArray *NewDynDynArray(long allocChunk);
  104. PString255Array *NewString255Array(long allocChunk = 512);
  105.