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

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