home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BCPPOWL1.ZIP / OWLINC.ZIP / TCOLLECT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  2.3 KB  |  103 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. #if !defined( __TCOLLECT_H )
  4. #define __TCOLLECT_H
  5.  
  6. #if !defined( __OBJECT_H )
  7. #include <object.h>
  8. #endif  // __OBJECT_H
  9.  
  10. enum Boolean { False, True };
  11.  
  12. typedef unsigned short ushort;
  13. typedef unsigned char uchar;
  14.  
  15. const char EOS = '\0';
  16.  
  17. typedef int ccIndex;
  18. typedef Boolean (_FAR *ccTestFunc)( Pvoid, Pvoid );
  19. typedef void (_FAR *ccAppFunc)( Pvoid, Pvoid );
  20.  
  21. const ccNotFound = -1;
  22. const maxCollectionSize = (int)((65536uL - 16)/sizeof( Pvoid ));
  23.  
  24. const TCOLLECTION_CLASS_HASH_VALUE = 0;
  25.  
  26. _CLASSDEF(TNSCollection)
  27. _CLASSDEF(TNSSortedCollection)
  28.  
  29. class _CLASSTYPE TNSCollection
  30. {
  31. public:
  32.  
  33.     TNSCollection( ccIndex aLimit, ccIndex aDelta );
  34.     ~TNSCollection();
  35.  
  36.     Pvoid at( ccIndex index );
  37.     virtual ccIndex indexOf( Pvoid item );
  38.  
  39.     void atFree( ccIndex index );
  40.     void atRemove( ccIndex index );
  41.     void remove( Pvoid item );
  42.     void removeAll();
  43.     void free( Pvoid item );
  44.     void freeAll();
  45.  
  46.     void atInsert( ccIndex index, Pvoid item );
  47.     void atPut( ccIndex index, Pvoid item );
  48.     virtual ccIndex insert( Pvoid item );
  49.  
  50.     static void error( ccIndex code, ccIndex info );
  51.  
  52.     Pvoid firstThat( ccTestFunc Test, Pvoid arg );
  53.     Pvoid lastThat( ccTestFunc Test, Pvoid arg );
  54.     void forEach( ccAppFunc action, Pvoid arg );
  55.  
  56.     void pack();
  57.     virtual void setLimit( ccIndex aLimit );
  58.  
  59.     ccIndex getCount()
  60.         { return count; }
  61.  
  62. protected:
  63.  
  64.     TNSCollection();
  65.  
  66.     Pvoid _FAR *items;
  67.     ccIndex count;
  68.     ccIndex limit;
  69.     ccIndex delta;
  70.     Boolean shouldDelete;
  71.  
  72. private:
  73.  
  74.     virtual void freeItem( Pvoid item );
  75. };
  76.  
  77. class _CLASSTYPE TNSSortedCollection: public virtual TNSCollection
  78. {
  79. public:
  80.  
  81.     TNSSortedCollection( ccIndex aLimit, ccIndex aDelta) :
  82.         TNSCollection( aLimit, aDelta )
  83.         { delta = aDelta; setLimit( aLimit ); }
  84.  
  85.     virtual Boolean search( Pvoid key, ccIndex _FAR & index );
  86.  
  87.     virtual ccIndex indexOf( Pvoid item );
  88.     virtual ccIndex insert( Pvoid item );
  89.  
  90.     Boolean duplicates;
  91.  
  92. protected:
  93.  
  94.     TNSSortedCollection() {};
  95.     virtual Pvoid keyOf( Pvoid item ) { return item; }
  96.  
  97. private:
  98.  
  99.     virtual int compare( Pvoid key1, Pvoid key2 ) = 0;
  100. };
  101.  
  102. #endif // __TCOLLECT_H
  103.