home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / CLOBSH.PAK / ABSTARRY.H next >
C/C++ Source or Header  |  1995-08-29  |  5KB  |  205 lines

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