home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 3.ddi / OWLINC.ZIP / TCOLLECT.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  2.5 KB  |  117 lines

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