home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / runnable / ibmc / ibmclass / iarel.c < prev    next >
Encoding:
Text File  |  1992-10-26  |  2.8 KB  |  94 lines

  1. /* Copyright (c) IBM Corp. 1992 */
  2.  
  3.  
  4. template < class Element, class Key >
  5. INumber IARelation < Element, Key >::
  6. numberOfOccurrences (Element const& element) const
  7. { if (contains (element))
  8.     return 1;
  9.   else
  10.     return 0;
  11. }
  12.  
  13. template < class Element, class Key >
  14. Boolean IARelation < Element, Key >::
  15. locateNext (Element const&, ICursor& cursor) const
  16. { cursor.invalidate ();
  17.   return False;
  18. }
  19.  
  20. template < class Element, class Key >
  21. INumber IARelation < Element, Key >::
  22. removeAllOccurrences (Element const& element)
  23. { if (remove (element))
  24.     return 1;
  25.   else
  26.     return 0;
  27. }
  28.  
  29. template < class Element, class Key >
  30. Boolean IARelation < Element, Key >::
  31. operator == (IARelation < Element, Key > const& collection) const
  32. { return this->containsAllFrom (collection) &&
  33.      collection.containsAllFrom (*this);
  34. }
  35.  
  36. template < class Element, class Key >
  37. Boolean IARelation < Element, Key >::
  38. operator != (IARelation < Element, Key > const& collection) const
  39. { return ! operator == (collection);
  40. }
  41.  
  42. template < class Element, class Key >
  43. void IARelation < Element, Key >::
  44. unionWith (IARelation < Element, Key > const& collection)
  45. { addAllFrom (collection);
  46. }
  47.  
  48. template < class Element, class Key >
  49. void IARelation < Element, Key >::
  50. intersectionWith (IARelation < Element, Key > const& collection)
  51. { IAEqualityCollection < Element > const* env = &collection;
  52.   removeAll (IAEqualityCollection < Element >::isNotContained, &env);
  53. }
  54.  
  55. template < class Element, class Key >
  56. void IARelation < Element, Key >::
  57. differenceWith (IARelation < Element, Key > const& collection)
  58. { IAEqualityCollection < Element > const* env = &collection;
  59.   removeAll (IAEqualityCollection < Element >::isContained, &env);
  60. }
  61.  
  62. template < class Element, class Key >
  63. void IARelation < Element, Key >::
  64. addUnion (IARelation < Element, Key > const& collection1,
  65.           IARelation < Element, Key > const& collection2)
  66. { addAllFrom (collection1);
  67.   addAllFrom (collection2);
  68. }
  69.  
  70. template < class Element, class Key >
  71. void IARelation < Element, Key >::
  72. addIntersection (IARelation < Element, Key > const& collection1,
  73.                  IARelation < Element, Key > const& collection2)
  74. { ICursor *cursor = collection1.newCursor ();
  75.   forCursor (*cursor) {
  76.     if (collection2.contains (collection1.elementAt (*cursor)))
  77.       add (collection1.elementAt (*cursor));
  78.   }
  79.   delete cursor;
  80. }
  81.  
  82. template < class Element, class Key >
  83. void IARelation < Element, Key >::
  84. addDifference (IARelation < Element, Key > const& collection1,
  85.                IARelation < Element, Key > const& collection2)
  86. { ICursor *cursor = collection1.newCursor ();
  87.   forCursor (*cursor) {
  88.     if (! collection2.contains (collection1.elementAt (*cursor)))
  89.       add (collection1.elementAt (*cursor));
  90.   }
  91.   delete cursor;
  92. }
  93.  
  94.