home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IITBSEQ.H < prev    next >
Text File  |  1993-09-22  |  6KB  |  141 lines

  1. /*******************************************************************************
  2. *                                                                              *
  3. * COPYRIGHT:                                                                   *
  4. *   IBM C/C++ Tools Version 2.01 - Collection Class Library                    *
  5. *   Licensed Materials - Property of IBM                                       *
  6. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  7. *   All Rights Reserved                                                        *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  10. *                                                                              *
  11. *******************************************************************************/
  12. #ifndef _IITBSEQ_H
  13. #define _IITBSEQ_H
  14.  
  15. #include <iglobals.h>
  16. #include <icursor.h>
  17.  
  18. class ITabularSequenceImpl
  19. {
  20. public:
  21.  
  22.   class Cursor
  23.   {
  24.   public:
  25.     INumber ivIndex;
  26.     IBoolean ivIsValid;
  27.     Cursor () : ivIsValid (False) {}
  28.     IBoolean operator== (Cursor const& cursor) const
  29.     { return ivIsValid == cursor.ivIsValid &&
  30.              ivIndex == cursor.ivIndex; }
  31.   };
  32.  
  33.   class Table
  34.   {
  35.   public:
  36.     INumber ivFirst;
  37.     INumber ivLast;
  38.     INumber ivNumberOfElements;
  39.     INumber ivAllocatedElements;
  40.     void *ivNodes;
  41.  
  42.     IBoolean     canAdd               (INumber n) const
  43.                 { return ivNumberOfElements+n <= ivAllocatedElements; }
  44.     INumber     pos                  (INumber n) const
  45.                 { return n >= ivFirst ?
  46.                          n - ivFirst % ivAllocatedElements :
  47.                          ivAllocatedElements -
  48.                            (ivFirst - n) % ivAllocatedElements; }
  49.  
  50.     INumber&    decMod               (INumber& n) const
  51.                 { if (n == 0) n = ivAllocatedElements;
  52.                   return --n; }
  53.     INumber&    incMod               (INumber& n) const
  54.                 { if (++n == ivAllocatedElements) n = 0;
  55.                   return n; }
  56.     INumber&    addMod               (INumber& n, INumber n1) const
  57.                 { n = (n + n1) % ivAllocatedElements;
  58.                   return n; }
  59.  
  60.   };
  61.  
  62.   class Operations : public Table
  63.   {
  64.   protected:
  65.     virtual void        swap                 (INumber index1,
  66.                                               INumber index2) const = 0;
  67.     virtual void        copyFrom             (INumber index,
  68.                                               void const* element) const = 0;
  69.     virtual void const* elementAt            (INumber index) const = 0;
  70.  
  71.     virtual IBoolean     constantFunctionIteration
  72.                                              (void *function,
  73.                                               void* env,
  74.                                               INumber index) const = 0;
  75.     virtual IBoolean     functionIteration    (void *function,
  76.                                               void* env,
  77.                                               INumber index) = 0;
  78.     virtual IBoolean     constantIteratorIteration
  79.                                              (void* iterator,
  80.                                               INumber index) const = 0;
  81.     virtual IBoolean     iteratorIteration    (void* iterator,
  82.                                               INumber index) = 0;
  83.  
  84.     virtual long        functionComparison   (void *compareFunction,
  85.                                               void const* element1,
  86.                                               void const* element2) = 0;
  87.     virtual long        functionComparison   (void *compareFunction,
  88.                                               INumber index1,
  89.                                               INumber index2) = 0;
  90.  
  91.     virtual void        blockLeft            (INumber, INumber) = 0;
  92.     virtual void        blockRight           (INumber, INumber) = 0;
  93.  
  94.     virtual void        copy                 (Table const& from) = 0;
  95.     virtual void        expand               (INumber) = 0;
  96.  
  97.     friend class ITabularSequenceImpl;
  98.   };
  99.  
  100. private :
  101.  
  102.   Operations *ivOps;
  103.  
  104. public :
  105.  
  106.           ITabularSequenceImpl        (Operations* ops) : ivOps (ops)
  107.           {}
  108.  
  109.   void    addAllFrom                  (ITabularSequenceImpl const& sequence);
  110.   void    removeAt                    (INumber& index);
  111.   INumber removeAll                   (void* predicate, void* env);
  112.   IBoolean setToFirst                  (Cursor& cursor) const;
  113.   IBoolean setToNext                   (Cursor& cursor) const;
  114.   IBoolean setToLast                   (Cursor& cursor) const;
  115.   IBoolean setToPrevious               (Cursor& cursor) const;
  116.   void    setToPosition               (IPosition position,
  117.                                        Cursor& cursor) const;
  118.   IBoolean allElementsDo               (void* iterationFunction, void* env);
  119.   IBoolean allElementsDo               (void *iterationFunction,
  120.                                        void* env) const;
  121.   IBoolean allElementsDo               (void* iterator);
  122.   IBoolean allElementsDo               (void *iterator) const;
  123.   void    operator=                   (ITabularSequenceImpl const& sequence);
  124.   long    compare                     (ITabularSequenceImpl const& sequence,
  125.                                        void* comparisonFunction) const;
  126.   void    addAsFirst                  (void const* element, Cursor& cursor);
  127.   void    addAsNext                   (void const* element, Cursor& cursor);
  128.   void    addAsLast                   (void const* element, Cursor& cursor);
  129.   void    addAsPrevious               (void const* element, Cursor& cursor);
  130.   void    addAtPosition               (IPosition position,
  131.                                        void const* element,
  132.                                        Cursor& cursor);
  133.   void    quicksort                   (void* comparisonFunction,
  134.                                        INumber from, INumber to);
  135.   void    sort                        (void* comparisonFunction);
  136.   IBoolean checkIndex                  (INumber index) const;
  137.   IBoolean isConsistent                () const;
  138. };
  139.  
  140. #endif
  141.