home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / bbxxk / irelkb.h__ / IRELKB.H
Encoding:
C/C++ Source or Header  |  1992-10-26  |  8.1 KB  |  218 lines

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