home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP30-1.ZIP / CLASSINC.ZIP / SETS.H < prev    next >
C/C++ Source or Header  |  1992-02-18  |  6KB  |  211 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  SETS.H                                                                */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991                                  */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __SETS_H )
  11. #define __SETS_H
  12.  
  13. #if !defined( __CHECKS_H )
  14. #include <Checks.h>
  15. #endif    // __CHECKS_H
  16.  
  17. #if !defined( __RESOURCE_H )
  18. #include <Resource.h>
  19. #endif    // __RESOURCE_H
  20.  
  21. #if !defined( __BAGS_H )
  22. #include <Bags.h>
  23. #endif    // __BAGS_H
  24.  
  25. #if !defined( __COLLECT_H )
  26. #include <Collect.h>
  27. #endif    // __COLLECT_H
  28.  
  29. /*------------------------------------------------------------------------*/
  30. /*                                                                        */
  31. /*  template <class T> class BI_SetAsVector                               */
  32. /*                                                                        */
  33. /*  Implements a set of objects of type T, using a vector as              */
  34. /*  the underlying implementation.                                        */
  35. /*                                                                        */
  36. /*------------------------------------------------------------------------*/
  37.  
  38. template <class T> class _CLASSTYPE BI_SetAsVector : public BI_BagAsVector<T>
  39. {
  40.  
  41. public:
  42.  
  43.     BI_SetAsVector( unsigned sz = DEFAULT_SET_SIZE ) :
  44.         BI_BagAsVector<T>(sz)
  45.         {
  46.         }
  47.  
  48.     void add( T );
  49.  
  50. };
  51.  
  52. template <class T> void BI_SetAsVector<T>::add( T t )
  53. {
  54.     if( hasMember(t) )
  55.         return;
  56.     else
  57.         BI_BagAsVector<T>::add(t);
  58. }
  59.  
  60. template <class T> class BI_SetAsVectorIterator :
  61.     public BI_BagAsVectorIterator<T>
  62. {
  63.  
  64. public:
  65.  
  66.     BI_SetAsVectorIterator<T>( const BI_SetAsVector _FAR &s ) :
  67.         BI_BagAsVectorIterator<T>(s) {}
  68.  
  69. };
  70.  
  71. /*------------------------------------------------------------------------*/
  72. /*                                                                        */
  73. /*  template <class T> class BI_ISetAsVector                              */
  74. /*                                                                        */
  75. /*  Implements a set of pointers to objects of type T,                    */
  76. /*  using a vector as the underlying implementation.                      */
  77. /*                                                                        */
  78. /*------------------------------------------------------------------------*/
  79.  
  80. template <class T> class _CLASSTYPE BI_ISetAsVector :
  81.     public BI_IBagAsVector<T>
  82. {
  83.  
  84. public:
  85.  
  86.     BI_ISetAsVector( unsigned sz = DEFAULT_SET_SIZE ) :
  87.         BI_IBagAsVector<T>(sz)
  88.         {
  89.         }
  90.  
  91.     void add( T _FAR * );
  92.  
  93. };
  94.  
  95. template <class T> void BI_ISetAsVector<T>::add( T _FAR *t )
  96. {
  97.     if( hasMember(t) )
  98.         return;
  99.     else
  100.         BI_IBagAsVector<T>::add(t);
  101. }
  102.  
  103. template <class T> class _CLASSTYPE BI_ISetAsVectorIterator :
  104.     public BI_IBagAsVectorIterator<T>
  105. {
  106.  
  107. public:
  108.  
  109.     BI_ISetAsVectorIterator( const BI_ISetAsVector<T> _FAR &s ) :
  110.         BI_IBagAsVectorIterator<T>(s) {}
  111.  
  112. };
  113.  
  114. /*------------------------------------------------------------------------*/
  115. /*                                                                        */
  116. /*  class BI_OSetAsVector                                                 */
  117. /*                                                                        */
  118. /*  Implements a set of pointers to Object,                               */
  119. /*  using a vector as the underlying implementation.                      */
  120. /*                                                                        */
  121. /*------------------------------------------------------------------------*/
  122.  
  123. class _CLASSTYPE BI_OSetAsVector : public BI_OBagAsVector
  124. {
  125.  
  126. public:
  127.  
  128.     BI_OSetAsVector( unsigned sz = DEFAULT_SET_SIZE ) :
  129.         BI_OBagAsVector(sz)
  130.         {
  131.         }
  132.  
  133.     void add( Object _FAR *o )
  134.         {
  135.         if( !hasMember(o) )
  136.             BI_OBagAsVector::add(o);
  137.         }
  138.  
  139.  
  140. };
  141.  
  142. class BI_OSetAsVectorIterator : public BI_OBagAsVectorIterator
  143. {
  144.  
  145. public:
  146.  
  147.     BI_OSetAsVectorIterator( const BI_OSetAsVector _FAR &s ) :
  148.         BI_OBagAsVectorIterator(s) {}
  149.  
  150. };
  151.  
  152. /*------------------------------------------------------------------------*/
  153. /*                                                                        */
  154. /*  class BI_TCSetAsVector                                                */
  155. /*                                                                        */
  156. /*  Implements an Object set, with the full semantics of                  */
  157. /*  the BC 2.0 style Set, using a vector as the underlying                */
  158. /*  implementation.                                                       */
  159. /*                                                                        */
  160. /*------------------------------------------------------------------------*/
  161.  
  162. class _CLASSTYPE BI_TCSetAsVector : public BI_TCBagAsVector
  163. {
  164.  
  165. public:
  166.  
  167.     BI_TCSetAsVector( unsigned sz = DEFAULT_SET_SIZE ) :
  168.         BI_TCBagAsVector(sz)
  169.         {
  170.         }
  171.  
  172.     virtual void add( Object _FAR &o )
  173.         {
  174.         if( !hasMember(o) )
  175.             BI_TCBagAsVector::add(o);
  176.         }
  177.  
  178.     virtual classType isA() const
  179.         {
  180.         return setClass;
  181.         }
  182.  
  183.     virtual char _FAR *nameOf() const
  184.         {
  185.         return "BI_TCSetAsVector";
  186.         }
  187.  
  188.     virtual ContainerIterator _FAR & BI_TCSetAsVector::initIterator() const;
  189.  
  190. };
  191.  
  192. class BI_TCSetAsVectorIterator : public BI_TCBagAsVectorIterator
  193. {
  194.  
  195. public:
  196.  
  197.     BI_TCSetAsVectorIterator( const BI_TCSetAsVector _FAR &s ) :
  198.         BI_TCBagAsVectorIterator(s)
  199.         {
  200.         }
  201.  
  202. };
  203.  
  204. inline ContainerIterator _FAR & BI_TCSetAsVector::initIterator() const
  205. {
  206.     return *new BI_TCSetAsVectorIterator( *this );
  207. }
  208.  
  209. #endif  // __SETS_H
  210.  
  211.