home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / ORDCOLL.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  6KB  |  202 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: odutils
  5. //
  6. //   CLASSES:   OrderedCollection
  7. //        OrderedCollectionIterator
  8. //        ValueLink
  9. //
  10. //   ORIGINS: 82,27
  11. //
  12. //
  13. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  14. //   All Rights Reserved
  15. //   Licensed Materials - Property of IBM
  16. //   US Government Users Restricted Rights - Use, duplication or
  17. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  18. //       
  19. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  22. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  23. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  24. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  25. //   OR PERFORMANCE OF THIS SOFTWARE.
  26. //
  27. //====END_GENERATED_PROLOG========================================
  28. //
  29. // @(#) 1.3 com/src/utils/include/OrdColl.h, odutils, od96os2, odos29646d 7/15/96 18:01:29 [ 11/15/96 15:29:33 ]
  30. /*
  31.     File:        OrdColl.h
  32.  
  33.     Contains:    Definition of class OrderedCollection
  34.  
  35.     Owned by:    Richard Rodseth
  36.  
  37.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  38.  
  39.     
  40.     In Progress:
  41.         
  42. */
  43.  
  44. #ifndef _ORDCOLL_
  45. #define _ORDCOLL_
  46.  
  47. #ifndef _ODTYPES_
  48. #include "ODTypes.h"
  49. #endif
  50.  
  51. #ifndef _PLFMDEF_
  52. #include "PlfmDef.h"
  53. #endif
  54.  
  55. #ifndef _LINKLIST_
  56. #include "LinkList.h"
  57. #endif
  58.  
  59. #ifndef _ODMEMORY_
  60. #include "ODMemory.h"
  61. #endif
  62.  
  63. //==============================================================================
  64. // Theory of Operation
  65. //==============================================================================
  66.  
  67. // OrdereCollection is an ordered collection of elements of type void* (since
  68. // we can't use templates)
  69. // Duplicates are allowed.
  70.  
  71. //==============================================================================
  72. // Constants
  73. //==============================================================================
  74.  
  75. //==============================================================================
  76. // Scalar Types
  77. //==============================================================================
  78.  
  79. typedef void* ElementType;
  80.  
  81. //=====================================================================================
  82. // Classes defined in this interface
  83. //=====================================================================================
  84.  
  85. class OrderedCollection;    // An ordered (not sorted) collection of ElementTypes
  86. class OrderedCollectionIterator;
  87.  
  88. //=====================================================================================
  89. // Classes used by this interface
  90. //=====================================================================================
  91.  
  92. class ValueLink;             // A link plus a value of type ElementType.
  93.  
  94. //=====================================================================================
  95. // Global Variables
  96. //=====================================================================================
  97.  
  98. //=====================================================================================
  99. // Class ValueLink - Definition
  100. //=====================================================================================
  101.  
  102. class ValueLink : public Link {
  103.     
  104. public:
  105.                             ValueLink(ElementType value);        
  106.     ODVMethod                ~ValueLink();
  107.     ODNVMethod    ElementType    GetValue()                        { return fValue;}
  108.     ODNVMethod void        SetValue(ElementType v)            { fValue = v;}
  109.  
  110. private:
  111.     ElementType         fValue;
  112. };
  113.  
  114. //=====================================================================================
  115. // Class OrderedCollection
  116. //=====================================================================================
  117.  
  118. class OrderedCollection
  119. {
  120.     
  121. public:
  122.  
  123.     OrderedCollection();
  124.     OrderedCollection(ODMemoryHeapID where);
  125.     virtual ~OrderedCollection();
  126.  
  127.     ODNVMethod ODULong Count() const             { return fImplementation.Count(); };
  128.     
  129.     ODVMethod void    AddFirst(ElementType element);
  130.     ODVMethod void    AddLast(ElementType element);
  131.     ODVMethod void    AddBefore(ElementType existing, ElementType tobeadded);
  132.     ODVMethod void    AddAfter(ElementType existing, ElementType tobeadded);
  133.  
  134.     ODVMethod ElementType    After(ElementType existing) const;
  135.     ODVMethod ElementType    Before(ElementType existing) const;
  136.  
  137.     ODVMethod ElementType    First() const;
  138.         // Returns kODNULL if there is no first element.
  139.     ODVMethod ElementType    Last() const;
  140.  
  141.     ODVMethod ElementType    RemoveFirst();
  142.         // Don't call if there are no elements. Crash will result.
  143.     ODVMethod ElementType    RemoveLast();
  144.     ODVMethod void    RemoveAll();
  145.     
  146.         // Called from the destructor. Removes all elements, deleting the links
  147.         // Does not delete the elements themselves
  148.         
  149.     ODVMethod void    DeleteAll();
  150.     
  151.         // Removes and deletes all elements
  152.         
  153.     ODVMethod ODBoolean    Remove(ElementType existing);
  154.         // Returns true if existing was actually removed.
  155.         
  156.     ODVMethod ODBoolean    Contains(ElementType existing) const;
  157.     
  158.     ODVMethod OrderedCollectionIterator* CreateIterator();
  159.     
  160.     ODNVMethod ODMemoryHeapID GetHeap() const;
  161.  
  162. protected:
  163.      ODVMethod ValueLink*     CreateNewLink(ElementType value) const;
  164.      ODVMethod ODBoolean    ElementsMatch(ElementType v1,ElementType v2) const;
  165.          // Does a pointer comparison by default 
  166.  
  167. private:
  168.     LinkedList        fImplementation;
  169.     ODMemoryHeapID    fHeap; // if kODNULL, use default heap.
  170.  
  171.     friend class OrderedCollectionIterator;
  172.     friend class ListIterator;
  173. };
  174.  
  175. inline ODMemoryHeapID OrderedCollection::GetHeap() const 
  176. {
  177.     return fHeap;
  178. }
  179.  
  180.  
  181. //=====================================================================================
  182. // Class OrderedCollectionIterator
  183. //=====================================================================================
  184.  
  185. class OrderedCollectionIterator {
  186. public:
  187.     OrderedCollectionIterator(OrderedCollection* collection);
  188.     ~OrderedCollectionIterator();
  189.     ElementType First();
  190.     ElementType Next();
  191.     ElementType Last();
  192.     ElementType Previous();
  193.     ODBoolean   IsNotComplete();
  194.     void        RemoveCurrent();
  195.     
  196. private:
  197.       OrderedCollection*    fCollection;
  198.     LinkedListIterator    fImplementation;
  199. };
  200.  
  201. #endif // _ORDCOLL_
  202.