home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / IHSHKS.IF < prev    next >
Text File  |  1993-09-22  |  12KB  |  348 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, class ElementOps >
  15. inline void IGHashKeySet < Element, Key, ElementOps >::
  16. checkNotEmpty () const
  17. {
  18. #ifndef INO_CHECKS
  19.   ICHECK (!isEmpty (), IEmptyException, ICollectionIsEmptyText)
  20. #endif
  21. }
  22.  
  23. template < class Element, class Key, class ElementOps >
  24. inline void IGHashKeySet < Element, Key, ElementOps >::
  25. checkCursorIsForThis (ICursor const& c) const
  26. {
  27. #ifndef INO_CHECKS
  28.   ICHECK (((Cursor const&)c).isFor (*this), ICursorInvalidException,
  29.           ICursorNotForThisText)
  30. #endif
  31. }
  32.  
  33. template < class Element, class Key, class ElementOps >
  34. inline void IGHashKeySet < Element, Key, ElementOps >::
  35. checkCursor (ICursor const& c) const
  36. {
  37. #ifndef INO_CHECKS
  38.   ICHECK (((Cursor const&)c).isFor (*this), ICursorInvalidException,
  39.           ICursorNotForThisText)
  40.   ICHECK (c.isValid (), ICursorInvalidException, IInvalidCursorText)
  41. #endif
  42. #ifdef IALL_CHECKS
  43.   ICHECK (ivImpl.checkCursor(((Cursor const&)c).ivImpl),
  44.           ICursorInvalidException, ICursorNotContainedText)
  45. #endif
  46. }
  47.  
  48. template < class Element, class Key, class ElementOps >
  49. inline IGHashKeySet < Element, Key, ElementOps >::
  50. IGHashKeySet (INumber n)
  51. : ivImpl(n, &ivOps) {
  52. }
  53.  
  54. template < class Element, class Key, class ElementOps >
  55. inline IGHashKeySet < Element, Key, ElementOps >::
  56. IGHashKeySet (IGHashKeySet < Element, Key, ElementOps > const& h)
  57. :  ivImpl(h.ivImpl, &ivOps) {
  58. }
  59.  
  60. template < class Element, class Key, class ElementOps >
  61. inline IGHashKeySet < Element, Key, ElementOps >::
  62. ~IGHashKeySet () {
  63. }
  64.  
  65. template < class Element, class Key, class ElementOps >
  66. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  67. add (Element const& e, ICursor& c)
  68. { return ! locateOrAddElementWithKey (e, c);
  69. }
  70.  
  71. template < class Element, class Key, class ElementOps >
  72. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  73. add (Element const& e)
  74. { return ! locateOrAddElementWithKey (e);
  75. }
  76.  
  77. template < class Element, class Key, class ElementOps >
  78. inline void IGHashKeySet < Element, Key, ElementOps >::
  79. addAllFrom (IGHashKeySet < Element, Key, ElementOps > const& h)
  80. {
  81. #ifndef INO_CHECKS
  82.   ICHECK (this != &h,
  83.           IIdenticalCollectionException, IIdenticalCollectionText)
  84. #endif
  85.   Cursor cursor (h);
  86.   forCursor (cursor) add (h.elementAt (cursor));
  87. };
  88.  
  89. template < class Element, class Key, class ElementOps >
  90. inline IGHashKeySet < Element, Key, ElementOps >&
  91. IGHashKeySet < Element, Key, ElementOps >::
  92. operator = (IGHashKeySet < Element, Key, ElementOps > const& h)
  93. { ivImpl = h.ivImpl;
  94.   return *this;
  95. }
  96.  
  97. template < class Element, class Key, class ElementOps >
  98. inline Element const& IGHashKeySet < Element, Key, ElementOps >::
  99. elementAt (ICursor const& c) const
  100. { checkCursor(c);
  101.   return *(Element const*) ivImpl.elementAt(((Cursor const&)c).ivImpl);
  102. }
  103.  
  104. template < class Element, class Key, class ElementOps >
  105. inline Element& IGHashKeySet < Element, Key, ElementOps >::
  106. elementAt (ICursor const& c)
  107. { checkCursor(c);
  108.   return *(Element*) ivImpl.elementAt(((Cursor const&)c).ivImpl);
  109. }
  110.  
  111. template < class Element, class Key, class ElementOps >
  112. inline Element const& IGHashKeySet < Element, Key, ElementOps >::
  113. anyElement () const
  114. { checkNotEmpty();
  115.   return *(Element const*) ivImpl.anyElement();
  116. }
  117.  
  118. template < class Element, class Key, class ElementOps >
  119. inline void IGHashKeySet < Element, Key, ElementOps >::
  120. removeAt (ICursor const& c)
  121. { checkCursor(c);
  122.   ivImpl.removeAt(((Cursor&)c).ivImpl);
  123. }
  124.  
  125. template < class Element, class Key, class ElementOps >
  126. inline INumber IGHashKeySet < Element, Key, ElementOps >::
  127. removeAll (IBoolean (*predicate) (Element const&, void*), void* env)
  128. { return ivImpl.removeAll (predicate, env);
  129. }
  130.  
  131. template < class Element, class Key, class ElementOps >
  132. inline void IGHashKeySet < Element, Key, ElementOps >::
  133. replaceAt (ICursor const& c, Element const& e)
  134. { checkCursor(c);
  135. #ifndef INO_CHECKS
  136.   ICHECK (elementOps().keyOps.equal
  137.            (elementOps().key
  138.              (((Node const*)((Cursor const&)c).ivImpl.ivNode)->ivElement),
  139.             elementOps().key (e)),
  140.           IInvalidReplacementException, IInvalidReplacementText)
  141. #endif
  142.   ivImpl.replaceAt(((Cursor const&)c).ivImpl, &e);
  143. }
  144.  
  145. template < class Element, class Key, class ElementOps >
  146. inline void IGHashKeySet < Element, Key, ElementOps >::
  147. removeAll ()
  148. { ivImpl.removeAll();
  149. }
  150.  
  151. template < class Element, class Key, class ElementOps >
  152. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  153. isBounded () const
  154. { return ivImpl.isBounded();
  155. }
  156.  
  157. template < class Element, class Key, class ElementOps >
  158. inline INumber IGHashKeySet < Element, Key, ElementOps >::
  159. maxNumberOfElements () const
  160. { ICHECK (False, INotBoundedException,
  161.           INotBoundedText)
  162.   return 0;
  163. }
  164.  
  165. template < class Element, class Key, class ElementOps >
  166. inline INumber IGHashKeySet < Element, Key, ElementOps >::
  167. numberOfElements () const
  168. { return ivImpl.numberOfElements();
  169. }
  170.  
  171. template < class Element, class Key, class ElementOps >
  172. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  173. isEmpty () const
  174. { return ivImpl.isEmpty();
  175. }
  176.  
  177. template < class Element, class Key, class ElementOps >
  178. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  179. isFull () const
  180. { return ivImpl.isFull();
  181. }
  182.  
  183. template < class Element, class Key, class ElementOps >
  184. inline ICursor* IGHashKeySet < Element, Key, ElementOps >::
  185. newCursor () const
  186. { ICursor* result = new Cursor (*this);
  187.   ICHECK (result != 0, IOutOfMemory, IOutOfMemoryText)
  188.   return result;
  189. }
  190.  
  191. template < class Element, class Key, class ElementOps >
  192. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  193. setToFirst (ICursor& c) const
  194. { checkCursorIsForThis(c);
  195.   return ivImpl.setToFirst(((Cursor&)c).ivImpl);
  196. }
  197.  
  198. template < class Element, class Key, class ElementOps >
  199. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  200. setToNext (ICursor& c) const
  201. { checkCursor(c);
  202.   return ivImpl.setToNext(((Cursor&)c).ivImpl);
  203. }
  204.  
  205. template < class Element, class Key, class ElementOps >
  206. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  207. allElementsDo (IBoolean (*iterationFunction) (Element const&, void*),
  208.                void* env) const {
  209.   return ivImpl.allElementsDo (iterationFunction, env);
  210. }
  211.  
  212. template < class Element, class Key, class ElementOps >
  213. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  214. allElementsDo (IBoolean (*iterationFunction) (Element&, void*), void* env)
  215. { return ivImpl.allElementsDo (iterationFunction, env);
  216. }
  217.  
  218. template < class Element, class Key, class ElementOps >
  219. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  220. allElementsDo (IConstantIterator <Element>& iterator) const
  221. { return ivImpl.allElementsDo (&iterator);
  222. }
  223.  
  224. template < class Element, class Key, class ElementOps >
  225. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  226. allElementsDo (IIterator <Element>& iterator)
  227. { return ivImpl.allElementsDo (&iterator);
  228. }
  229.  
  230. template < class Element, class Key, class ElementOps >
  231. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  232. isConsistent () const
  233. { return ivImpl.isConsistent ();
  234. }
  235.  
  236. template < class Element, class Key, class ElementOps >
  237. inline Key const& IGHashKeySet < Element, Key, ElementOps >::
  238. key (Element const& element) const
  239. { return elementOps().key (element);
  240. }
  241.  
  242. template < class Element, class Key, class ElementOps >
  243. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  244. containsElementWithKey (Key const& k) const
  245. { return ivImpl.containsElementWithKey
  246.            (&k,
  247.             elementOps().keyOps.hash(k, ivImpl.noEntries())
  248.            );
  249. }
  250.  
  251. template < class Element, class Key, class ElementOps >
  252. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  253. containsAllKeysFrom (IGHashKeySet < Element, Key, ElementOps > const& h) const
  254. { return ivImpl.containsAllKeysFrom(h.ivImpl);
  255. }
  256.  
  257. template < class Element, class Key, class ElementOps >
  258. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  259. locateElementWithKey (Key const& k, ICursor& c) const
  260. { checkCursorIsForThis(c);
  261.   return ivImpl.locateElementWithKey
  262.            (&k,
  263.             elementOps().keyOps.hash(k, ivImpl.noEntries()),
  264.             ((Cursor&)c).ivImpl
  265.            );
  266. }
  267.  
  268. template < class Element, class Key, class ElementOps >
  269. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  270. replaceElementWithKey (Element const& e, ICursor& c)
  271. { checkCursorIsForThis(c);
  272.   return ivImpl.replaceElementWithKey
  273.            (&e,
  274.             elementOps().keyOps.hash((elementOps().key(e)), ivImpl.noEntries()),
  275.             ((Cursor&)c).ivImpl
  276.            );
  277. }
  278.  
  279. template < class Element, class Key, class ElementOps >
  280. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  281. replaceElementWithKey (Element const& e)
  282. { return ivImpl.replaceElementWithKey
  283.            (&e,
  284.             elementOps().keyOps.hash((elementOps().key(e)), ivImpl.noEntries())
  285.            );
  286. }
  287.  
  288. template < class Element, class Key, class ElementOps >
  289. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  290. locateOrAddElementWithKey (Element const& e, ICursor& c)
  291. { checkCursorIsForThis(c);
  292.   return ivImpl.locateOrAddElementWithKey
  293.            (&e,
  294.             elementOps().keyOps.hash((elementOps().key(e)), ivImpl.noEntries()),
  295.             ((Cursor&)c).ivImpl
  296.            );
  297. }
  298.  
  299. template < class Element, class Key, class ElementOps >
  300. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  301. locateOrAddElementWithKey (Element const& e)
  302. { return ivImpl.locateOrAddElementWithKey
  303.            (&e,
  304.             elementOps().keyOps.hash((elementOps().key(e)), ivImpl.noEntries())
  305.            );
  306. }
  307.  
  308. template < class Element, class Key, class ElementOps >
  309. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  310. addOrReplaceElementWithKey (Element const& e, ICursor& c)
  311. { checkCursorIsForThis(c);
  312.   return ivImpl.addOrReplaceElementWithKey
  313.            (&e,
  314.             elementOps().keyOps.hash((elementOps().key(e)), ivImpl.noEntries()),
  315.             ((Cursor&)c).ivImpl
  316.            );
  317. }
  318.  
  319. template < class Element, class Key, class ElementOps >
  320. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  321. addOrReplaceElementWithKey (Element const& e)
  322. { return ivImpl.addOrReplaceElementWithKey
  323.            (&e,
  324.             elementOps().keyOps.hash((elementOps().key(e)), ivImpl.noEntries())
  325.            );
  326. }
  327.  
  328. template < class Element, class Key, class ElementOps >
  329. inline IBoolean IGHashKeySet < Element, Key, ElementOps >::
  330. removeElementWithKey (Key const& k)
  331. { return ivImpl.removeElementWithKey
  332.                 (&k, elementOps().keyOps.hash(k, ivImpl.noEntries()));
  333. }
  334.  
  335. template < class Element, class Key, class ElementOps >
  336. inline Element const& IGHashKeySet < Element, Key, ElementOps >::
  337. elementWithKey (Key const& k) const
  338. { return *(Element const*) ivImpl.elementWithKey
  339.                               (&k, elementOps().keyOps.hash(k, ivImpl.noEntries()));
  340. }
  341.  
  342. template < class Element, class Key, class ElementOps >
  343. inline Element& IGHashKeySet < Element, Key, ElementOps >::
  344. elementWithKey (Key const& k)
  345. { return *(Element*) ivImpl.elementWithKey
  346.                               (&k, elementOps().keyOps.hash(k, ivImpl.noEntries()));
  347. }
  348.