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 / ABSTARRY.H next >
C/C++ Source or Header  |  1992-02-18  |  5KB  |  183 lines

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