home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 2.ddi / CLASSINC.ZIP / ABSTARRY.H next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  5.1 KB  |  203 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  ABSTARRY.H                                                            */
  4. /*                                                                        */
  5. /*  Copyright Borland International 1991, 1992                            */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __ABSTARRY_H )
  11. #define __ABSTARRY_H
  12.  
  13. #if defined( TEMPLATES )
  14.  
  15.     #if !defined( __COLLECT_H )
  16.     #include <Collect.h>
  17.     #endif  // __COLLECT_H
  18.  
  19.     #if !defined( __MEM_H )
  20.     #include <Mem.h>
  21.     #endif  // __MEM_H
  22.  
  23.     #pragma option -Vo-
  24.     #if defined( __BCOPT__ ) && !defined( _ALLOW_po )
  25.     #pragma option -po-
  26.     #endif
  27.  
  28.     _CLASSDEF(ostream)
  29.     _CLASSDEF(ContainerIterator)
  30.     _CLASSDEF(AbstractArray)
  31.     _CLASSDEF(ArrayIterator)
  32.  
  33.     class _CLASSTYPE AbstractArray:  public Collection
  34.     {
  35.  
  36.     public:
  37.  
  38.         friend class ArrayIterator;
  39.  
  40.         virtual Object _FAR & operator []( int loc ) = 0;
  41.  
  42.         virtual int lowerBound() const = 0;
  43.         virtual int upperBound() const = 0;
  44.         virtual sizeType arraySize() const = 0;
  45.  
  46.         virtual void detach( int loc, DeleteType dt = NoDelete ) = 0;
  47.         virtual void detach( Object _FAR &, DeleteType dt = NoDelete ) = 0;
  48.         void destroy( int i )
  49.             {
  50.             detach( i, Delete );
  51.             }
  52.  
  53.         int isEqual( const Object _FAR & ) const;
  54.         void printContentsOn( ostream _FAR & ) const;
  55.  
  56.     };
  57.  
  58. #else   // TEMPLATES
  59.  
  60.     #if !defined( __COLLECT_H )
  61.     #include <Collect.h>
  62.     #endif  // __COLLECT_H
  63.  
  64.     #if !defined( __MEM_H )
  65.     #include <Mem.h>
  66.     #endif  // __MEM_H
  67.  
  68.     #if !defined( __CHECKS_H )
  69.     #include <Checks.h>
  70.     #endif    // __CHECKS_H
  71.  
  72.     #pragma option -Vo-
  73.     #if defined( __BCOPT__ ) && !defined( _ALLOW_po )
  74.     #pragma option -po-
  75.     #endif
  76.  
  77.     _CLASSDEF(ostream)
  78.     _CLASSDEF(ContainerIterator)
  79.     _CLASSDEF(AbstractArray)
  80.     _CLASSDEF(ArrayIterator)
  81.  
  82.     class _CLASSTYPE AbstractArray:  public Collection
  83.     {
  84.  
  85.     public:
  86.  
  87.         AbstractArray( int, int = 0, sizeType = 0 );
  88.         virtual ~AbstractArray();
  89.  
  90.         Object _FAR & operator []( int ) const;
  91.  
  92.         int lowerBound() const
  93.             {
  94.             return lowerbound;
  95.             }
  96.  
  97.         int upperBound() const
  98.             {
  99.             return upperbound;
  100.             }
  101.  
  102.         sizeType arraySize() const;
  103.  
  104.         virtual void detach( Object _FAR &, DeleteType = NoDelete );
  105.         virtual void detach( int, DeleteType = NoDelete );
  106.         void destroy( int i ) { detach( i, DefDelete ); }
  107.         virtual void flush( DeleteType = DefDelete );
  108.  
  109.         virtual int isEqual( const Object _FAR & ) const;
  110.         virtual void printContentsOn( ostream _FAR & ) const;
  111.  
  112.         virtual ContainerIterator _FAR & initIterator() const;
  113.  
  114.     protected:
  115.  
  116.         Object _FAR & objectAt( int i ) const
  117.             {
  118.             return *theArray[ zeroBase(i) ];
  119.             }
  120.  
  121.         Object _FAR *ptrAt( int i ) const
  122.             {
  123.             return theArray[ zeroBase(i) ];
  124.             }
  125.  
  126.         int find( const Object _FAR & );
  127.  
  128.         void reallocate( sizeType );
  129.  
  130.         void setData( int, Object _FAR * );
  131.  
  132.         void insertEntry( int );
  133.         void removeEntry( int );
  134.         void squeezeEntry( int );
  135.  
  136.         sizeType delta;
  137.         int lowerbound;
  138.         int upperbound;
  139.         int lastElementIndex;
  140.  
  141.     private:
  142.  
  143.         Object _FAR * _FAR *theArray;
  144.  
  145.         int zeroBase( int loc ) const
  146.             {
  147.             PRECONDITION( loc >= lowerbound && loc <= upperbound );
  148.             return loc - lowerbound;
  149.             }
  150.  
  151.         int boundBase( unsigned loc ) const
  152.             {
  153.             PRECONDITION( loc == UINT_MAX || loc <= upperbound - lowerbound );
  154.             return loc == UINT_MAX ? INT_MAX : loc + lowerbound;
  155.             }
  156.  
  157.         friend class ArrayIterator;
  158.  
  159.     };
  160.  
  161.     inline Object _FAR & AbstractArray::operator [] ( int atIndex ) const
  162.     {
  163.         return objectAt( atIndex );
  164.     }
  165.  
  166.     inline sizeType AbstractArray::arraySize() const
  167.     {
  168.         return sizeType( upperbound - lowerbound + 1 );
  169.     }
  170.  
  171.     class _CLASSTYPE ArrayIterator : public ContainerIterator
  172.     {
  173.  
  174.     public:
  175.  
  176.         ArrayIterator( const AbstractArray _FAR & );
  177.         virtual ~ArrayIterator();
  178.  
  179.         virtual operator int();
  180.         virtual Object _FAR & current();
  181.         virtual Object _FAR & operator ++( int );
  182.         virtual Object _FAR & operator ++();
  183.         virtual void restart();
  184.  
  185.     private:
  186.  
  187.         int currentIndex;
  188.         const AbstractArray _FAR & beingIterated;
  189.  
  190.         void scan();
  191.  
  192.     };
  193.  
  194. #endif  // TEMPLATES
  195.  
  196. #if defined( __BCOPT__ ) && !defined( _ALLOW_po )
  197. #pragma option -po.
  198. #endif
  199. #pragma option -Vo.
  200.  
  201. #endif  // __ABSTARRY_H
  202.  
  203.