home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / classinc.pak / VECTIMP.H < prev    next >
C/C++ Source or Header  |  1997-07-23  |  43KB  |  1,450 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  VECTIMP.H                                                             */
  4. /*                                                                        */
  5. /*  Copyright (c) 1991, 1994 Borland International                        */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( CLASSLIB_VECTIMP_H )
  11. #define CLASSLIB_VECTIMP_H
  12.  
  13. #if !defined( __LIMITS_H )
  14. #include <limits.h>
  15. #endif
  16.  
  17. #if !defined( __CHECKS_H )
  18. #include <checks.h>
  19. #endif
  20.  
  21. #if !defined( CLASSLIB_DEFS_H )
  22. #include <classlib/defs.h>
  23. #endif
  24.  
  25. #if !defined( CLASSLIB_STDTEMPL_H )
  26. #include <classlib/stdtempl.h>
  27. #endif
  28.  
  29. #if !defined( CLASSLIB_ALLOCTR_H )
  30. #include <classlib/alloctr.h>
  31. #endif
  32.  
  33. #if !defined( CLASSLIB_MEMMGR_H )
  34. #include <classlib/memmgr.h>
  35. #endif
  36.  
  37. #if !defined( CLASSLIB_VOIDP_H )
  38. #include <classlib/voidp.h>
  39. #endif
  40.  
  41. #pragma option -Vo-
  42. #if defined( BI_CLASSLIB_NO_po )
  43. #pragma option -po-
  44. #endif
  45.  
  46. /*------------------------------------------------------------------------*/
  47. /*                                                                        */
  48. /*  template <class T, class Alloc> class TVectorImpBase                  */
  49. /*                                                                        */
  50. /*  Implements the base functionality for a managed vector of objects of  */
  51. /*  type T.  Assumes that T has meaningful copy semantics and a default   */
  52. /*  constructor.                                                          */
  53. /*                                                                        */
  54. /*------------------------------------------------------------------------*/
  55.  
  56. template <class T, class Alloc> class TVectorImpBase :
  57.     public Alloc
  58. {
  59.  
  60. public:
  61.  
  62.     TVectorImpBase() : Data(0), Lim(0) {}
  63.  
  64.     TVectorImpBase( unsigned sz, unsigned d ) :
  65.         Data( new(*this)T[sz] ),
  66.         Lim(sz)
  67.         {
  68.         }
  69.  
  70.     TVectorImpBase( const TVectorImpBase<T,Alloc>& );
  71.  
  72.     const TVectorImpBase<T,Alloc>& operator = (
  73.                 const TVectorImpBase<T,Alloc>& );
  74.  
  75.     ~TVectorImpBase()
  76.         {
  77.         delete [] Data;
  78.         }
  79.  
  80.     unsigned Limit() const
  81.         {
  82.         return Lim;
  83.         }
  84.  
  85.     virtual unsigned Top() const
  86.         {
  87.         return Lim;
  88.         }
  89.  
  90.     virtual unsigned Count() const
  91.         {
  92.         return Lim;
  93.         }
  94.  
  95.     int Resize( unsigned, unsigned = 0 );
  96.  
  97.     virtual unsigned GetDelta() const
  98.         {
  99.         return 0;
  100.         }
  101.  
  102. #if defined( BI_OLDNAMES )
  103.     unsigned limit() const { return Limit(); }
  104.     int resize( unsigned sz, unsigned off = 0 ) { return Resize(sz,off); }
  105. #endif
  106.  
  107. protected:
  108.  
  109.     T * Data;
  110.     unsigned Lim;
  111.  
  112.     virtual void Zero( unsigned, unsigned )
  113.         {
  114.         }
  115.  
  116. };
  117.  
  118. template <class T, class Alloc>
  119. TVectorImpBase<T,Alloc>::TVectorImpBase(
  120.         const TVectorImpBase<T,Alloc>& v ) :
  121.     Data( new(*this)T[v.Lim] ),
  122.     Lim(v.Lim)
  123. {
  124.     PRECONDITION( Lim == 0 || (Data != 0 && v.Data != 0) );
  125.     for( unsigned i = 0; i < Lim; i++ )
  126.         Data[i] = v.Data[i];
  127. }
  128.  
  129. template <class T, class Alloc>
  130. const TVectorImpBase<T,Alloc>& TVectorImpBase<T,Alloc>::operator = ( const TVectorImpBase<T,Alloc>& v )
  131. {
  132.     if( Data != v.Data )
  133.         {
  134.         delete [] Data;
  135.         Data = new(*this)T[v.Lim];
  136.         CHECK( Data != 0 );
  137.         Lim = v.Lim;
  138.         for( unsigned i = 0; i < Lim; i++ )
  139.             Data[i] = v.Data[i];
  140.         }
  141.     return *this;
  142. }
  143.  
  144. inline unsigned NextDelta( unsigned sz, unsigned delta )
  145. {
  146.     return (sz%delta) ? ((sz+delta)/delta)*delta : sz;
  147. }
  148.  
  149. template <class T, class Alloc>
  150. int TVectorImpBase<T,Alloc>::Resize( unsigned newSz, unsigned offset )
  151. {
  152.     if( newSz <= Lim || GetDelta() == 0 )
  153.         return 0;
  154.     unsigned sz = Lim + NextDelta( newSz - Lim, GetDelta() );
  155.     T *temp = new(*this)T[sz];
  156.     unsigned last = min( sz-offset, Lim );
  157.     for( unsigned i = 0; i < last; i++ )
  158.         temp[i+offset] = Data[i];
  159.     delete [] Data;
  160.     Data = temp;
  161.     Lim = sz;
  162.     Zero( last+offset, sz );
  163.     return 1;
  164. }
  165.  
  166. /*------------------------------------------------------------------------*/
  167. /*                                                                        */
  168. /*  template <class T, class Alloc> class TMVectorImp                     */
  169. /*                                                                        */
  170. /*  Implements a managed vector of objects of type T.  Assumes that       */
  171. /*  T has meaningful copy semantics and a default constructor.            */
  172. /*                                                                        */
  173. /*------------------------------------------------------------------------*/
  174.  
  175. template <class T,class Alloc> class TMVectorIteratorImp;
  176.  
  177. template <class T,class Alloc> class TMVectorImp :
  178.     public TVectorImpBase<T,Alloc>
  179. {
  180.  
  181. public:
  182.  
  183.     typedef void (*IterFunc)(T&, void *);
  184.     typedef int  (*CondFunc)(const T&, void *);
  185.  
  186.     friend TMVectorIteratorImp<T,Alloc>;
  187.  
  188.     TMVectorImp() : TVectorImpBase<T,Alloc>() {}
  189.     TMVectorImp( unsigned sz, unsigned d = 0 ) : TVectorImpBase<T,Alloc>(sz,d) {}
  190.  
  191.     T& operator [] ( unsigned index )
  192.         {
  193.         PRECONDITION( Lim == 0 || Data != 0 && index < Lim );
  194.         return Data[index];
  195.         }
  196.  
  197.     T& operator [] ( unsigned index ) const
  198.         {
  199.         PRECONDITION( Lim > 0 && Data != 0 && index < Lim );
  200.         return Data[index];
  201.         }
  202.  
  203.     void Flush( unsigned = UINT_MAX, unsigned = 0 ) {}
  204.  
  205.     void ForEach( IterFunc iter, void *args )
  206.         {
  207.         ForEach( iter, args, 0, Count() );
  208.         }
  209.  
  210.     void ForEach( IterFunc iter, void *args,
  211.                   unsigned start, unsigned stop );
  212.  
  213.     T *FirstThat( CondFunc cond, void *args,
  214.                            unsigned start, unsigned ) const;
  215.  
  216.     T *FirstThat( CondFunc cond, void *args ) const
  217.         {
  218.         return FirstThat( cond, args, 0, Count() );
  219.         }
  220.  
  221.     T *LastThat( CondFunc cond, void *args,
  222.                           unsigned start, unsigned stop ) const;
  223.  
  224.     T *LastThat( CondFunc cond, void *args ) const
  225.         {
  226.         return LastThat( cond, args, 0, Count() );
  227.         }
  228.  
  229. #if defined( BI_OLDNAMES )
  230.     void flush( unsigned = 0, unsigned = UINT_MAX, unsigned = 0 ) {}
  231.     void forEach( IterFunc iter, void *args )
  232.         { ForEach( iter, args ); }
  233.     void forEach( IterFunc iter, void *args,
  234.                   unsigned start, unsigned stop )
  235.         { ForEach( iter, args, start, stop ); }
  236.     T *firstThat( CondFunc cond, void *args,
  237.                            unsigned start, unsigned stop ) const
  238.         { return FirstThat( cond, args, start, stop ); }
  239.     T *firstThat( CondFunc cond, void *args ) const
  240.         { return FirstThat( cond, args ); }
  241.     T *lastThat( CondFunc cond, void *args,
  242.                           unsigned start, unsigned stop ) const
  243.         { return LastThat( cond, args, start, stop ); }
  244.     T *lastThat( CondFunc cond, void *args ) const
  245.         { return LastThat( cond, args ); }
  246. #endif  // BI_OLDNAMES
  247.  
  248. };
  249.  
  250. template <class T, class Alloc>
  251. void TMVectorImp<T,Alloc>::ForEach( IterFunc iter, void *args,
  252.                                     unsigned start, unsigned stop )
  253. {
  254.     for( unsigned cur = start; cur < stop; cur++ )
  255.         iter( Data[cur], args );
  256. }
  257.  
  258. template <class T, class Alloc>
  259. T *TMVectorImp<T,Alloc>::FirstThat( CondFunc cond, void *args,
  260.                                     unsigned start, unsigned stop ) const
  261. {
  262.     for( unsigned cur = start; cur < stop; cur++ )
  263.         if( cond( Data[cur], args ) != 0 )
  264.             return &(T&)Data[cur];
  265.     return 0;
  266. }
  267.  
  268. template <class T, class Alloc>
  269. T *TMVectorImp<T,Alloc>::LastThat( CondFunc cond, void *args,
  270.                                    unsigned start, unsigned stop ) const
  271. {
  272.     T *res = 0;
  273.     for( unsigned cur = start; cur < stop; cur++ )
  274.         if( cond( Data[cur], args ) != 0 )
  275.             res = &(T&)Data[cur];
  276.     return res;
  277. }
  278.  
  279. #if defined( BI_OLDNAMES )
  280. #define BI_MVectorImp TMVectorImp
  281. #endif
  282.  
  283. /*------------------------------------------------------------------------*/
  284. /*                                                                        */
  285. /*  template <class T, class Alloc> class TMVectorIteratorImp             */
  286. /*                                                                        */
  287. /*  Implements a vector iterator.  This iterator works with any direct,   */
  288. /*  managed vector.  For indirect vectors, see TMIVectorIteratorImp.      */
  289. /*                                                                        */
  290. /*------------------------------------------------------------------------*/
  291.  
  292. template <class T, class Alloc> class TMVectorIteratorImp
  293. {
  294.  
  295. public:
  296.  
  297.     TMVectorIteratorImp( const TMVectorImp<T,Alloc>&v )
  298.         {
  299.         Vect = &v;
  300.         Restart(0,v.Top());
  301.         }
  302.  
  303.     TMVectorIteratorImp( const TMVectorImp<T,Alloc>&v,
  304.                          unsigned start,
  305.                          unsigned stop
  306.                          )
  307.         {
  308.         Vect = &v;
  309.         Restart( start, stop );
  310.         }
  311.  
  312.     operator int() const
  313.         {
  314.         return Cur < Upper;
  315.         }
  316.  
  317.     const T& Current() const
  318.         {
  319.         PRECONDITION( Cur < Upper );
  320.         return (*Vect)[Cur];
  321.         }
  322.  
  323.     const T& operator ++ ( int )
  324.         {
  325.         const T& temp = Current();
  326.         Cur++;
  327.         return temp;
  328.         }
  329.  
  330.     const T& operator ++ ()
  331.         {
  332.         PRECONDITION( Cur < Upper );
  333.         Cur++;
  334.         return Current();
  335.         }
  336.  
  337.     void Restart()
  338.         {
  339.         Restart(Lower,Upper);
  340.         }
  341.  
  342.     void Restart( unsigned start, unsigned stop )
  343.         {
  344.         Cur = Lower = start;
  345.         Upper = stop;
  346.         }
  347.  
  348. #if defined( BI_OLDNAMES )
  349.     const T& current() { return Current(); }
  350.     void restart() { Restart(); }
  351.     void restart( unsigned start, unsigned stop ) { Restart( start, stop ); }
  352. #endif  // BI_OLDNAMES
  353.  
  354. private:
  355.  
  356.     const TMVectorImp<T,Alloc> *Vect;
  357.     unsigned Cur;
  358.     unsigned Lower, Upper;
  359.  
  360. };
  361.  
  362. #if defined( BI_OLDNAMES )
  363. #define BI_MVectorIteratorImp TMVectorIteratorImp
  364. #endif
  365.  
  366. /*------------------------------------------------------------------------*/
  367. /*                                                                        */
  368. /*  template <class T> class TVectorImp                                   */
  369. /*  template <class T> class TVectorIteratorImp                           */
  370. /*                                                                        */
  371. /*  Implements a vector of objects of type T using TStandardAllocator as  */
  372. /*  its memory manager. Assumes that T has meaningful copy semantics and  */
  373. /*  a default constructor.                                                */
  374. /*                                                                        */
  375. /*------------------------------------------------------------------------*/
  376.  
  377. template <class T> class TVectorImp :
  378.     public TMVectorImp<T,TStandardAllocator>
  379. {
  380.  
  381. public:
  382.  
  383.     TVectorImp()
  384.         {
  385.         }
  386.  
  387.     TVectorImp( unsigned sz, unsigned = 0 ) :
  388.         TMVectorImp<T,TStandardAllocator>( sz )
  389.         {
  390.         }
  391.  
  392.     TVectorImp( const TVectorImp<T>& v ) :
  393.         TMVectorImp<T,TStandardAllocator>( v )
  394.         {
  395.         }
  396.  
  397. };
  398.  
  399. template <class T> class TVectorIteratorImp :
  400.     public TMVectorIteratorImp<T,TStandardAllocator>
  401. {
  402.  
  403. public:
  404.  
  405.     TVectorIteratorImp( const TVectorImp<T>& v ) :
  406.         TMVectorIteratorImp<T,TStandardAllocator>(v)
  407.         {
  408.         }
  409.  
  410.     TVectorIteratorImp( const TVectorImp<T>& v,
  411.                         unsigned start,
  412.                         unsigned stop
  413.                         ) :
  414.         TMVectorIteratorImp<T,TStandardAllocator>(v,start,stop)
  415.         {
  416.         }
  417.  
  418. };
  419.  
  420. #if defined( BI_OLDNAMES )
  421. #define BI_VectorImp TVectorImp
  422. #define BI_VectorIteratorImp TVectorIteratorImp
  423. #endif
  424.  
  425. /*------------------------------------------------------------------------*/
  426. /*                                                                        */
  427. /*  template <class T, class Alloc> class TMCVectorImp                    */
  428. /*  template <class T, class Alloc> class TMCVectorIteratorImp            */
  429. /*                                                                        */
  430. /*  Implements a managed, counted vector of objects of type T.  Assumes   */
  431. /*  that T has meaningful copy semantics and a default constructor.       */
  432. /*                                                                        */
  433. /*------------------------------------------------------------------------*/
  434.  
  435. template <class T, class Alloc> class TMCVectorImp :
  436.     public TMVectorImp<T,Alloc>
  437. {
  438.  
  439. public:
  440.  
  441.     TMCVectorImp() :
  442.         Count_(0),
  443.         Delta(0)
  444.         {
  445.         }
  446.  
  447.     TMCVectorImp( unsigned sz, unsigned d = 0 ) :
  448.         TMVectorImp<T,Alloc>( sz ),
  449.         Count_(0),
  450.         Delta(d)
  451.         {
  452.         }
  453.  
  454.     int Add( const T& );
  455.     int AddAt( const T&, unsigned );
  456.     int Detach( const T& t )
  457.         {
  458.         return Detach( Find(t) );
  459.         }
  460.  
  461.     int Detach( unsigned loc );
  462.  
  463.     int IsEmpty() const
  464.         {
  465.         return Count_ == 0;
  466.         }
  467.  
  468.     void Flush( unsigned stop = UINT_MAX,
  469.                 unsigned start = 0 )
  470.         {
  471.         TMVectorImp<T,Alloc>::Flush( stop, start );
  472.         Count_ = 0;
  473.         }
  474.  
  475.     virtual unsigned Find( const T& ) const;
  476.  
  477.     virtual unsigned Top() const
  478.         {
  479.         return Count_;
  480.         }
  481.  
  482.     virtual unsigned Count() const
  483.         {
  484.         return Count_;
  485.         }
  486.  
  487.     virtual unsigned GetDelta() const
  488.         {
  489.         return Delta;
  490.         }
  491.  
  492. #if defined( BI_OLDNAMES )
  493.     void add( const T& t ) { Add(t); }
  494.     void addAt( const T& t, unsigned loc ) { AddAt( t, loc ); }
  495.     void detach( const T& t, int del = 0 ) { Detach( t ); }
  496.     void detach( unsigned loc, int del = 0 ) { Detach( loc ); }
  497.     int isEmpty() const { return IsEmpty(); }
  498.     void flush( unsigned del = 0,
  499.                 unsigned stop = UINT_MAX,
  500.                 unsigned start = 0 )
  501.         { Flush( stop, start ); }
  502.     unsigned count() const { return Count(); }
  503. #endif  // BI_OLDNAMES
  504.  
  505. protected:
  506.  
  507.     unsigned Count_;
  508.     unsigned Delta;
  509.  
  510. };
  511.  
  512. template <class T,class Alloc> class TMCVectorIteratorImp :
  513.     public TMVectorIteratorImp<T,Alloc>
  514. {
  515.  
  516. public:
  517.  
  518.     TMCVectorIteratorImp( const TMCVectorImp<T,Alloc>& v ) :
  519.         TMVectorIteratorImp<T,Alloc>(v)
  520.         {
  521.         }
  522.  
  523.     TMCVectorIteratorImp( const TMCVectorImp<T,Alloc>& v,
  524.                           unsigned start,
  525.                           unsigned stop
  526.                         ) :
  527.         TMVectorIteratorImp<T,Alloc>(v,start,stop)
  528.         {
  529.         }
  530.  
  531. };
  532.  
  533. template <class T, class Alloc> int TMCVectorImp<T,Alloc>::Add( const T& t )
  534. {
  535.     if( Count_ >= Lim && !Resize( Count_+1 ) )
  536.         return 0;
  537.     Data[Count_++] = t;
  538.     return 1;
  539. }
  540.  
  541. template <class T, class Alloc> 
  542. int TMCVectorImp<T,Alloc>::AddAt( const T& t, unsigned loc )
  543. {
  544.     if( loc >= Lim && !Resize(loc+1) )
  545.         return 0;
  546.     if( Count_ == Lim && !Resize(Lim+1) )
  547.         return 0;
  548.     if( loc > Count_ )
  549.         Count_ = loc;
  550.     for( unsigned cur = Count_; cur > loc; cur-- )
  551.         Data[cur] = Data[cur-1];
  552.     Data[loc] = t;
  553.     Count_++;
  554.     return 1;
  555. }
  556.  
  557. template <class T, class Alloc>
  558. int TMCVectorImp<T,Alloc>::Detach( unsigned loc )
  559. {
  560.     if( loc >= Lim )
  561.         return 0;
  562.     if( loc >= Count_ )
  563.         {
  564.         Zero( loc, loc+1 ); // removing an element that's not
  565.         return 1;           // in the counted portion
  566.         }
  567.     Count_--;
  568.     for( unsigned cur = loc; cur < Count_; cur++ )
  569.         Data[cur] = Data[cur+1];
  570.     return 1;
  571. }
  572.  
  573. template <class T, class Alloc>
  574. unsigned TMCVectorImp<T,Alloc>::Find( const T& t ) const
  575. {
  576.     for( unsigned loc = 0; loc < Count_; loc++ )
  577.         if( Data[loc] == t )
  578.             return loc;
  579.     return UINT_MAX;
  580. }
  581.  
  582. #if defined( BI_OLDNAMES )
  583. #define BI_MCVectorImp TMCVectorImp
  584. #endif
  585.  
  586. /*------------------------------------------------------------------------*/
  587. /*                                                                        */
  588. /*  template <class T> class TCVectorImp                                  */
  589. /*  template <class T> class TCVectorIteratorImp                          */
  590. /*                                                                        */
  591. /*  Implements a counted vector of objects of type T using                */
  592. /*  TStandardAllocator as its memory manager.  Assumes                    */
  593. /*  that T has meaningful copy semantics and a default constructor.       */
  594. /*                                                                        */
  595. /*------------------------------------------------------------------------*/
  596.  
  597. template <class T> class TCVectorImp :
  598.     public TMCVectorImp<T,TStandardAllocator>
  599. {
  600.  
  601. public:
  602.  
  603.     TCVectorImp()
  604.         {
  605.         }
  606.  
  607.     TCVectorImp( unsigned sz, unsigned d = 0 ) :
  608.         TMCVectorImp<T,TStandardAllocator>( sz, d )
  609.         {
  610.         }
  611.  
  612. };
  613.  
  614. template <class T> class TCVectorIteratorImp :
  615.     public TMCVectorIteratorImp<T,TStandardAllocator>
  616. {
  617.  
  618. public:
  619.  
  620.     TCVectorIteratorImp( const TCVectorImp<T>& v ) :
  621.         TMCVectorIteratorImp<T,TStandardAllocator>(v)
  622.         {
  623.         }
  624.  
  625.     TCVectorIteratorImp( const TCVectorImp<T>& v,
  626.                          unsigned start,
  627.                          unsigned stop
  628.                         ) :
  629.         TMCVectorIteratorImp<T,TStandardAllocator>(v,start,stop)
  630.         {
  631.         }
  632.  
  633. };
  634.  
  635. #if defined( BI_OLDNAMES )
  636. #define BI_CVectorImp TCVectorImp
  637. #endif
  638.  
  639. /*------------------------------------------------------------------------*/
  640. /*                                                                        */
  641. /*  template <class T, class Alloc> class TMSVectorImp                    */
  642. /*  template <class T, class Alloc> class TMSVectorIteratorImp            */
  643. /*                                                                        */
  644. /*  Implements a managed, sorted vector of objects of type T.  Assumes    */
  645. /*  that T has meaningful copy semantics, a meaningful < operator,        */
  646. /*  and a default constructor.                                            */
  647. /*                                                                        */
  648. /*------------------------------------------------------------------------*/
  649.  
  650. template <class T, class Alloc> class TMSVectorImp :
  651.     public TMCVectorImp<T,Alloc>
  652. {
  653.  
  654. public:
  655.  
  656.     TMSVectorImp()
  657.         {
  658.         }
  659.  
  660.     TMSVectorImp( unsigned sz, unsigned d = 0 ) :
  661.         TMCVectorImp<T,Alloc>( sz, d )
  662.         {
  663.         }
  664.  
  665.     int Add( const T& );
  666.  
  667.     virtual unsigned Find( const T& ) const;
  668.  
  669. };
  670.  
  671. template <class T,class Alloc> class TMSVectorIteratorImp :
  672.     public TMCVectorIteratorImp<T,Alloc>
  673. {
  674.  
  675. public:
  676.  
  677.     TMSVectorIteratorImp( const TMSVectorImp<T,Alloc>& v ) :
  678.         TMCVectorIteratorImp<T,Alloc>(v)
  679.         {
  680.         }
  681.  
  682.     TMSVectorIteratorImp( const TMSVectorImp<T,Alloc>& v,
  683.                           unsigned start,
  684.                           unsigned stop
  685.                         ) :
  686.         TMCVectorIteratorImp<T,Alloc>(v,start,stop)
  687.         {
  688.         }
  689.  
  690. };
  691.  
  692. template <class T, class Alloc> int TMSVectorImp<T,Alloc>::Add( const T& t )
  693. {
  694.     unsigned loc = Count_++;
  695.     if( Count_ > Lim )
  696.         if( !Resize( Count_ ) )
  697.             {
  698.             --Count_;
  699.             return 0;
  700.             }
  701.     while( loc > 0 && t < Data[loc-1] )
  702.         {
  703.         Data[loc] = Data[loc-1];
  704.         loc--;
  705.         }
  706.     Data[loc] = t;
  707.     return 1;
  708. }
  709.  
  710. template <class T, class Alloc>
  711. unsigned TMSVectorImp<T,Alloc>::Find( const T& t ) const
  712. {
  713.     if( Count_ == 0 )
  714.         return UINT_MAX;
  715.  
  716.     unsigned lower = 0;
  717.     unsigned upper = Count_-1;
  718.  
  719.     while( lower < upper && upper != UINT_MAX )
  720.         {
  721.         unsigned middle = (lower+upper)/2;
  722.         if( (T&)Data[middle] == (T&)t )
  723.             return middle;
  724.         if( (T&)Data[middle] < (T&)t )
  725.             lower = middle+1;
  726.         else
  727.             upper = middle-1;
  728.         }
  729.  
  730.     if( lower == upper && (T&)Data[lower] == (T&)t )
  731.         return lower;
  732.     else
  733.         return UINT_MAX;
  734. }
  735.  
  736. #if defined( BI_OLDNAMES )
  737. #define BI_MSVectorImp TMSVectorImp
  738. #define BI_MSVectorIteratorImp TMSVectorIteratorImp
  739. #endif
  740.  
  741. /*------------------------------------------------------------------------*/
  742. /*                                                                        */
  743. /*  template <class T> class TSVectorImp                                  */
  744. /*  template <class T> class TSVectorIteratorImp                          */
  745. /*                                                                        */
  746. /*  Implements a sorted vector of objects of type T using                 */
  747. /*  TStandardAllocator as its memory manager.  Assumes                    */
  748. /*  that T has meaningful copy semantics, a meaningful < operator,        */
  749. /*  and a default constructor.                                            */
  750. /*                                                                        */
  751. /*------------------------------------------------------------------------*/
  752.  
  753. template <class T> class TSVectorImp :
  754.     public TMSVectorImp<T,TStandardAllocator>
  755. {
  756.  
  757. public:
  758.  
  759.     TSVectorImp()
  760.         {
  761.         }
  762.  
  763.     TSVectorImp( unsigned sz, unsigned d = 0 ) :
  764.         TMSVectorImp<T,TStandardAllocator>( sz, d )
  765.         {
  766.         }
  767.  
  768. };
  769.  
  770. template <class T> class TSVectorIteratorImp :
  771.     public TMSVectorIteratorImp<T,TStandardAllocator>
  772. {
  773.  
  774. public:
  775.  
  776.     TSVectorIteratorImp( const TSVectorImp<T>& v ) :
  777.         TMSVectorIteratorImp<T,TStandardAllocator>(v)
  778.         {
  779.         }
  780.  
  781.     TSVectorIteratorImp( const TSVectorImp<T>& v,
  782.                          unsigned start,
  783.                          unsigned stop
  784.                         ) :
  785.         TMSVectorIteratorImp<T,TStandardAllocator>(v,start,stop)
  786.         {
  787.         }
  788.  
  789. };
  790.  
  791. #if defined( BI_OLDNAMES )
  792. #define BI_SVectorImp TSVectorImp
  793. #define BI_SVectorIteratorImp TSVectorIteratorImp
  794. #endif
  795.  
  796. /*------------------------------------------------------------------------*/
  797. /*                                                                        */
  798. /*  template <class T,class Alloc> class TMIVectorImp                     */
  799. /*                                                                        */
  800. /*  Implements a managed vector of pointers to objects of type T.         */
  801. /*  Since pointers always have meaningful copy semantics, this class      */
  802. /*  can handle any type of object.                                        */
  803. /*                                                                        */
  804. /*------------------------------------------------------------------------*/
  805.  
  806. template <class T,class Alloc> class TMIVectorImp :
  807.     public TVectorImpBase<TVoidPointer,Alloc>
  808. {
  809.  
  810. public:
  811.  
  812.     typedef void (*IterFunc)(T&, void *);
  813.     typedef int  (*CondFunc)(const T&, void *);
  814.  
  815.     TMIVectorImp( unsigned sz, unsigned d = 0 ) :
  816.         TVectorImpBase<TVoidPointer,Alloc>(sz,d) {}
  817.  
  818.     T *& operator [] ( unsigned index )
  819.         {
  820.         PRECONDITION( Lim == 0 || Data != 0 && index < Lim );
  821.         return *STATIC_CAST(T **,STATIC_CAST(void *,&Data[index]));
  822.         }
  823.  
  824.     T *& operator [] ( unsigned index ) const
  825.         {
  826.         PRECONDITION( Lim > 0 && Data != 0 && index < Lim );
  827.         return *STATIC_CAST(T **,STATIC_CAST(void *,&Data[index]));
  828.         }
  829.  
  830.     void Flush( unsigned del = 0,
  831.                 unsigned stop = UINT_MAX,
  832.                 unsigned start = 0 );
  833.  
  834.     void ForEach( IterFunc iter, void *args )
  835.         {
  836.         ForEach( iter, args, 0, Count() );
  837.         }
  838.  
  839.     void ForEach( IterFunc iter, void *args,
  840.                   unsigned start, unsigned stop );
  841.  
  842.     T *FirstThat( CondFunc cond, void *args ) const
  843.         {
  844.         return FirstThat( cond, args, 0, Count() );
  845.         }
  846.  
  847.     T *FirstThat( CondFunc cond, void *args,
  848.                            unsigned start, unsigned stop ) const;
  849.  
  850.     T *LastThat( CondFunc cond, void *args ) const
  851.         {
  852.         return LastThat( cond, args, 0, Count() );
  853.         }
  854.  
  855.     T *LastThat( CondFunc cond, void *args,
  856.                           unsigned start, unsigned stop ) const;
  857.  
  858. #if defined( BI_OLDNAMES )
  859.     void flush( unsigned del = 0, unsigned upr = UINT_MAX, unsigned lwr = 0 )
  860.         { Flush( del, upr, lwr ); }
  861.     void forEach( IterFunc iter, void *args )
  862.         { ForEach( iter, args ); }
  863.     void forEach( IterFunc cond, void *args,
  864.                   unsigned start, unsigned stop)
  865.         { ForEach( cond, args, start, stop ); }
  866.     T *firstThat( CondFunc cond, void *args ) const
  867.         { return FirstThat( cond, args ); }
  868.     T *firstThat( CondFunc cond, void *args,
  869.                            unsigned start, unsigned stop ) const
  870.         { return FirstThat( cond, args, start, stop ); }
  871.     T *lastThat( CondFunc cond, void *args ) const
  872.         { return LastThat( cond, args ); }
  873.     T *lastThat( CondFunc cond, void *args,
  874.                           unsigned start, unsigned stop ) const
  875.         { return LastThat( cond, args, start, stop ); }
  876. #endif  // BI_OLDNAMES
  877.  
  878. protected:
  879.  
  880.     void Zero( unsigned, unsigned );
  881.  
  882. private:
  883.  
  884.     static void DelObj( T&, void * );
  885.  
  886. };
  887.  
  888. template <class T, class Alloc>
  889. void TMIVectorImp<T,Alloc>::DelObj( T& tRef, void * )
  890. {
  891.     delete &tRef;
  892. }
  893.  
  894. template <class T, class Alloc>
  895. void TMIVectorImp<T,Alloc>::Flush( unsigned del,
  896.                                    unsigned upr,
  897.                                    unsigned lwr )
  898. {
  899.     upr = min( upr, Limit() );
  900.     if( del )
  901.         ForEach( DelObj, 0, lwr, upr );
  902.     Zero( lwr, upr );
  903. }
  904.  
  905. template <class T, class Alloc>
  906. void TMIVectorImp<T,Alloc>::ForEach( IterFunc iter, void *args,
  907.                                     unsigned start, unsigned stop )
  908. {
  909.     for( unsigned cur = start; cur < stop; cur++ )
  910.         if( Data[cur] != 0 )
  911.             iter( *STATIC_CAST(T *,STATIC_CAST(void *,Data[cur])), args );
  912. }
  913.  
  914. template <class T, class Alloc>
  915. T *TMIVectorImp<T,Alloc>::FirstThat( CondFunc cond,
  916.                                      void *args,
  917.                                      unsigned start,
  918.                                      unsigned stop ) const
  919. {
  920.     for( unsigned cur = start; cur < stop; cur++ )
  921.         if( Data[cur] != 0 &&
  922.             cond( *STATIC_CAST(T *,STATIC_CAST(void *,Data[cur])), args ) != 0 )
  923.             return STATIC_CAST(T *,STATIC_CAST(void *,Data[cur]));
  924.     return 0;
  925. }
  926.  
  927. template <class T, class Alloc>
  928. T *TMIVectorImp<T,Alloc>::LastThat( CondFunc cond,
  929.                                     void *args,
  930.                                     unsigned start,
  931.                                     unsigned stop ) const
  932. {
  933.     T *res = 0;
  934.     for( unsigned cur = start; cur < stop; cur++ )
  935.         if( Data[cur] != 0 &&
  936.             cond( *STATIC_CAST(T *,STATIC_CAST(void *,Data[cur])), args ) != 0 )
  937.             res = STATIC_CAST(T *,STATIC_CAST(void *,Data[cur]));
  938.     return res;
  939. }
  940.  
  941. template <class T, class Alloc>
  942. void TMIVectorImp<T,Alloc>::Zero( unsigned lwr, unsigned upr )
  943. {
  944.     for( unsigned i = lwr; i < min( Limit(), upr ); i++ )
  945.         Data[i] = 0;
  946. }
  947.  
  948. #if defined( BI_OLDNAMES )
  949. #define BI_MIVectorImp TMIVectorImp
  950. #endif
  951.  
  952. /*------------------------------------------------------------------------*/
  953. /*                                                                        */
  954. /*  template <class T,class Alloc> class TMIVectorIteratorImp             */
  955. /*                                                                        */
  956. /*  Implements an iterator for a managed indirect vector of pointers to   */
  957. /*  objects of type T.                                                    */
  958. /*                                                                        */
  959. /*------------------------------------------------------------------------*/
  960.  
  961. template <class T, class Alloc> class TMIVectorIteratorImp
  962. {
  963.  
  964. public:
  965.  
  966.     TMIVectorIteratorImp( const TMIVectorImp<T,Alloc>& v )
  967.         {
  968.         Vect = &v;
  969.         Restart(0,v.Top());
  970.         }
  971.  
  972.     TMIVectorIteratorImp( const TMIVectorImp<T,Alloc>& v,
  973.                           unsigned start,
  974.                           unsigned stop )
  975.         {
  976.         Vect = &v;
  977.         Restart( start, stop );
  978.         }
  979.  
  980.     operator int() const
  981.         {
  982.         return Cur < Upper;
  983.         }
  984.  
  985.     T *Current() const
  986.         {
  987.         PRECONDITION( Cur < Upper );
  988.         return STATIC_CAST(T *,STATIC_CAST(void *,(*Vect)[Cur]));
  989.         }
  990.  
  991.     T *operator ++ ( int )
  992.         {
  993.         T *temp = Current();
  994.         Cur++;
  995.         return temp;
  996.         }
  997.  
  998.     T *operator ++ ()
  999.         {
  1000.         PRECONDITION( Cur < Upper );
  1001.         Cur++;
  1002.         return Current();
  1003.         }
  1004.  
  1005.     void Restart()
  1006.         {
  1007.         Restart(Lower,Upper);
  1008.         }
  1009.  
  1010.     void Restart( unsigned start, unsigned stop )
  1011.         {
  1012.         Cur = Lower = start;
  1013.         Upper = stop;
  1014.         }
  1015.  
  1016. #if defined( BI_OLDNAMES )
  1017.     const T *current() { return Current(); }
  1018.     void restart() { Restart(); }
  1019.     void restart( unsigned start, unsigned stop ) { Restart( start, stop ); }
  1020. #endif  // BI_OLDNAMES
  1021.  
  1022. private:
  1023.  
  1024.     const TMIVectorImp<T,Alloc> *Vect;
  1025.     unsigned Cur;
  1026.     unsigned Lower, Upper;
  1027.  
  1028. };
  1029.  
  1030. #if defined( BI_OLDNAMES )
  1031. #define BI_MIVectorIteratorImp TMIVectorIteratorImp
  1032. #endif
  1033.  
  1034. /*------------------------------------------------------------------------*/
  1035. /*                                                                        */
  1036. /*  template <class T> class TIVectorImp                                  */
  1037. /*  template <class T> class TIVectorIteratorImp                          */
  1038. /*                                                                        */
  1039. /*  Implements a vector of pointers to objects of type T using            */
  1040. /*  TStandardAllocator as its memory manager.                             */
  1041. /*  Since pointers always have meaningful copy semantics, this class      */
  1042. /*  can handle any type of object.                                        */
  1043. /*                                                                        */
  1044. /*------------------------------------------------------------------------*/
  1045.  
  1046. template <class T> class TIVectorImp :
  1047.     public TMIVectorImp<T,TStandardAllocator>
  1048. {
  1049.  
  1050. public:
  1051.  
  1052.     TIVectorImp( unsigned sz, unsigned d = 0 ) :
  1053.         TMIVectorImp<T,TStandardAllocator>(sz,d)
  1054.         {
  1055.         }
  1056.  
  1057. };
  1058.  
  1059. template <class T> class TIVectorIteratorImp :
  1060.     public TMIVectorIteratorImp<T,TStandardAllocator>
  1061. {
  1062.  
  1063. public:
  1064.  
  1065.     TIVectorIteratorImp( const TIVectorImp<T>& v ) :
  1066.         TMIVectorIteratorImp<T,TStandardAllocator>(v)
  1067.         {
  1068.         }
  1069.  
  1070.     TIVectorIteratorImp( const TIVectorImp<T>& v,
  1071.                          unsigned l, unsigned u ) :
  1072.         TMIVectorIteratorImp<T,TStandardAllocator>(v,l,u)
  1073.         {
  1074.         }
  1075.  
  1076. };
  1077.  
  1078. #if defined( BI_OLDNAMES )
  1079. #define BI_IVectorImp TIVectorImp
  1080. #define BI_IVectorIteratorImp TIVectorIteratorImp
  1081. #endif
  1082.  
  1083. /*------------------------------------------------------------------------*/
  1084. /*                                                                        */
  1085. /*  template <class T,class Alloc> class TMICVectorImp                    */
  1086. /*  template <class T,class Alloc> class TMICVectorIteratorImp            */
  1087. /*                                                                        */
  1088. /*  Implements a managed, counted vector of pointers to objects of type T.*/
  1089. /*  Since pointers always have meaningful copy semantics, this class      */
  1090. /*  can handle any type of object.                                        */
  1091. /*                                                                        */
  1092. /*------------------------------------------------------------------------*/
  1093.  
  1094. template <class T,class Alloc> class TMICVectorImp :
  1095.     public TMIVectorImp<T,Alloc>
  1096. {
  1097.  
  1098. public:
  1099.  
  1100.     TMICVectorImp( unsigned sz, unsigned d = 0 ) :
  1101.         TMIVectorImp<T,Alloc>(sz), Delta(d), Count_(0) {}
  1102.  
  1103.     int Add( T *t );
  1104.     int AddAt( T *, unsigned );
  1105.     int Detach( const T *t, int del = 0 )
  1106.         {
  1107.         return Detach( Find(t), del );
  1108.         }
  1109.  
  1110.     int Detach( unsigned loc, int del = 0 );
  1111.  
  1112.     int IsEmpty() const
  1113.         {
  1114.         return Count_ == 0;
  1115.         }
  1116.  
  1117.     void Flush( int del = 0,
  1118.                 unsigned stop = UINT_MAX,
  1119.                 unsigned start = 0 )
  1120.         {
  1121.         TMIVectorImp<T,Alloc>::Flush( del, stop, start );
  1122.         Count_ = 0;
  1123.         }
  1124.  
  1125.     unsigned Find( const T *t ) const;
  1126.  
  1127.     virtual unsigned Top() const
  1128.         {
  1129.         return Count_;
  1130.         }
  1131.  
  1132.     virtual unsigned Count() const
  1133.         {
  1134.         return Count_;
  1135.         }
  1136.  
  1137.     virtual unsigned GetDelta() const
  1138.         {
  1139.         return Delta;
  1140.         }
  1141.  
  1142. #if defined( BI_OLDNAMES )
  1143.     unsigned find( T *t ) const { return Find(t); }
  1144.     void add( T *t ) { Add(t); }
  1145. #endif  // BI_OLDNAMES
  1146.  
  1147. protected:
  1148.  
  1149.     unsigned Count_;
  1150.     unsigned Delta;
  1151.  
  1152. };
  1153.  
  1154. template <class T,class Alloc> class TMICVectorIteratorImp :
  1155.     public TMIVectorIteratorImp<T,Alloc>
  1156. {
  1157.  
  1158. public:
  1159.  
  1160.     TMICVectorIteratorImp( const TMICVectorImp<T,Alloc>& v ) :
  1161.         TMIVectorIteratorImp<T,Alloc>(v)
  1162.         {
  1163.         }
  1164.  
  1165.     TMICVectorIteratorImp( const TMICVectorImp<T,Alloc>& v,
  1166.                            unsigned start,
  1167.                            unsigned stop ) :
  1168.         TMIVectorIteratorImp<T,Alloc>(v,start,stop)
  1169.         {
  1170.         }
  1171.  
  1172. };
  1173.  
  1174. template <class T, class Alloc> 
  1175. int TMICVectorImp<T,Alloc>::AddAt( T *t, unsigned loc )
  1176. {
  1177.     if( loc >= Lim && !Resize(loc+1) )
  1178.         return 0;
  1179.     if( Count_ == Lim && !Resize(Lim+1) )
  1180.         return 0;
  1181.     if( loc > Count_ )
  1182.         Count_ = loc;
  1183.     for( unsigned cur = Count_; cur > loc; cur-- )
  1184.         Data[cur] = Data[cur-1];
  1185.     Data[loc] = t;
  1186.     Count_++;
  1187.     return 1;
  1188. }
  1189.  
  1190. template <class T, class Alloc>
  1191. int TMICVectorImp<T,Alloc>::Detach( unsigned loc, int del )
  1192. {
  1193.     if( loc >= Lim )
  1194.         return 0;
  1195.     if( del )
  1196.         delete STATIC_CAST(T *,STATIC_CAST(void *,Data[loc]));
  1197.     if( loc >= Count_ )
  1198.         {
  1199.         Zero( loc, loc+1 ); // removing an element that's not
  1200.         return 1;           // in the counted portion
  1201.         }
  1202.     Count_--;
  1203.     for( unsigned cur = loc; cur < Count_; cur++ )
  1204.         Data[cur] = Data[cur+1];
  1205.     Zero( Count_, Count_+1 );
  1206.     return 1;
  1207. }
  1208.  
  1209. template <class T,class Alloc>
  1210. unsigned TMICVectorImp<T,Alloc>::Find( const T *t ) const
  1211. {
  1212.     if( Top() != 0 )
  1213.         {
  1214.         for( unsigned loc = 0; loc < Top(); loc++ )
  1215.             if( Data[loc] &&
  1216.               *STATIC_CAST(T *,STATIC_CAST(void *,Data[loc])) == *t )
  1217.                 return loc;
  1218.         }
  1219.     return UINT_MAX;
  1220. }
  1221.  
  1222. template <class T,class Alloc> int TMICVectorImp<T,Alloc>::Add( T *t )
  1223. {
  1224.     while( Count_ < Limit() && (*this)[Count_] != 0 )
  1225.         Count_++;
  1226.     if( Count_ >= Lim && !Resize( Count_+1 ) )
  1227.         return 0;
  1228.     Data[Count_++] = t;
  1229.     return 1;
  1230. }
  1231.  
  1232. #if defined( BI_OLDNAMES )
  1233. #define BI_MICVectorImp TMICVectorImp
  1234. #define BI_MICVectorIteratorImp TMICVectorIteratorImp
  1235. #endif
  1236.  
  1237. /*------------------------------------------------------------------------*/
  1238. /*                                                                        */
  1239. /*  template <class T> class TICVectorImp                                 */
  1240. /*  template <class T> class TICVectorIteratorImp                         */
  1241. /*                                                                        */
  1242. /*  Implements a counted vector of pointers to objects of type T using    */
  1243. /*  TStandardAllocator as its memory manager.                             */
  1244. /*  Since pointers always have meaningful copy semantics, this class      */
  1245. /*  can handle any type of object.                                        */
  1246. /*                                                                        */
  1247. /*------------------------------------------------------------------------*/
  1248.  
  1249. template <class T> class TICVectorImp :
  1250.     public TMICVectorImp<T,TStandardAllocator>
  1251. {
  1252.  
  1253. public:
  1254.  
  1255.     TICVectorImp( unsigned sz, unsigned d = 0 ) :
  1256.         TMICVectorImp<T,TStandardAllocator>( sz, d )
  1257.         {
  1258.         }
  1259.  
  1260. };
  1261.  
  1262. template <class T> class TICVectorIteratorImp :
  1263.     public TMICVectorIteratorImp<T,TStandardAllocator>
  1264. {
  1265.  
  1266. public:
  1267.  
  1268.     TICVectorIteratorImp( const TICVectorImp<T>& v ) :
  1269.         TMICVectorIteratorImp<T,TStandardAllocator>(v)
  1270.         {
  1271.         }
  1272.  
  1273.     TICVectorIteratorImp( const TICVectorImp<T>& v,
  1274.                           unsigned l, unsigned u ) :
  1275.         TMICVectorIteratorImp<T,TStandardAllocator>(v,l,u)
  1276.         {
  1277.         }
  1278.  
  1279. };
  1280.  
  1281. #if defined( BI_OLDNAMES )
  1282. #define BI_ICVectorImp TICVectorImp
  1283. #define BI_ICVectorVectorImp TICVectorIteratorImp
  1284. #endif
  1285.  
  1286. /*------------------------------------------------------------------------*/
  1287. /*                                                                        */
  1288. /*  template <class T,class Alloc> class TMISVectorImp                    */
  1289. /*  template <class T,class Alloc> class TMISVectorIteratorImp            */
  1290. /*                                                                        */
  1291. /*  Implements a managed, sorted vector of pointers to objects of type T. */
  1292. /*  This is implemented through the template TInternalIVectorImp.         */
  1293. /*  Since pointers always have meaningful copy semantics, this class      */
  1294. /*  can handle any type of object.                                        */
  1295. /*                                                                        */
  1296. /*------------------------------------------------------------------------*/
  1297.  
  1298. template <class T,class Alloc> class TMISVectorImp :
  1299.     public TMICVectorImp<T,Alloc>
  1300. {
  1301.  
  1302. public:
  1303.  
  1304.     TMISVectorImp( unsigned sz, unsigned d = 0 ) :
  1305.         TMICVectorImp<T,Alloc>(sz)
  1306.         {
  1307.         Delta = d;
  1308.         }
  1309.  
  1310.     unsigned Find( const T *t ) const;
  1311.     int Add( T *t );
  1312.  
  1313. #if defined( BI_OLDNAMES )
  1314.     unsigned find( T *t ) const { return Find(t); }
  1315.     void add( T *t ) { Add(t); }
  1316. #endif  // BI_OLDNAMES
  1317.  
  1318. };
  1319.  
  1320. template <class T,class Alloc> class TMISVectorIteratorImp :
  1321.     public TMICVectorIteratorImp<T,Alloc>
  1322. {
  1323.  
  1324. public:
  1325.  
  1326.     TMISVectorIteratorImp( const TMISVectorImp<T,Alloc>& v ) :
  1327.         TMICVectorIteratorImp<T,Alloc>(v)
  1328.         {
  1329.         }
  1330.  
  1331.     TMISVectorIteratorImp( const TMISVectorImp<T,Alloc>& v,
  1332.                            unsigned start,
  1333.                            unsigned stop ) :
  1334.         TMICVectorIteratorImp<T,Alloc>(v,start,stop)
  1335.         {
  1336.         }
  1337.  
  1338. };
  1339.  
  1340. template <class T,class Alloc>
  1341. unsigned TMISVectorImp<T,Alloc>::Find( const T *t ) const
  1342. {
  1343.     if( Count_ == 0 )
  1344.         return UINT_MAX;
  1345.  
  1346.     unsigned lower = 0;
  1347.     unsigned upper = Count_-1;
  1348.  
  1349.     while( lower < upper && upper != UINT_MAX )
  1350.         {
  1351.         unsigned middle = (lower+upper)/2;
  1352.         if( *STATIC_CAST(T *,STATIC_CAST(void *,Data[middle])) == *t )
  1353.             return middle;
  1354.         if( *STATIC_CAST(T *,STATIC_CAST(void *,Data[middle])) < *t )
  1355.             lower = middle+1;
  1356.         else
  1357.             upper = middle-1;
  1358.         }
  1359.  
  1360.     if( lower == upper &&
  1361.         *STATIC_CAST(T *,STATIC_CAST(void *,Data[lower])) == *t )
  1362.         return lower;
  1363.     else
  1364.         return UINT_MAX;
  1365. }
  1366.  
  1367. template <class T,class Alloc> int TMISVectorImp<T,Alloc>::Add( T *t )
  1368. {
  1369.     unsigned loc = Count_++;
  1370.     if( Count_ > Lim )
  1371.         if( !Resize( Count_ ) )
  1372.             {
  1373.             --Count_;
  1374.             return 0;
  1375.             }
  1376.     while( loc > 0 &&
  1377.            *t < *STATIC_CAST(T *,STATIC_CAST(void *,(*this)[loc-1])) )
  1378.         {
  1379.         Data[loc] = Data[loc-1];
  1380.         loc--;
  1381.         }
  1382.     Data[loc] = t;
  1383.     return 1;
  1384. }
  1385.  
  1386. #if defined( BI_OLDNAMES )
  1387. #define BI_MISVectorImp TMISVectorImp
  1388. #define BI_MISVectorVectorImp TMISVectorIteratorImp
  1389. #endif
  1390.  
  1391. /*------------------------------------------------------------------------*/
  1392. /*                                                                        */
  1393. /*  template <class T> class TISVectorImp                                 */
  1394. /*  template <class T> class TISVectorIteratorImp                         */
  1395. /*                                                                        */
  1396. /*  Implements a sorted vector of pointers to objects of type T using     */
  1397. /*  TStandardAllocator as its memory manager.                             */
  1398. /*  This is implemented through the template TInternalIVectorImp.         */
  1399. /*  Since pointers always have meaningful copy semantics, this class      */
  1400. /*  can handle any type of object.                                        */
  1401. /*                                                                        */
  1402. /*------------------------------------------------------------------------*/
  1403.  
  1404. template <class T> class TISVectorImp :
  1405.     public TMISVectorImp<T,TStandardAllocator>
  1406. {
  1407.  
  1408. public:
  1409.  
  1410.     TISVectorImp( unsigned sz, unsigned d = 0 ) :
  1411.         TMISVectorImp<T,TStandardAllocator>( sz, d )
  1412.         {
  1413.         }
  1414.  
  1415. };
  1416.  
  1417. template <class T> class TISVectorIteratorImp :
  1418.     public TMISVectorIteratorImp<T,TStandardAllocator>
  1419. {
  1420.  
  1421. public:
  1422.  
  1423.     TISVectorIteratorImp( const TISVectorImp<T>& v ) :
  1424.         TMISVectorIteratorImp<T,TStandardAllocator>(v)
  1425.         {
  1426.         }
  1427.  
  1428.     TISVectorIteratorImp( const TISVectorImp<T>& v,
  1429.                           unsigned l, unsigned u
  1430.                          ) :
  1431.         TMISVectorIteratorImp<T,TStandardAllocator>(v,l,u)
  1432.         {
  1433.         }
  1434.  
  1435. };
  1436.  
  1437. #if defined( BI_OLDNAMES )
  1438. #define BI_ISVectorImp TISVectorImp
  1439. #define BI_ISVectorIteratorImp TISVectorIteratorImp
  1440. #endif
  1441.  
  1442. #if defined( BI_CLASSLIB_NO_po )
  1443. #pragma option -po.
  1444. #endif
  1445.  
  1446. #pragma option -Vo.
  1447.  
  1448. #endif  // CLASSLIB_VECTIMP_H
  1449.  
  1450.