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