home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IKSBSEQ.H < prev    next >
Text File  |  1993-09-22  |  8KB  |  204 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 _IKSBSEQ_H
  13. #define _IKSBSEQ_H
  14.  
  15. #include <iglobals.h>
  16. #include <icursor.h>
  17.  
  18. template < class Element, class Key, class ElementOps, class Base >
  19. class IWKSBagOnSeq {
  20.   Base ivBase;
  21.   class Cursor;
  22.   friend class Cursor;
  23. public:
  24.  
  25.   class Cursor : public Base::Cursor {
  26.   protected:
  27.     IBoolean isFor (IWKSBagOnSeq
  28.                      < Element, Key, ElementOps, Base > const& c) const
  29.     { return Base::Cursor::isFor (c.ivBase); }
  30.  
  31.   public:
  32.     Cursor (IWKSBagOnSeq < Element, Key, ElementOps, Base > const& c)
  33.     : Base::Cursor (c.ivBase) {}
  34.   };
  35.  
  36.                   IWKSBagOnSeq             (INumber
  37.                                                numberOfElements = 100);
  38.  
  39.                   IWKSBagOnSeq             (IWKSBagOnSeq < Element, Key, ElementOps, Base > const&);
  40.  
  41.    IWKSBagOnSeq < Element, Key, ElementOps, Base >&
  42.                   operator =                  (IWKSBagOnSeq < Element, Key, ElementOps, Base > const&);
  43.  
  44.                  ~IWKSBagOnSeq             ();
  45.  
  46.    IBoolean       add                         (Element const&);
  47.  
  48.    IBoolean       add                         (Element const&,
  49.                                                ICursor&);
  50.  
  51.    void           addAllFrom                  (IWKSBagOnSeq < Element, Key, ElementOps, Base > const&);
  52.  
  53.    Element const& elementAt                   (ICursor const&) const;
  54.  
  55.    Element&       elementAt                   (ICursor const&);
  56.  
  57.    Element const& anyElement                  () const;
  58.  
  59.    void           removeAt                    (ICursor const&);
  60.  
  61.    INumber        removeAll                   (IBoolean (*property)
  62.                                                (Element const&, void*),
  63.                                                void* additionalArgument = 0);
  64.  
  65.    void           replaceAt                   (ICursor const&,
  66.                                                Element const&);
  67.  
  68.    void           removeAll                   ();
  69.  
  70.    IBoolean       isBounded                   () const;
  71.  
  72.    INumber        maxNumberOfElements         () const;
  73.  
  74.    INumber        numberOfElements            () const;
  75.  
  76.    IBoolean       isEmpty                     () const;
  77.  
  78.    IBoolean       isFull                      () const;
  79.  
  80.    ICursor*       newCursor                   () const;
  81.  
  82.    IBoolean       setToFirst                  (ICursor&) const;
  83.  
  84.    IBoolean       setToNext                   (ICursor&) const;
  85.  
  86.    IBoolean       allElementsDo               (IBoolean (*function)
  87.                                                   (Element&, void*),
  88.                                                void* additionalArgument = 0);
  89.  
  90.    IBoolean       allElementsDo               (IIterator <Element>&);
  91.  
  92.    IBoolean       allElementsDo               (IBoolean (*function)
  93.                                                (Element const&, void*),
  94.                                                void* additionalArgument = 0)
  95.                                                const;
  96.  
  97.    IBoolean       allElementsDo               (IConstantIterator
  98.                                                   <Element>&) const;
  99.  
  100.    IBoolean       isConsistent                () const;
  101.  
  102.    Key const&     key                         (Element const&) const;
  103.  
  104.    IBoolean       containsElementWithKey      (Key const&) const;
  105.  
  106.    IBoolean       containsAllKeysFrom         (IWKSBagOnSeq < Element, Key, ElementOps, Base > const&) const;
  107.  
  108.    IBoolean       locateElementWithKey        (Key const&, ICursor&)
  109.                                                const;
  110.  
  111.    IBoolean       replaceElementWithKey       (Element const&);
  112.  
  113.    IBoolean       replaceElementWithKey       (Element const&,
  114.                                                ICursor&);
  115.  
  116.    IBoolean       locateOrAddElementWithKey   (Element const&);
  117.  
  118.    IBoolean       locateOrAddElementWithKey   (Element const&,
  119.                                                ICursor&);
  120.  
  121.    IBoolean       addOrReplaceElementWithKey  (Element const&);
  122.  
  123.    IBoolean       addOrReplaceElementWithKey  (Element const&,
  124.                                                ICursor&);
  125.  
  126.    IBoolean       removeElementWithKey        (Key const&);
  127.  
  128.    Element const& elementWithKey              (Key const&) const;
  129.  
  130.    Element&       elementWithKey              (Key const&);
  131.  
  132.    INumber        numberOfElementsWithKey     (Key const&) const;
  133.  
  134.    IBoolean       locateNextElementWithKey    (Key const&,
  135.                                                ICursor&) const;
  136.  
  137.    INumber        removeAllElementsWithKey    (Key const&);
  138.  
  139.    INumber        numberOfDifferentKeys       () const;
  140.  
  141.    IBoolean       setToNextWithDifferentKey   (ICursor&) const;
  142.  
  143.    void           removeFirst                 ();
  144.  
  145.    void           removeLast                  ();
  146.  
  147.    void           removeAtPosition            (IPosition);
  148.  
  149.    Element const& firstElement                () const;
  150.  
  151.    Element const& lastElement                 () const;
  152.  
  153.    Element const& elementAtPosition           (IPosition) const;
  154.  
  155.    IBoolean       setToLast                   (ICursor&) const;
  156.  
  157.    IBoolean       setToPrevious               (ICursor&) const;
  158.  
  159.    void           setToPosition               (IPosition,
  160.                                                ICursor&) const;
  161.  
  162.    IBoolean       isFirst                     (ICursor const&) const;
  163.  
  164.    IBoolean       isLast                      (ICursor const&) const;
  165.  
  166.    long           compare                     (IWKSBagOnSeq < Element, Key, ElementOps, Base > const&,
  167.                                                long (*comparisonFunction)
  168.                                                   (Element const&,
  169.                                                   Element const&)) const;
  170.  
  171. protected:
  172.  
  173.   static IBoolean  removePredicate (Element const&, void*);
  174.   IBoolean         locateKeyFwd    (Key const&, ICursor&) const;
  175.   IBoolean         locateKey       (Key const&, ICursor&) const;
  176.  
  177.   static ElementOps elementOps ()
  178.   { ElementOps ops;
  179.     return ops;
  180.   }
  181.  
  182. };
  183.  
  184. #define IDefineGKeySortedBagOnGSequence(GSeq, GKeySortedBag) \
  185. template < class Element, class Key, class ElementOps > \
  186. class GKeySortedBag : \
  187.   public IWKSBagOnSeq < Element, Key, ElementOps, \
  188.                         GSeq < Element, ElementOps > > { \
  189. public: \
  190.   GKeySortedBag (INumber n = 100) : \
  191.     IWKSBagOnSeq < Element, Key, ElementOps, \
  192.                    GSeq < Element, ElementOps > > (n) {} \
  193. };
  194.  
  195. #include <iksbseq.if>
  196.  
  197. #ifdef __IBMCPP__
  198. #ifndef __TEMPINC__
  199. #include <iksbseq.c>
  200. #endif
  201. #endif
  202.  
  203. #endif
  204.