home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / h.z / WCLIST.H < prev    next >
C/C++ Source or Header  |  1996-07-24  |  8KB  |  286 lines

  1. //
  2. //  wclist.h    Defines the WATCOM Container List Classes
  3. //
  4. //  Copyright by WATCOM International Corp. 1988-1996.  All rights reserved.
  5. //
  6. #ifndef _WCLIST_H_INCLUDED
  7. #define _WCLIST_H_INCLUDED
  8.  
  9. #pragma warning 621 9       // I want the behaviour this warning points to
  10.  
  11. #ifndef __cplusplus
  12. #error wclist.h is for use with C++
  13. #endif
  14.  
  15. #ifndef _WCDEFS_H_INCLUDED
  16.  #include <wcdefs.h>
  17. #endif
  18. #ifndef _WCEXCEPT_H_INCLUDED
  19.  #include <wcexcept.h>
  20. #endif
  21. #ifndef _WCLCOM_H_INCLUDED
  22.  #include <wclcom.h>
  23. #endif
  24. #ifndef _WCLBASE_H_INCLUDED
  25.  #include <wclbase.h>
  26. #endif
  27.  
  28.  
  29. //
  30. //  This defines a single linked list of values of type <Type>
  31. //
  32. //  The base class is invoked to process the copy and assignment
  33. //  constructors.  The copies are shallow, in that only the values
  34. //  contained in the list are copied.  If the contained values
  35. //  themselves have defined copy constructors, they can effect a
  36. //  deeper copy.
  37. //
  38.  
  39. template<class Type>
  40. class WCValSList : public WCValListBase< Type,
  41.                    WCIsvSListBase<WCNIsvSLink<Type> >, WCNIsvSLink<Type> > {
  42. private:
  43.     // This virtual function defines equivalence for the base classes.
  44.     virtual int base_equivalent( const Type &elem1, const Type &elem2 ) const {
  45.         return( elem1 == elem2 );
  46.     };
  47.  
  48. public:
  49.     inline WCValSList( void * (*user_alloc)( size_t )
  50.                 , void (*user_dealloc)( void *, size_t )
  51.                 ) : WCValListBase( user_alloc, user_dealloc ) {};
  52.  
  53.     inline WCValSList() : WCValListBase( 0, 0 ) {};
  54.  
  55.     inline ~WCValSList() {};
  56.  
  57.     inline WCValSList( const WCValSList & olist ) {
  58.         base_construct( &olist );
  59.     };
  60.  
  61.     inline WCValSList & operator=( const WCValSList & olist ) {
  62.         base_assign( &olist );
  63.         return( *this );
  64.     };
  65. };
  66.  
  67.  
  68.  
  69.  
  70. //
  71. //  This defines a double linked list of values of type <Type>
  72. //
  73. //  The base class is invoked to process the copy and assignment
  74. //  constructors.  The copies are shallow, in that only the values
  75. //  contained in the list are copied.  If the contained values
  76. //  themselves have defined copy constructors, they can effect a
  77. //  deeper copy.
  78. //
  79.  
  80. template<class Type>
  81. class WCValDList : public WCValListBase<Type,
  82.                    WCIsvDListBase<WCNIsvDLink<Type> >, WCNIsvDLink<Type> > {
  83. private:
  84.     // This virtual function defines equivalence for the base classes.
  85.     virtual int base_equivalent( const Type &elem1, const Type &elem2 ) const {
  86.         return( elem1 == elem2 );
  87.     };
  88.  
  89. public:
  90.     inline WCValDList( void * (*user_alloc)( size_t ) 
  91.                 , void (*user_dealloc)( void *, size_t )
  92.                 ) : WCValListBase( user_alloc, user_dealloc ) {};
  93.  
  94.     inline WCValDList() : WCValListBase( 0, 0 ) {};
  95.  
  96.     inline ~WCValDList() {};
  97.  
  98.     inline WCValDList( const WCValDList & olist ) {
  99.         base_construct( &olist );
  100.     };
  101.  
  102.     inline WCValDList & operator=( const WCValDList & olist ) {
  103.         base_assign( &olist );
  104.         return( *this );
  105.     };
  106. };
  107.  
  108.  
  109.  
  110.  
  111. //
  112. //  This defines a single linked list of pointers of type <Type>
  113. //
  114. //  The base class is invoked to process the copy and assignment
  115. //  constructors.  The copies are shallow, in that only the pointers
  116. //  contained in the list are copied.
  117. //  deeper copy.
  118. //
  119.  
  120. template<class Type>
  121. class WCPtrSList : public WCPtrListBase<Type, WCValSList<Type *> > {
  122. private:
  123.     // This virtual function defines equivalence for the base classes.
  124.     virtual int base_equivalent( Type * const &elem1
  125.                                , Type * const &elem2 ) const {
  126.         return( *(const Type *)elem1 == *(const Type *)elem2 );
  127.     };
  128.  
  129. public:
  130.     inline WCPtrSList( void * (*user_alloc)( size_t )
  131.                 , void (*user_dealloc)( void *, size_t )
  132.                 ) : WCPtrListBase( user_alloc, user_dealloc ) {};
  133.  
  134.     inline WCPtrSList() : WCPtrListBase( 0, 0 ) {};
  135.  
  136.     inline ~WCPtrSList() {};
  137.  
  138.     inline WCPtrSList( const WCPtrSList & olist ) {
  139.         base_construct( &olist );
  140.     };
  141.  
  142.     inline int index( const Type * ptr ) const {
  143.         return( WCPtrListBase::index( (Type * const)ptr ) );
  144.     };
  145.  
  146.     inline WCPtrSList & operator=( const WCPtrSList & olist ) {
  147.         base_assign( &olist );
  148.         return( *this );
  149.     };
  150. };
  151.  
  152.  
  153.  
  154.  
  155. //
  156. //  This defines a double linked list of pointers of type <Type>
  157. //
  158. //  The base class is invoked to process the copy and assignment
  159. //  constructors.  The copies are shallow, in that only the pointers
  160. //  contained in the list are copied.
  161. //
  162.  
  163. template<class Type>
  164. class WCPtrDList : public WCPtrListBase<Type, WCValDList<Type *> > {
  165. private:
  166.     // This virtual function defines equivalence for the base classes.
  167.     virtual int base_equivalent( Type * const &elem1
  168.                                , Type * const &elem2 ) const {
  169.         return( *(const Type *)elem1 == *(const Type *)elem2 );
  170.     };
  171.  
  172. public:
  173.     inline WCPtrDList( void * (*user_alloc)( size_t )
  174.                 , void (*user_dealloc)( void *, size_t )
  175.                 ) : WCPtrListBase( user_alloc, user_dealloc ) {};
  176.  
  177.     inline WCPtrDList() : WCPtrListBase( 0, 0 ) {};
  178.  
  179.     inline ~WCPtrDList() {};
  180.  
  181.     inline WCPtrDList( const WCPtrDList & olist ) {
  182.         base_construct( &olist );
  183.     };
  184.  
  185.     inline int index( const Type * ptr ) const {
  186.         return( WCPtrListBase::index( (Type * const)ptr ) );
  187.     };
  188.  
  189.     inline WCPtrDList & operator=( const WCPtrDList & olist ) {
  190.         base_assign( &olist );
  191.         return( *this );
  192.     };
  193. };
  194.  
  195.  
  196.  
  197.  
  198. //
  199. //  This defines a single linked list of values of type <Type>,
  200. //  stored intrusively.
  201. //
  202. //  The copy and assignment constructors are made private so
  203. //  that a second copy of the list is not made (intrusive lists
  204. //  require modification of the base links, making second copies
  205. //  a problem).
  206. //
  207.  
  208. template<class Type>
  209. class WCIsvSList : public WCPtrListBase<Type, WCIsvSListBase<Type> > {
  210. private:
  211.     WCIsvSList( const WCIsvSList & );
  212.     WCIsvSList & operator=( const WCIsvSList & );
  213.  
  214. protected:
  215.     //
  216.     // This constuctor is necessary for inherited classes such as WCStack and
  217.     // WCQueue to be able to support user allocators and deallocators.
  218.     // It is not intended for users of the class.
  219.     //
  220.     inline WCIsvSList( void * (*)( size_t ), void (*)( void *, size_t ) ) {};
  221.  
  222. public:    
  223.     inline WCIsvSList() {};
  224.     inline ~WCIsvSList() {};
  225.  
  226.     inline void forAll( void (*fn)( Type *, void * ), void *data ) {
  227.         WCPtrListBase::forAll( fn, data );
  228.     };
  229.  
  230.     inline int index( int (*test_fn)( const Type *, void * )
  231.                     , void *data ) const {
  232.         return( WCPtrListBase::index( test_fn, data ) );
  233.     };
  234.  
  235.     inline int index( const Type *elem ) const {
  236.         return( WCPtrListBase::index( elem ) );
  237.     };
  238. };
  239.  
  240.  
  241.  
  242.  
  243. //
  244. //  This defines a double linked list of values of type <Type>,
  245. //  stored intrusively.
  246. //
  247. //  The copy and assignment constructors are made private so
  248. //  that a second copy of the list is not made (intrusive lists
  249. //  require modification of the base links, making second copies
  250. //  a problem).
  251. //
  252.  
  253. template<class Type>
  254. class WCIsvDList : public WCPtrListBase<Type, WCIsvDListBase<Type> > {
  255. private:
  256.     WCIsvDList( const WCIsvDList & );
  257.     WCIsvDList & operator=( const WCIsvDList & );
  258.  
  259. protected:
  260.     //
  261.     // This constuctor is necessary for inherited classes such as WCStack and
  262.     // WCQueue to be able to support user allocators and deallocators.
  263.     // It is not intended for users of the class.
  264.     //
  265.     inline WCIsvDList( void * (*)( size_t ), void (*)( void *, size_t ) ) {};
  266.  
  267. public:    
  268.     inline WCIsvDList() {};
  269.     inline ~WCIsvDList() {};
  270.  
  271.     inline void forAll( void (*fn)( Type *, void * ), void *data ) {
  272.         WCPtrListBase::forAll( fn, data );
  273.     };
  274.  
  275.     inline int index( int (*test_fn)( const Type *, void * )
  276.                     , void *data ) const {
  277.         return( WCPtrListBase::index( test_fn, data ) );
  278.     };
  279.  
  280.     inline int index( const Type *elem ) const {
  281.         return( WCPtrListBase::index( elem ) );
  282.     };
  283. };
  284.  
  285. #endif
  286.