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

  1. /* ------------------------------------------------------------------------*/
  2. /*                                                                         */
  3. /*   TVOBJS.H                                                              */
  4. /*                                                                         */
  5. /*   Copyright (c) Borland International 1991                              */
  6. /*   All Rights Reserved.                                                  */
  7. /*                                                                         */
  8. /*   defines the classes TObject, TNSCollection, and TNSSortedCollection.  */
  9. /*                                                                         */
  10. /*   The NS variants of collections are Not Streamable.  These are         */
  11. /*   needed for internal use in the stream manager.  There are             */
  12. /*   streamable variants of each of these classes for use by the           */
  13. /*   rest of the library.                                                  */
  14. /*                                                                         */
  15. /* ------------------------------------------------------------------------*/
  16.  
  17. #pragma option -Vo-
  18. #if defined( __BCOPT__ )
  19. #pragma option -po-
  20. #endif
  21.  
  22. #if defined( Uses_TObject ) && !defined( __TObject )
  23. #define __TObject
  24.  
  25. #if !defined( __STDDEF_H )
  26. #include <StdDef.h>
  27. #endif  // __STDDEF_H
  28.  
  29. class TObject
  30. {
  31.  
  32. public:
  33.  
  34.     virtual ~TObject();
  35.  
  36.     static void destroy( TObject * );
  37.     virtual void shutDown();
  38.  
  39. private:
  40.  
  41. };
  42.  
  43. inline void TObject::destroy( TObject *o )
  44. {
  45.     if( o != 0 )
  46.         o->shutDown();
  47.     delete o;
  48. }
  49.  
  50. #endif  // Uses_TObject
  51.  
  52. #if defined( Uses_TNSCollection ) && !defined( __TNSCollection )
  53. #define __TNSCollection
  54.  
  55. class TNSCollection : public TObject
  56. {
  57.  
  58. public:
  59.  
  60.     TNSCollection( ccIndex aLimit, ccIndex aDelta );
  61.     ~TNSCollection();
  62.  
  63.     virtual void shutDown();
  64.  
  65.     void *at( ccIndex index );
  66.     virtual ccIndex indexOf( void *item );
  67.  
  68.     void atFree( ccIndex index );
  69.     void atRemove( ccIndex index );
  70.     void remove( void *item );
  71.     void removeAll();
  72.     void free( void *item );
  73.     void freeAll();
  74.  
  75.     void atInsert( ccIndex index, void *item );
  76.     void atPut( ccIndex index, void *item );
  77.     virtual ccIndex insert( void *item );
  78.  
  79.     static void error( ccIndex code, ccIndex info );
  80.  
  81.     void *firstThat( ccTestFunc Test, void *arg );
  82.     void *lastThat( ccTestFunc Test, void *arg );
  83.     void forEach( ccAppFunc action, void *arg );
  84.  
  85.     void pack();
  86.     virtual void setLimit( ccIndex aLimit );
  87.  
  88.     ccIndex getCount()
  89.         { return count; }
  90.  
  91. protected:
  92.  
  93.     TNSCollection();
  94.  
  95.     void **items;
  96.     ccIndex count;
  97.     ccIndex limit;
  98.     ccIndex delta;
  99.     Boolean shouldDelete;
  100.  
  101. private:
  102.  
  103.     virtual void freeItem( void *item );
  104.  
  105. };
  106.  
  107. #endif  // Uses_TNSCollection
  108.  
  109. #if defined( Uses_TNSSortedCollection ) && !defined( __TNSSortedCollection )
  110. #define __TNSSortedCollection
  111.  
  112. class TNSSortedCollection: public virtual TNSCollection
  113. {
  114.  
  115. public:
  116.  
  117.     TNSSortedCollection( ccIndex aLimit, ccIndex aDelta) :
  118.         TNSCollection( aLimit, aDelta ), duplicates(False)
  119.             { delta = aDelta; setLimit( aLimit ); }
  120.  
  121.     virtual Boolean search( void *key, ccIndex& index );
  122.  
  123.     virtual ccIndex indexOf( void *item );
  124.     virtual ccIndex insert( void *item );
  125.  
  126.     Boolean duplicates;
  127.     virtual void *keyOf( void *item );
  128.  
  129. protected:
  130.  
  131.     TNSSortedCollection() : duplicates(False) {}
  132.  
  133. private:
  134.  
  135.     virtual int compare( void *key1, void *key2 ) = 0;
  136.  
  137. };
  138.  
  139. #endif  // Uses_TNSSortedCollection
  140.  
  141. #pragma option -Vo.
  142. #if defined( __BCOPT__ )
  143. #pragma option -po.
  144. #endif
  145.  
  146.