home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IADEQUE.C < prev    next >
Text File  |  1993-09-22  |  3KB  |  75 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>
  15. IADeque <Element> ::~IADeque ()
  16. {
  17. }
  18.  
  19. template <class Element>
  20. void IADeque < Element >::
  21. addAllFrom (IADeque < Element > 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>
  32. void IADeque < Element >::
  33. copy (IADeque < Element > const& collection)
  34. { if (! isIdentical (collection)) {
  35.     removeAll ();
  36.     addAllFrom (collection);
  37.   }
  38. };
  39.  
  40. template <class Element>
  41. void* IADeque < Element >::
  42. identity () const
  43. { return (void*) this;
  44. }
  45.  
  46. template < class Element >
  47. long IADeque < Element >::
  48. compare (IADeque < Element > const& collection,
  49.          long (*comparisonFunction) (Element const&, Element const&)) const
  50. { long result = 0;
  51.   ICursor *thisCursor = newCursor ();
  52.   ICursor *collectionCursor = collection.newCursor ();
  53.  
  54.   for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
  55.        result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
  56.        thisCursor->setToNext (), collectionCursor->setToNext ()) {
  57.     result = (*comparisonFunction) (this->elementAt (*thisCursor),
  58.                                       collection.elementAt (*collectionCursor));
  59.   }
  60.  
  61.   if (result == 0) {
  62.     if (thisCursor->isValid () && ! collectionCursor->isValid ())
  63.       result = 1;
  64.     else if (! thisCursor->isValid () && collectionCursor->isValid ())
  65.       result = -1;
  66.     else {
  67.     }
  68.   }
  69.   delete thisCursor;
  70.   delete collectionCursor;
  71.  
  72.   return result;
  73. }
  74.  
  75.