home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IAPRIOQU.C < prev    next >
Text File  |  1993-09-22  |  3KB  |  89 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. #include <ibexcept.h>
  13.  
  14. template < class Element, class Key >
  15. IAPriorityQueue < Element, Key > ::~IAPriorityQueue ()
  16. {
  17. }
  18.  
  19. template < class Element, class Key >
  20. void IAPriorityQueue < Element, Key >::
  21. addAllFrom (IAPriorityQueue < Element, Key > const& collection)
  22. { ICHECK (! isIdentical (collection),
  23.           IIdenticalCollectionException, IIdenticalCollectionText)
  24.   ICursor *cursor = collection.newCursor ();
  25.   forCursor (*cursor) {
  26.     add (collection.elementAt (*cursor));
  27.   }
  28.   delete cursor;
  29. };
  30.  
  31. template < class Element, class Key >
  32. void IAPriorityQueue < Element, Key >::
  33. copy (IAPriorityQueue < Element, Key > const& collection)
  34. { if (! isIdentical (collection)) {
  35.     removeAll ();
  36.     addAllFrom (collection);
  37.   }
  38. };
  39.  
  40. template < class Element, class Key >
  41. void* IAPriorityQueue < Element, Key >::
  42. identity () const
  43. { return (void*) this;
  44. }
  45.  
  46. template <class Element, class Key>
  47. IBoolean IAPriorityQueue < Element, Key >::
  48. containsAllKeysFrom (IAPriorityQueue < Element, Key > const& collection) const
  49. { IBoolean result = True;
  50.   ICursor *cursor = collection.newCursor ();
  51.   forCursor (*cursor) {
  52.     if (! containsElementWithKey (key (collection.elementAt (*cursor)))) {
  53.       result = False;
  54.       break;
  55.     }
  56.   }
  57.   delete cursor;
  58.   return result;
  59. };
  60.  
  61. template < class Element, class Key >
  62. long IAPriorityQueue < Element, Key >::
  63. compare (IAPriorityQueue < Element, Key > const& collection,
  64.          long (*comparisonFunction) (Element const&, Element const&)) const
  65. { long result = 0;
  66.   ICursor *thisCursor = newCursor ();
  67.   ICursor *collectionCursor = collection.newCursor ();
  68.  
  69.   for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
  70.        result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
  71.        thisCursor->setToNext (), collectionCursor->setToNext ()) {
  72.     result = (*comparisonFunction) (this->elementAt (*thisCursor),
  73.                                       collection.elementAt (*collectionCursor));
  74.   }
  75.  
  76.   if (result == 0) {
  77.     if (thisCursor->isValid () && ! collectionCursor->isValid ())
  78.       result = 1;
  79.     else if (! thisCursor->isValid () && collectionCursor->isValid ())
  80.       result = -1;
  81.     else {
  82.     }
  83.   }
  84.   delete thisCursor;
  85.   delete collectionCursor;
  86.  
  87.   return result;
  88. }
  89.