home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / fed0217s.zip / include / collect.h < prev    next >
C/C++ Source or Header  |  1998-03-31  |  2KB  |  79 lines

  1. /*
  2. ** Module   :COLLECT.H
  3. ** Abstract :Class Collection and SortedCollection
  4. **
  5. ** Copyright (C) Sergey I. Yevtushenko
  6. **
  7. ** Log: Sun  13/03/1994     Updated
  8. **      Sat  03/05/1997     Some methods inlined, to achieve maximum performance
  9. */
  10.  
  11. #ifndef  __COLLECT_H
  12. #define  __COLLECT_H
  13.  
  14. class Collection;
  15. typedef Collection* PCollection;
  16. typedef Collection& RCollection;
  17.  
  18. typedef void * Ptr;
  19.  
  20. typedef void (*ForEachFunc)(Ptr);
  21.  
  22. class Collection
  23. {
  24.     protected:
  25.  
  26.         Ptr * ppData;
  27.         unsigned     dwLast;
  28.         unsigned     dwCount;
  29.         unsigned     dwDelta;
  30.         int      bDuplicates;
  31.  
  32.         void remove_items(PCollection dest, unsigned from, unsigned count);
  33.         void move_items(PCollection src, unsigned from);
  34.  
  35.     public:
  36.  
  37.         //───── New
  38.  
  39.         Collection(unsigned aCount =1024, unsigned aDelta =1024);
  40.         virtual ~Collection();
  41.         Ptr Get(unsigned index) { return (index < dwLast) ? ppData[index]:0;}
  42.  
  43.         Ptr Remove(unsigned);
  44.  
  45.         virtual void Add(Ptr);
  46.         virtual void At(Ptr, unsigned);
  47.         virtual void Free(Ptr p);
  48.  
  49.         void  ForEach(ForEachFunc);
  50.         unsigned Count()                {return dwLast;}
  51.         void  RemoveAll();
  52.  
  53. };
  54.  
  55. class SortedCollection;
  56. typedef SortedCollection* PSortedCollection;
  57. typedef SortedCollection& RSortedCollection;
  58.  
  59. class SortedCollection:public Collection
  60. {
  61.     public:
  62.  
  63.         //───── New
  64.  
  65.         SortedCollection(unsigned aCount = 10, unsigned aDelta = 5):Collection(aCount, aDelta)
  66.                         { bDuplicates = 1;}
  67.  
  68.         virtual int Compare(Ptr p1, Ptr p2)
  69.                         {return *((int *)p1) - *((int *)p2);}
  70.  
  71.         virtual unsigned Look(Ptr);
  72.  
  73.         //───── Replaced
  74.  
  75.         virtual void Add(Ptr);
  76. };
  77.  
  78. #endif //__COLLECT_H
  79.