home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / iivksb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  7.1 KB  |  258 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. #pragma info (nocls, nocnd, nocns, nocnv, noext, nognr, novft)
  19. #pragma pack (4)
  20.  
  21. // ---
  22. // IVKeySortedBagImpl
  23. // ---
  24.  
  25. // public members
  26.  
  27. template <class VInherited>
  28. IVKeySortedBagImpl <VInherited>::
  29. IVKeySortedBagImpl (Ops& ops, INumber numberOfElements)
  30. : VInherited (ops, numberOfElements)
  31. {
  32. }
  33.  
  34. template <class VInherited>
  35. IVKeySortedBagImpl <VInherited>::
  36. IVKeySortedBagImpl
  37.   (Ops& ops, IVKeySortedBagImpl <VInherited> const& collection)
  38. : VInherited (ops, collection)
  39. {
  40. }
  41.  
  42. template <class VInherited>
  43. IBoolean
  44. IVKeySortedBagImpl <VInherited>::
  45. Add (void const* element, ICursorImpl& cursor)
  46. { IBoolean isEnabled = IsEnabledForNotification ();
  47.   DisableNotification ();
  48.   IBoolean hasBeenAdded = VInherited::Add (element, cursor);
  49.   EnableNotification (isEnabled);
  50.   if (hasBeenAdded && HasObservers ()) {
  51.     NotifyOfAddAt (cursor);
  52.   }
  53.   return hasBeenAdded;
  54. }
  55.  
  56. template <class VInherited>
  57. void
  58. IVKeySortedBagImpl <VInherited>::
  59. AddAllFrom (IACollectionImpl const& collection)
  60. { IBoolean isEnabled = IsEnabledForNotification ();
  61.   DisableNotification ();
  62.   VInherited::AddAllFrom (collection);
  63.   EnableNotification (isEnabled);
  64.   if (HasObservers ()) {
  65.     NotifyOfModification ();
  66.   }
  67. }
  68.  
  69. template <class VInherited>
  70. IBoolean
  71. IVKeySortedBagImpl <VInherited>::
  72. AddOrReplaceElementWithKey (void const* element, ICursorImpl& cursor)
  73. { IBoolean hasBeenAdded = false;
  74.   if (VInherited::LocateElementWithKey (Key (element), cursor)) {
  75.     if (HasObservers ()) {
  76. #if defined (ICLCC_COMPAT_IVB)
  77.       NotifyOfRemoveAt (cursor); // to be removed in a future release
  78. #else
  79.       NotifyOfReplaceAt (cursor, element);
  80. #endif
  81.     }
  82.     VInherited::ReplaceAt (cursor, element);
  83. #if defined (ICLCC_COMPAT_IVB)
  84.     if (HasObservers ()) {
  85.       NotifyOfAddAt (cursor); // to be removed in a future release
  86.     }
  87. #endif
  88.   }
  89.   else {
  90.     hasBeenAdded = VInherited::Add (element, cursor);
  91.     if (HasObservers ()) {
  92.       NotifyOfAddAt (cursor);
  93.     }
  94.   }
  95.   return hasBeenAdded;
  96. }
  97.  
  98. template <class VInherited>
  99. void
  100. IVKeySortedBagImpl <VInherited>::
  101. Copy (IACollectionImpl const& collection)
  102. { IBoolean isEnabled = IsEnabledForNotification ();
  103.   DisableNotification ();
  104.   VInherited::Copy (collection);
  105.   EnableNotification (isEnabled);
  106.   if (HasObservers ()) {
  107.     NotifyOfModification ();
  108.   }
  109. }
  110.  
  111. template <class VInherited>
  112. IBoolean
  113. IVKeySortedBagImpl <VInherited>::
  114. LocateOrAddElementWithKey (void const* key, ICursorImpl& cursor)
  115. { IBoolean isEnabled = IsEnabledForNotification ();
  116.   DisableNotification ();
  117.   IBoolean hasBeenLocated =
  118.     VInherited::LocateOrAddElementWithKey (key, cursor);
  119.   EnableNotification (isEnabled);
  120.   if (!hasBeenLocated && HasObservers ()) {
  121.     NotifyOfAddAt (cursor);
  122.   }
  123.   return hasBeenLocated;
  124. }
  125.  
  126. template <class VInherited>
  127. INumber
  128. IVKeySortedBagImpl <VInherited>::
  129. RemoveAll ()
  130. { INumber result = VInherited::RemoveAll ();
  131.   if (result > 0 && HasObservers ()) {
  132.     NotifyOfModification ();
  133.   }
  134.   return result;
  135. }
  136.  
  137. template <class VInherited>
  138. INumber
  139. IVKeySortedBagImpl <VInherited>::
  140. RemoveAll (IPredFunc predFunc, void* addArg)
  141. { INumber result = VInherited::RemoveAll (predFunc, addArg);
  142.   if (result > 0 && HasObservers ()) {
  143.     NotifyOfModification ();
  144.   }
  145.   return result;
  146. }
  147.  
  148. template <class VInherited>
  149. INumber
  150. IVKeySortedBagImpl <VInherited>::
  151. RemoveAllElementsWithKey (void const* key)
  152. { IBoolean isEnabled = IsEnabledForNotification ();
  153.   DisableNotification ();
  154.   INumber result = VInherited::RemoveAllElementsWithKey (key);
  155.   EnableNotification (isEnabled);
  156.   if (result > 0 && HasObservers ()) {
  157.     NotifyOfModification ();
  158.   }
  159.   return result;
  160. }
  161.  
  162. template <class VInherited>
  163. void
  164. IVKeySortedBagImpl <VInherited>::
  165. RemoveAt (ICursorImpl& cursor)
  166. { if (HasObservers ()) {
  167.     NotifyOfRemoveAt (cursor);
  168.   }
  169.   VInherited::RemoveAt (cursor);
  170. }
  171.  
  172. template <class VInherited>
  173. IBoolean
  174. IVKeySortedBagImpl <VInherited>::
  175. RemoveElementWithKey (void const* key)
  176. { if (HasObservers () &&
  177.       LocateElementWithKey (key, CursorOf (*this))) {
  178.     NotifyOfRemoveAt (CursorOf (*this));
  179.   }
  180.   return VInherited::RemoveElementWithKey (key);
  181. }
  182.  
  183. template <class VInherited>
  184. void
  185. IVKeySortedBagImpl <VInherited>::
  186. RemoveAtPosition (IPosition position)
  187. { if (HasObservers ()) {
  188.     SetToPosition (position, CursorOf (*this));
  189.     NotifyOfRemoveAt (CursorOf (*this));
  190.   }
  191.   VInherited::RemoveAtPosition (position);
  192. }
  193.  
  194. template <class VInherited>
  195. void
  196. IVKeySortedBagImpl <VInherited>::
  197. RemoveFirst ()
  198. { if (HasObservers ()) {
  199.     SetToFirst (CursorOf (*this));
  200.     NotifyOfRemoveAt (CursorOf (*this));
  201.   }
  202.   VInherited::RemoveFirst ();
  203. }
  204.  
  205. template <class VInherited>
  206. void
  207. IVKeySortedBagImpl <VInherited>::
  208. RemoveLast ()
  209. { if (HasObservers ()) {
  210.     SetToLast (CursorOf (*this));
  211.     NotifyOfRemoveAt (CursorOf (*this));
  212.   }
  213.   VInherited::RemoveLast ();
  214. }
  215.  
  216. template <class VInherited>
  217. void
  218. IVKeySortedBagImpl <VInherited>::
  219. ReplaceAt (ICursorImpl const& cursor, void const* element)
  220. { if (HasObservers ()) {
  221. #if defined (ICLCC_COMPAT_IVB)
  222.     NotifyOfRemoveAt (cursor); // to be removed in a future release
  223. #else
  224.     NotifyOfReplaceAt (cursor, element);
  225. #endif
  226.   }
  227.   VInherited::ReplaceAt (cursor, element);
  228. #if defined (ICLCC_COMPAT_IVB)
  229.   if (HasObservers ()) {
  230.     NotifyOfAddAt (cursor); // to be removed in a future release
  231.   }
  232. #endif
  233. }
  234.  
  235. template <class VInherited>
  236. IBoolean
  237. IVKeySortedBagImpl <VInherited>::
  238. ReplaceElementWithKey (void const* element, ICursorImpl& cursor)
  239. { if (HasObservers ()) {
  240. #if defined (ICLCC_COMPAT_IVB)
  241.     NotifyOfRemoveAt (cursor); // to be removed in a future release
  242. #else
  243.     NotifyOfReplaceAt (cursor, element);
  244. #endif
  245.   }
  246.   IBoolean hasBeenReplaced =
  247.     VInherited::ReplaceElementWithKey (element, cursor);
  248. #if defined (ICLCC_COMPAT_IVB)
  249.   if (HasObservers ()) {
  250.     NotifyOfAddAt (cursor); // to be removed in a future release
  251.   }
  252. #endif
  253.   return hasBeenReplaced;
  254. }
  255.  
  256. #pragma info (restore)
  257. #pragma pack ()
  258.