home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / iikssavl.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  11.9 KB  |  499 lines

  1. /**********************************************************************
  2. *                                                                     *
  3. *  IBM(R) VisualAge(TM) for C++ for Windows(R), Version 3.5           *
  4. *                                                                     *
  5. *  PID: 5622-880                                                      *
  6. *  - Licensed Material - Program-Property of IBM                      *
  7. *  (C) Copyright IBM Corp. 1991, 1995 - All Right Reserved.           *
  8. *                                                                     *
  9. *  US Government Users Restricted Rights - Use, duplication or        *
  10. *  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.  *
  11. *                                                                     *
  12. *  VisualAge, and IBM are trademarks or registered trademarks of      *
  13. *  International Business Machines Corporation.                       *
  14. *  Windows is a registered trademark of Microsoft Corporation.        *
  15. *                                                                     *
  16. **********************************************************************/
  17.  
  18. #ifndef _IIKSSAVL_H
  19. #define _IIKSSAVL_H
  20.  
  21. #include <iiakss.h>
  22.  
  23. #pragma info (nocls, nocnd, nocns, nocnv, noext, nognr, novft)
  24. #pragma pack (4)
  25.  
  26.  
  27. #pragma SOMAsDefault (off)
  28.  
  29. typedef short Direction;
  30.  
  31. const short kAvlLeft  = -1;
  32. const short kAvlNone  =  0;
  33. const short kAvlRight =  1;
  34.  
  35. struct IAKeySortedSetAsAvlTreeNodeImpl {
  36.  
  37.   IAKeySortedSetAsAvlTreeNodeImpl
  38.           *ivLeft,
  39.           *ivRight,
  40.           *ivParent;
  41.  
  42.   Direction
  43.            ivDeeperSubtree;
  44.  
  45.            IAKeySortedSetAsAvlTreeNodeImpl
  46.                             ();
  47.  
  48.   IAKeySortedSetAsAvlTreeNodeImpl*&
  49.            Link             (Direction);
  50.  
  51.   void     Parent           (IAKeySortedSetAsAvlTreeNodeImpl*&,
  52.                              Direction&);
  53.  
  54.   void     ConnectChild     (Direction,
  55.                              IAKeySortedSetAsAvlTreeNodeImpl*);
  56.  
  57.   void     ConnectChild0    (Direction,
  58.                              IAKeySortedSetAsAvlTreeNodeImpl*);
  59.  
  60. };
  61.  
  62. template <class Element>
  63. struct IKeySortedSetAsAvlTreeNodeImpl :
  64.   public IAKeySortedSetAsAvlTreeNodeImpl {
  65.  
  66.   Element  ivElement;
  67.  
  68.            IKeySortedSetAsAvlTreeNodeImpl
  69.                             (Element const&);
  70.  
  71.           ~IKeySortedSetAsAvlTreeNodeImpl
  72.                             ();
  73.  
  74.  
  75. };
  76.  
  77. #pragma SOMAsDefault (pop)
  78. #pragma SOMAsDefault (off)
  79.  
  80. class IKeySortedSetAsAvlTreeCursorImpl : public ICursorImpl {
  81.  
  82.   typedef  ICursorImpl Inherited;
  83.  
  84.   typedef  IKeySortedSetAsAvlTreeCursorImpl Self;
  85.  
  86. public:
  87.  
  88.            IKeySortedSetAsAvlTreeCursorImpl
  89.                             (IACollectionImpl const&);
  90.  
  91.            IKeySortedSetAsAvlTreeCursorImpl
  92.                             (IKeySortedSetAsAvlTreeCursorImpl const&);
  93.  
  94.           ~IKeySortedSetAsAvlTreeCursorImpl
  95.                             ();
  96.  
  97.   ICursorImpl*
  98.            Clone            () const;
  99.  
  100.   void     Copy             (ICursorImpl const&);
  101.  
  102.   void     Invalidate       ();
  103.  
  104.   IBoolean IsInBetween      () const;
  105.  
  106.   IBoolean IsValid          () const;
  107.  
  108.   void     operator=        (IKeySortedSetAsAvlTreeCursorImpl const&);
  109.  
  110.   IBoolean operator==       (ICursorImpl const&) const;
  111.  
  112. protected:
  113.  
  114. private:
  115.  
  116.   IAKeySortedSetAsAvlTreeNodeImpl*
  117.            ivNode;
  118.  
  119.   friend
  120.   class    IKeySortedSetAsAvlTreeImpl;
  121.  
  122.  
  123. };
  124.  
  125.  
  126. template <class Base>
  127. class IKeySetOnKeySortedSetImpl;
  128.  
  129. template <class Base>
  130. class ISortedBagOnKeySortedSetImpl;
  131.  
  132. template <class Base>
  133. class ISortedMapOnKeySortedSetImpl;
  134.  
  135. class IAKeySortedSetAsAvlTreeOps;
  136.  
  137. class IKeySortedSetAsAvlTreeImpl : public IAKeySortedSetImpl {
  138.  
  139.   typedef  IAKeySortedSetImpl Inherited;
  140.  
  141.   typedef  IKeySortedSetAsAvlTreeImpl Self;
  142.  
  143.   typedef  IAKeySortedSetAsAvlTreeNodeImpl Node;
  144.  
  145. public:
  146.  
  147.   typedef  IAKeySortedSetAsAvlTreeOps Ops;
  148.  
  149.   typedef  IKeySortedSetAsAvlTreeCursorImpl Cursor;
  150.  
  151.   typedef  IKeySortedSetAsAvlTreeCursorImpl MngCursor;
  152.  
  153.            IKeySortedSetAsAvlTreeImpl
  154.                             (Ops&, INumber);
  155.  
  156.            IKeySortedSetAsAvlTreeImpl
  157.                             (Ops&, IKeySortedSetAsAvlTreeImpl const&);
  158.  
  159.           ~IKeySortedSetAsAvlTreeImpl
  160.                             ();
  161.  
  162.   IBoolean Add              (void const*, ICursorImpl&);
  163.  
  164.   void     AddAllFrom       (IACollectionImpl const&);
  165.  
  166.   IBoolean AddOrReplaceElementWithKey
  167.                             (void const*, ICursorImpl&);
  168.  
  169.   IBoolean AllElementsDo    (IApplFunc, void*);
  170.  
  171.   void*    Any              () const;
  172.  
  173.   IBoolean CheckCursor      (ICursorImpl const&) const;
  174.  
  175.   IBoolean CheckReplacement (ICursorImpl const&, void const*) const;
  176.  
  177.   char const*
  178.            ClassName        () const;
  179.  
  180.   IACollectionImpl*
  181.            Clone            () const;
  182.  
  183.   IBoolean ContainsAllKeysFrom
  184.                             (IACollectionImpl const&) const;
  185.  
  186.   IBoolean ContainsElementWithKey
  187.                             (void const*) const;
  188.  
  189.   void     Copy             (IACollectionImpl const&);
  190.  
  191.   Cursor*  CreateCursor     () const;
  192.  
  193.   MngCursor*
  194.            CreateMngCursor  () const;
  195.  
  196.   void*    ElementAt        (ICursorImpl const&) const;
  197.  
  198.   void*    ElementAtPosition
  199.                             (IPosition) const;
  200.  
  201.   void*    ElementWithKey   (void const*) const;
  202.  
  203.   void*    First            () const;
  204.  
  205.   IBoolean IsBounded        () const;
  206.  
  207.   IBoolean IsConsistent     () const;
  208.  
  209.   IBoolean IsEmpty          () const;
  210.  
  211.   IBoolean IsFirstAt        (ICursorImpl const&) const;
  212.  
  213.   IBoolean IsFull           () const;
  214.  
  215.   IBoolean IsLastAt         (ICursorImpl const&) const;
  216.  
  217.   void*    Key              (void const*) const;
  218.  
  219.   void*    Last             () const;
  220.  
  221.   IBoolean LocateElementWithKey
  222.                             (void const*, ICursorImpl&) const;
  223.  
  224.   IBoolean LocateNextElementWithKey
  225.                             (void const*, ICursorImpl&) const;
  226.  
  227.   IBoolean LocateOrAddElementWithKey
  228.                             (void const*, ICursorImpl&);
  229.  
  230.   INumber  NumberOfElements () const;
  231.  
  232.   IPosition
  233.            PositionAt       (ICursorImpl const&) const;
  234.  
  235.   INumber  RemoveAll        ();
  236.  
  237.   INumber  RemoveAll        (IPredFunc, void*);
  238.  
  239.   void     RemoveAt         (ICursorImpl&);
  240.  
  241.   void     RemoveAtPosition (IPosition);
  242.  
  243.   IBoolean RemoveElementWithKey
  244.                             (void const*);
  245.  
  246.   void     RemoveFirst      ();
  247.  
  248.   void     RemoveLast       ();
  249.  
  250.   void     ReplaceAt        (ICursorImpl const&, void const*);
  251.  
  252.   void     ReplaceAtPosition
  253.                             (IPosition, void const*);
  254.  
  255.   IBoolean ReplaceElementWithKey
  256.                             (void const*, ICursorImpl&);
  257.  
  258.   IBoolean SetToFirst       (ICursorImpl&) const;
  259.  
  260.   IBoolean SetToNext        (ICursorImpl&) const;
  261.  
  262.   IBoolean SetToLast        (ICursorImpl&) const;
  263.  
  264.   void     SetToPosition    (IPosition, ICursorImpl&) const;
  265.  
  266.   IBoolean SetToPrevious    (ICursorImpl&) const;
  267.  
  268.   void     operator=        (IKeySortedSetAsAvlTreeImpl const&);
  269.  
  270.   TStream& operator<<=      (TStream&);
  271.  
  272.   TStream& operator>>=      (TStream&) const;
  273.  
  274. protected:
  275.  
  276.   void     Assign           (void*, void const*) const;
  277.  
  278.   void*    CreateNode       (void const*) const;
  279.  
  280.   long     CompareKeys      (void const*, void const*,
  281.                              IArgType) const;
  282.  
  283.   void     DeleteNode       (void*) const;
  284.  
  285.   void*    StreamIn         (TStream&) const;
  286.  
  287.   void     StreamOut        (void const*, TStream&) const;
  288.  
  289. private:
  290.  
  291.   enum { kOriginalVersion };
  292.  
  293.   static
  294.   char const*
  295.            cvClassName;
  296.  
  297.   MngCursor*
  298.            ivMngCursors;
  299.  
  300.   Node*    ivRoot;
  301.  
  302.   INumber  ivNumberOfElements;
  303.  
  304.   void     AddAllFromSubtree
  305.                             (Node const*);
  306.  
  307.   IBoolean AllElementsDoSubtree
  308.                             (IApplFunc, void*, Node*) const;
  309.  
  310.   void     Balance          (Node*, Direction, IBoolean&);
  311.  
  312.   IBoolean CheckNode        (Node const*, Node*) const;
  313.  
  314.   IBoolean ContainsAllKeysFromSubtree
  315.                             (Node const*) const;
  316.  
  317.   Node*    CopySubtree      (Node const*) const;
  318.  
  319.   void     DeleteSubtree    (Node*) const;
  320.  
  321.   void     DisconnectAndRemove
  322.                             (Node*, IBoolean&);
  323.  
  324.   void*    ElementOf        (Node const*) const;
  325.  
  326.   IBoolean IsConsistentSubtree
  327.                             (Node const*, int&, INumber&) const;
  328.  
  329.   static
  330.   IBoolean IsInBetween      (ICursorImpl const&);
  331.  
  332.   static
  333.   Node*&   NextNodeOf       (ICursorImpl const&);
  334.  
  335.   static
  336.   Node*&   NodeOf           (ICursorImpl const&);
  337.  
  338.   static
  339.   Ops&     OpsOf            (IKeySortedSetAsAvlTreeImpl const&);
  340.  
  341.   static
  342.   Node*&   PreviousNodeOf   (ICursorImpl const&);
  343.  
  344.   void     ReplaceNode      (Node*, Node*);
  345.  
  346.   void     SetInBetween     (MngCursor&) const;
  347.  
  348.   friend
  349.   class    IKeySortedSetAsAvlTreeMngCursorImpl;
  350.  
  351.   friend
  352.   class    IKeySetOnKeySortedSetImpl <Self>;
  353.  
  354.   friend
  355.   class    ISortedBagOnKeySortedSetImpl <Self>;
  356.  
  357.   friend
  358.   class    ISortedMapOnKeySortedSetImpl <Self>;
  359.  
  360.  
  361. };
  362.  
  363. class IAKeySortedSetAsAvlTreeOps {
  364. public:
  365.  
  366.   virtual ~IAKeySortedSetAsAvlTreeOps
  367.                             ();
  368.  
  369.   virtual
  370.   void     Assign           (void*, void const*) const = 0;
  371.  
  372.   virtual
  373.   IACollectionImpl*
  374.            Clone            () const = 0;
  375.  
  376.   virtual
  377.   long     CompareKeys      (void const*, void const*,
  378.                              IArgType) const = 0;
  379.  
  380.   virtual
  381.   void*    CreateNode       (void const*) const = 0;
  382.  
  383.   virtual
  384.   void     DeleteNode       (void*) const = 0;
  385.  
  386.   virtual
  387.   void*    Key              (void const*) const = 0;
  388.  
  389.   virtual
  390.   void*    StreamIn         (TStream&) const = 0;
  391.  
  392.   virtual
  393.   void     StreamOut        (void const*, TStream&) const = 0;
  394.  
  395.   virtual
  396.   TStream& operator<<=      (TStream&) = 0;
  397.  
  398.   virtual
  399.   TStream& operator>>=      (TStream&) const = 0;
  400.  
  401. protected:
  402.  
  403.            IAKeySortedSetAsAvlTreeOps
  404.                             (IBoolean);
  405.  
  406. private:
  407.  
  408.   IBoolean ivContainsDTSObjects;
  409.  
  410.   friend
  411.   class    IKeySortedSetAsAvlTreeImpl;
  412.  
  413.  
  414. };
  415.  
  416. template <class Element, class _Key,
  417.           class ElementOps, class Implementation>
  418. class IKeySortedSetAsAvlTreeOps : public IAKeySortedSetAsAvlTreeOps {
  419.  
  420.   typedef  IAKeySortedSetAsAvlTreeOps Inherited;
  421.  
  422.   typedef  IKeySortedSetAsAvlTreeOps
  423.             <Element, _Key, ElementOps, Implementation> Self;
  424.  
  425.   typedef  IKeySortedSetAsAvlTreeNodeImpl <Element> Node;
  426.  
  427. public:
  428.  
  429.   typedef  Implementation ImplType;
  430.  
  431.   typedef  Element ElementType;
  432.  
  433.   typedef  _Key KeyType;
  434.  
  435.            IKeySortedSetAsAvlTreeOps
  436.                             (INumber);
  437.  
  438.            IKeySortedSetAsAvlTreeOps
  439.                             (INumber, void*);
  440.  
  441.            IKeySortedSetAsAvlTreeOps
  442.                             (IKeySortedSetAsAvlTreeOps
  443.                               <Element, _Key,
  444.                                ElementOps, Implementation> const&);
  445.  
  446.           ~IKeySortedSetAsAvlTreeOps
  447.                             ();
  448.  
  449.   void     Assign           (void*, void const*) const;
  450.  
  451.   IACollectionImpl*
  452.            Clone            () const;
  453.  
  454.   long     CompareKeys      (void const*, void const*, IArgType) const;
  455.  
  456.   void*    CreateNode       (void const*) const;
  457.  
  458.   void     DeleteNode       (void*) const;
  459.  
  460.   void*    Key              (void const*) const;
  461.  
  462.   void*    StreamIn         (TStream&) const;
  463.  
  464.   void     StreamOut        (void const*, TStream&) const;
  465.  
  466.   TStream& operator<<=      (TStream&);
  467.  
  468.   TStream& operator>>=      (TStream&) const;
  469.  
  470.            operator Implementation*
  471.                             ();
  472.  
  473.  
  474. protected:
  475.  
  476. private:
  477.  
  478.   ElementOps
  479.            ivElementOps;
  480.  
  481.   Implementation
  482.            ivImpl;
  483.  
  484.  
  485. };
  486.  
  487. #pragma SOMAsDefault (pop)
  488.  
  489. #include <iikssavl.inl>
  490.  
  491. #if ! defined (__TEMPINC__)
  492. #include <iikssavl.c>
  493. #endif
  494.  
  495. #pragma info (restore)
  496. #pragma pack ()
  497.  
  498. #endif
  499.