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