home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IITDSEQ.H < prev    next >
Text File  |  1993-09-22  |  7KB  |  144 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 _IITDSEQ_H
  13. #define _IITDSEQ_H
  14.  
  15. #include <iglobals.h>
  16. #include <icursor.h>
  17.  
  18. class IDilutedSequenceImpl
  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.   class Operations : public Table
  62.   {
  63.   protected:
  64.     virtual void        swap                 (INumber index1,
  65.                                               INumber index2) const = 0;
  66.     virtual void        copyFrom             (INumber index,
  67.                                               void const* element) const = 0;
  68.     virtual void const* elementAt            (INumber index) const = 0;
  69.  
  70.     virtual IBoolean     isRemoved            (INumber index) const = 0;
  71.     virtual void        remove               (INumber index) = 0;
  72.     virtual IBoolean     setToNext            (INumber& index) const = 0;
  73.     virtual IBoolean     setToPrevious        (INumber& index) const = 0;
  74.  
  75.     virtual IBoolean     constantFunctionIteration
  76.                                              (void *function,
  77.                                               void* env,
  78.                                               INumber index) const = 0;
  79.     virtual IBoolean     functionIteration    (void *function,
  80.                                               void* env,
  81.                                               INumber index) = 0;
  82.     virtual IBoolean     constantIteratorIteration
  83.                                              (void* iterator,
  84.                                               INumber index) const = 0;
  85.     virtual IBoolean     iteratorIteration    (void* iterator,
  86.                                               INumber index) = 0;
  87.  
  88.     virtual long        functionComparison   (void *compareFunction,
  89.                                               void const* element1,
  90.                                               void const* element2) = 0;
  91.     virtual long        functionComparison   (void *compareFunction,
  92.                                               INumber index1,
  93.                                               INumber index2) = 0;
  94.  
  95.     virtual void        blockLeft            (INumber, INumber) = 0;
  96.     virtual void        blockRight           (INumber, INumber) = 0;
  97.  
  98.     virtual void        copy                 (Table const& from) = 0;
  99.     virtual void        expand               (INumber) = 0;
  100.     virtual void        makeFree             (INumber&) = 0;
  101.  
  102.     friend class IDilutedSequenceImpl;
  103.   };
  104.  
  105. private :
  106.  
  107.   Operations *ivOps;
  108.  
  109. public :
  110.  
  111.           IDilutedSequenceImpl        (Operations* ops) : ivOps (ops)
  112.           {}
  113.  
  114.   void    addAllFrom                  (IDilutedSequenceImpl const& sequence);
  115.   void    removeAt                    (INumber& index);
  116.   INumber removeAll                   (void* predicate, void* env);
  117.   IBoolean setToFirst                  (Cursor& cursor) const;
  118.   IBoolean setToNext                   (Cursor& cursor) const;
  119.   IBoolean setToLast                   (Cursor& cursor) const;
  120.   IBoolean setToPrevious               (Cursor& cursor) const;
  121.   void    setToPosition               (IPosition position,
  122.                                        Cursor& cursor) const;
  123.   IBoolean allElementsDo               (void* iterationFunction, void* env);
  124.   IBoolean allElementsDo               (void *iterationFunction,
  125.                                        void* env) const;
  126.   IBoolean allElementsDo               (void* iterator);
  127.   IBoolean allElementsDo               (void *iterator) const;
  128.   void    operator=                   (IDilutedSequenceImpl const& sequence);
  129.   long    compare                     (IDilutedSequenceImpl const& sequence,
  130.                                        void* comparisonFunction) const;
  131.   void    addAsFirst                  (void const* element, Cursor& cursor);
  132.   void    addAsNext                   (void const* element, Cursor& cursor);
  133.   void    addAsLast                   (void const* element, Cursor& cursor);
  134.   void    addAsPrevious               (void const* element, Cursor& cursor);
  135.   void    addAtPosition               (IPosition position,
  136.                                        void const* element,
  137.                                        Cursor& cursor);
  138.   void    sort                        (void* comparisonFunction);
  139.   IBoolean checkIndex                  (INumber index) const;
  140.   IBoolean isConsistent                () const;
  141. };
  142.  
  143. #endif
  144.