home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / clobsh.pak / SET.H < prev    next >
C/C++ Source or Header  |  1997-07-23  |  5KB  |  202 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  SET.H                                                                 */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1993                            */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __SET_H )
  11. #define __SET_H
  12.  
  13. #define BI_OLDNAMES
  14.  
  15. #if !defined( TEMPLATES )
  16.  
  17. #if !defined( __RESOURCE_H )
  18. #include "classlib\Resource.h"
  19. #endif  // __RESOURCE_H
  20.  
  21. #if !defined( __CLSTYPES_H )
  22. #include "classlib\obsolete\ClsTypes.h"
  23. #endif  // __CLSTYPES_H
  24.  
  25. #if !defined( __BAG_H )
  26. #include "classlib\obsolete\Bag.h"
  27. #endif  // __BAG_H
  28.  
  29. _CLASSDEF(Set)
  30.  
  31. class _CLASSTYPE Set : public Bag
  32. {
  33.  
  34. public:
  35.  
  36.     Set( sizeType setSize = DEFAULT_SET_SIZE ) :
  37.         Bag( setSize )
  38.         {
  39.         }
  40.  
  41.     virtual void add( Object _FAR & toAdd )
  42.         {
  43.         if( !(Bag::hasMember( toAdd )) )
  44.             {
  45.             Bag::add( toAdd );
  46.             }
  47.         }
  48.     virtual classType isA() const
  49.         {
  50.         return setClass;
  51.         }
  52.  
  53.     virtual char _FAR *nameOf() const
  54.         {
  55.         return "Set";
  56.         }
  57.  
  58. };
  59.  
  60. #else   // TEMPLATES
  61.  
  62. #if !defined( __COLLECT_H )
  63. #include "classlib\obsolete\Collect.h"
  64. #endif  // __COLLECT_H
  65.  
  66. #if !defined( __BAG_H )
  67. #include "classlib\obsolete\Bag.h"
  68. #endif  // __BAG_H
  69.  
  70. #if !defined( __SETS_H )
  71. #include "classlib\Sets.h"
  72. #endif  // __SETS_H
  73.  
  74.  
  75. #pragma option -Vo-
  76. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  77. #pragma option -po-
  78. #endif
  79.  
  80. #define Set   BI_TCSetAsVector
  81. #define PSet  PBI_TCSetAsVector
  82. #define RSet  RBI_TCSetAsVector
  83. #define RPSet RPBI_TCSetAsVector
  84. #define PCSet PCBI_TCSetAsVector
  85. #define RCSet RCBI_TCSetAsVector
  86.  
  87. _CLASSDEF( BI_TCSetAsVector )
  88.  
  89. #define SetIterator   BI_TCSetAsVectorIterator
  90. #define PSetIterator  PBI_TCSetAsVectorIterator
  91. #define RSetIterator  RBI_TCSetAsVectorIterator
  92. #define RPSetIterator RPBI_TCSetAsVectorIterator
  93. #define PCSetIterator PCBI_TCSetAsVectorIterator
  94. #define RCSetIterator RCBI_TCSetAsVectorIterator
  95.  
  96. _CLASSDEF( BI_TCSetAsVectorIterator )
  97.  
  98. /*------------------------------------------------------------------------*/
  99. /*                                                                        */
  100. /*  class BI_OSetAsVector                                                 */
  101. /*                                                                        */
  102. /*  Implements a set of pointers to Object,                               */
  103. /*  using a vector as the underlying implementation.                      */
  104. /*                                                                        */
  105. /*------------------------------------------------------------------------*/
  106.  
  107. class _CLASSTYPE BI_OSetAsVector : public BI_OBagAsVector
  108. {
  109.  
  110. public:
  111.  
  112.     BI_OSetAsVector( unsigned sz = DEFAULT_SET_SIZE ) :
  113.         BI_OBagAsVector(sz)
  114.         {
  115.         }
  116.  
  117.     void add( Object _FAR *o )
  118.         {
  119.         if( !hasMember(o) )
  120.             BI_OBagAsVector::add(o);
  121.         }
  122.  
  123.  
  124. };
  125.  
  126. class BI_OSetAsVectorIterator : public BI_OBagAsVectorIterator
  127. {
  128.  
  129. public:
  130.  
  131.     BI_OSetAsVectorIterator( const BI_OSetAsVector _FAR &s ) :
  132.         BI_OBagAsVectorIterator(s) {}
  133.  
  134. };
  135.  
  136. /*------------------------------------------------------------------------*/
  137. /*                                                                        */
  138. /*  class BI_TCSetAsVector                                                */
  139. /*                                                                        */
  140. /*  Implements an Object set, with the full semantics of                  */
  141. /*  the BC 2.0 style Set, using a vector as the underlying                */
  142. /*  implementation.                                                       */
  143. /*                                                                        */
  144. /*------------------------------------------------------------------------*/
  145.  
  146. class _CLASSTYPE BI_TCSetAsVector : public BI_TCBagAsVector
  147. {
  148.  
  149. public:
  150.  
  151.     BI_TCSetAsVector( unsigned sz = DEFAULT_SET_SIZE ) :
  152.         BI_TCBagAsVector(sz)
  153.         {
  154.         }
  155.  
  156.     virtual void add( Object _FAR &o )
  157.         {
  158.         if( !hasMember(o) )
  159.             BI_TCBagAsVector::add(o);
  160.         }
  161.  
  162.     virtual classType isA() const
  163.         {
  164.         return setClass;
  165.         }
  166.  
  167.     virtual char _FAR *nameOf() const
  168.         {
  169.         return "BI_TCSetAsVector";
  170.         }
  171.  
  172.     virtual ContainerIterator _FAR & BI_TCSetAsVector::initIterator() const;
  173.  
  174. };
  175.  
  176. class BI_TCSetAsVectorIterator : public BI_TCBagAsVectorIterator
  177. {
  178.  
  179. public:
  180.  
  181.     BI_TCSetAsVectorIterator( const BI_TCSetAsVector _FAR &s ) :
  182.         BI_TCBagAsVectorIterator(s)
  183.         {
  184.         }
  185.  
  186. };
  187.  
  188. inline ContainerIterator _FAR & BI_TCSetAsVector::initIterator() const
  189. {
  190.     return *new BI_TCSetAsVectorIterator( *this );
  191. }
  192.  
  193. #endif  // TEMPLATES
  194.  
  195. #if defined( __BCOPT__ ) && !defined( __FLAT__ ) && !defined( _ALLOW_po )
  196. #pragma option -po.
  197. #endif
  198. #pragma option -Vo.
  199.  
  200. #endif  // __SET_H
  201.  
  202.