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

  1. /* Copyright (c) IBM Corp. 1992 */
  2. #include <ibexcept.h>
  3.  
  4. template < class Element, class Key, class ElementOps >
  5. inline void IGHashKeyBag < Element, Key, ElementOps >::
  6. checkNotEmpty () const
  7. {
  8. #ifndef INO_CHECKS
  9.   ICHECK (!isEmpty (), IEmptyException, "collection is empty")
  10. #endif
  11. }
  12.  
  13. template < class Element, class Key, class ElementOps >
  14. inline void IGHashKeyBag < Element, Key, ElementOps >::
  15. checkCursorIsForThis (ICursor const& c) const
  16. {
  17. #ifndef INO_CHECKS
  18.   ICHECK (((Cursor const&)c).ivCollection == this, ICursorInvalidException,
  19.       "cursor not for this collection")
  20. #endif
  21. }
  22.  
  23. template < class Element, class Key, class ElementOps >
  24. inline void IGHashKeyBag < Element, Key, ElementOps >::
  25. checkCursor (ICursor const& c) const
  26. {
  27. #ifndef INO_CHECKS
  28.   ICHECK (((Cursor const&)c).ivCollection == this, ICursorInvalidException,
  29.       "cursor not for this collection")
  30.   ICHECK (c.isValid (), ICursorInvalidException, "invalid cursor")
  31. #endif
  32. #ifdef IALL_CHECKS
  33.   ICHECK (ivImpl.checkNode(((Cursor const&)c).ivNode),
  34.       ICursorInvalidException, "cursor not contained in collection")
  35. #endif
  36. }
  37.  
  38. template < class Element, class Key, class ElementOps >
  39. inline IGHashKeyBag < Element, Key, ElementOps >::
  40. IGHashKeyBag (INumber n, IBoundIndicator b)
  41. : ivImpl(n, &ivOps) {
  42. }
  43.  
  44. template < class Element, class Key, class ElementOps >
  45. inline IGHashKeyBag < Element, Key, ElementOps >::
  46. IGHashKeyBag (IGHashKeyBag < Element, Key, ElementOps > const& h)
  47. :  ivImpl(h.ivImpl, &ivOps) {
  48. }
  49.  
  50. template < class Element, class Key, class ElementOps >
  51. inline IGHashKeyBag < Element, Key, ElementOps >::
  52. ~IGHashKeyBag () {
  53. }
  54.  
  55. template < class Element, class Key, class ElementOps >
  56. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  57. add (Element const& d, ICursor& c) 
  58. { return ivImpl.add
  59.            (&d,
  60.             cvElementOps.keyOps.hash(cvElementOps.key(d), ivImpl.noEntries()),
  61.             ((Cursor&)c).ivImpl
  62.            );
  63. }
  64.  
  65. template < class Element, class Key, class ElementOps >
  66. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  67. add (Element const& d)
  68. { return ivImpl.add
  69.            (&d,
  70.             cvElementOps.keyOps.hash(cvElementOps.key(d), ivImpl.noEntries())
  71.            );
  72. }
  73.  
  74. template < class Element, class Key, class ElementOps >
  75. inline void IGHashKeyBag < Element, Key, ElementOps >::
  76. addAllFrom (IGHashKeyBag < Element, Key, ElementOps > const& h)
  77. {
  78. #ifndef INO_CHECKS
  79.   ICHECK (this != &h,
  80.       IIdenticalCollectionException, "identical collection in addAllFrom")
  81. #endif
  82.   ivImpl.addAllFrom(h.ivImpl);
  83. }
  84.  
  85. template < class Element, class Key, class ElementOps >
  86. inline IGHashKeyBag < Element, Key, ElementOps >&
  87. IGHashKeyBag < Element, Key, ElementOps >::
  88. operator = (IGHashKeyBag < Element, Key, ElementOps > const& h)
  89. { ivImpl = h.ivImpl;
  90.   return *this;
  91. }
  92.  
  93. template < class Element, class Key, class ElementOps >
  94. inline Element const& IGHashKeyBag < Element, Key, ElementOps >::
  95. elementAt (ICursor const& c) const
  96. { checkCursor(c);
  97.   return *(Element const*) ivImpl.elementAt(((Cursor const&)c).ivImpl);
  98. }
  99.  
  100. template < class Element, class Key, class ElementOps >
  101. inline Element& IGHashKeyBag < Element, Key, ElementOps >::
  102. elementAt (ICursor const& c)
  103. { checkCursor(c);
  104.   return *(Element*) ivImpl.elementAt(((Cursor const&)c).ivImpl);
  105. }
  106.  
  107. template < class Element, class Key, class ElementOps >
  108. inline Element const& IGHashKeyBag < Element, Key, ElementOps >::
  109. anyElement () const
  110. { checkNotEmpty();
  111.   return *(Element const*) ivImpl.anyElement();
  112. }
  113.  
  114. template < class Element, class Key, class ElementOps >
  115. inline void IGHashKeyBag < Element, Key, ElementOps >::
  116. removeAt (ICursor const& c)
  117. { checkCursor(c);
  118.   ivImpl.removeAt(((Cursor&)c).ivImpl);
  119. }
  120.  
  121. template < class Element, class Key, class ElementOps >
  122. inline INumber IGHashKeyBag < Element, Key, ElementOps >::
  123. removeAll (Boolean (*predicate) (Element const&, void*), void* env)
  124. { return ivImpl.removeAll (predicate, env);
  125. }
  126.  
  127. template < class Element, class Key, class ElementOps >
  128. inline void IGHashKeyBag < Element, Key, ElementOps >::
  129. replaceAt (ICursor const& c, Element const& d)
  130. { checkCursor(c);
  131.   ivImpl.replaceAt(((Cursor const&)c).ivImpl, &d);
  132. }
  133.  
  134. template < class Element, class Key, class ElementOps >
  135. inline void IGHashKeyBag < Element, Key, ElementOps >::
  136. removeAll ()
  137. { ivImpl.removeAll();
  138. }
  139.  
  140. template < class Element, class Key, class ElementOps >
  141. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  142. isBounded () const
  143. { return ivImpl.isBounded();
  144. }
  145.  
  146. template < class Element, class Key, class ElementOps >
  147. inline INumber IGHashKeyBag < Element, Key, ElementOps >::
  148. maxNumberOfElements () const
  149. { ICHECK (False, INotBoundedException,
  150.           "maxNumberOfElements is undefined for unbounded collection")
  151.   return 0;
  152. }
  153.  
  154. template < class Element, class Key, class ElementOps >
  155. inline INumber IGHashKeyBag < Element, Key, ElementOps >::
  156. numberOfElements () const
  157. { return ivImpl.numberOfElements();
  158. }
  159.  
  160. template < class Element, class Key, class ElementOps >
  161. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  162. isEmpty () const
  163. { return ivImpl.isEmpty();
  164. }
  165.  
  166. template < class Element, class Key, class ElementOps >
  167. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  168. isFull () const
  169. { return ivImpl.isFull();
  170. }
  171.  
  172. template < class Element, class Key, class ElementOps >
  173. inline ICursor* IGHashKeyBag < Element, Key, ElementOps >::
  174. newCursor () const
  175. { return new Cursor (*this);
  176. }
  177.  
  178. template < class Element, class Key, class ElementOps >
  179. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  180. setToFirst (ICursor& c) const
  181. { return ivImpl.setToFirst(((Cursor&)c).ivImpl);
  182. }
  183.  
  184. template < class Element, class Key, class ElementOps >
  185. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  186. setToNext (ICursor& c) const
  187. { checkCursor(c);
  188.   return ivImpl.setToNext(((Cursor&)c).ivImpl);
  189. }
  190.  
  191. template < class Element, class Key, class ElementOps >
  192. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  193. allElementsDo (Boolean (*iterationFunction) (Element const&, void*),
  194.                void* env) const {
  195.   return ivImpl.allElementsDo (iterationFunction, env);
  196. }
  197.  
  198. template < class Element, class Key, class ElementOps >
  199. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  200. allElementsDo (Boolean (*iterationFunction) (Element&, void*), void* env)
  201. { return ivImpl.allElementsDo (iterationFunction, env);
  202. }
  203.  
  204. template < class Element, class Key, class ElementOps >
  205. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  206. allElementsDo (IConstantIterator <Element>& iterator) const
  207. { return ivImpl.allElementsDo (&iterator);
  208. }
  209.  
  210.  
  211. template < class Element, class Key, class ElementOps >
  212. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  213. allElementsDo (IIterator <Element>& iterator)
  214. { return ivImpl.allElementsDo (&iterator);
  215. }
  216.  
  217. template < class Element, class Key, class ElementOps >
  218. inline Key const& IGHashKeyBag < Element, Key, ElementOps >::
  219. key (Element const& element) const
  220. { return cvElementOps.key (element);
  221. }
  222.  
  223. template < class Element, class Key, class ElementOps >
  224. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  225. containsElementWithKey (Key const& k) const
  226. { return ivImpl.containsElementWithKey
  227.            (&k,
  228.             cvElementOps.keyOps.hash(k, ivImpl.noEntries())
  229.            );
  230. }
  231.  
  232. template < class Element, class Key, class ElementOps >
  233. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  234. containsAllKeysFrom (IGHashKeyBag < Element, Key, ElementOps > const& h) const
  235. { return ivImpl.containsAllKeysFrom(h.ivImpl);
  236. }
  237.  
  238. template < class Element, class Key, class ElementOps >
  239. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  240. locateElementWithKey (Key const& k, ICursor& c) const
  241. { checkCursorIsForThis(c);
  242.   return ivImpl.locateElementWithKey
  243.            (&k,
  244.             cvElementOps.keyOps.hash(k, ivImpl.noEntries()),
  245.             ((Cursor&)c).ivImpl
  246.            );
  247. }
  248.  
  249. template < class Element, class Key, class ElementOps >
  250. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  251. replaceElementWithKey (Element const& d, ICursor& c)
  252. { checkCursorIsForThis(c);
  253.   return ivImpl.replaceElementWithKey
  254.            (&d,
  255.             cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries()),
  256.             ((Cursor&)c).ivImpl
  257.            );
  258. }
  259.  
  260. template < class Element, class Key, class ElementOps >
  261. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  262. replaceElementWithKey (Element const& d)
  263. { return ivImpl.replaceElementWithKey
  264.            (&d,
  265.             cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries())
  266.            );
  267. }
  268.  
  269. template < class Element, class Key, class ElementOps >
  270. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  271. locateOrAddElementWithKey (Element const& d, ICursor& c)
  272. { checkCursorIsForThis(c);
  273.   return ivImpl.locateOrAddElementWithKey
  274.            (&d,
  275.             cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries()),
  276.             ((Cursor&)c).ivImpl
  277.            );
  278. }
  279.  
  280. template < class Element, class Key, class ElementOps >
  281. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  282. locateOrAddElementWithKey (Element const& d)
  283. { return ivImpl.locateOrAddElementWithKey
  284.            (&d,
  285.             cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries())
  286.            );
  287. }
  288.  
  289. template < class Element, class Key, class ElementOps >
  290. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  291. addOrReplaceElementWithKey (Element const& d, ICursor& c)
  292. { checkCursorIsForThis(c);
  293.   return ivImpl.addOrReplaceElementWithKey
  294.            (&d,
  295.             cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries()),
  296.             ((Cursor&)c).ivImpl
  297.            );
  298. }
  299.  
  300. template < class Element, class Key, class ElementOps >
  301. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  302. addOrReplaceElementWithKey (Element const& d)
  303. { return ivImpl.addOrReplaceElementWithKey
  304.            (&d,
  305.             cvElementOps.keyOps.hash((cvElementOps.key(d)), ivImpl.noEntries())
  306.            );
  307. }
  308.  
  309. template < class Element, class Key, class ElementOps >
  310. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  311. removeElementWithKey (Key const& k)
  312. { return ivImpl.removeElementWithKey
  313.                 (&k, cvElementOps.keyOps.hash(k, ivImpl.noEntries()));
  314. }
  315.  
  316. template < class Element, class Key, class ElementOps >
  317. inline Element const& IGHashKeyBag < Element, Key, ElementOps >::
  318. elementWithKey (Key const& k) const
  319. { return *(Element const*) ivImpl.elementWithKey
  320.                               (&k, cvElementOps.keyOps.hash(k, ivImpl.noEntries()));
  321. }
  322.  
  323. template < class Element, class Key, class ElementOps >
  324. inline Element& IGHashKeyBag < Element, Key, ElementOps >::
  325. elementWithKey (Key const& k)
  326. { return *(Element*) ivImpl.elementWithKey
  327.                               (&k, cvElementOps.keyOps.hash(k, ivImpl.noEntries()));
  328. }
  329.  
  330. template < class Element, class Key, class ElementOps >
  331. inline INumber IGHashKeyBag < Element, Key, ElementOps >::
  332. numberOfElementsWithKey (Key const& k) const
  333. { return ivImpl.numberOfElementsWithKey
  334.            (&k,
  335.             cvElementOps.keyOps.hash(k, ivImpl.noEntries())
  336.            );
  337. }
  338.  
  339. template < class Element, class Key, class ElementOps >
  340. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  341. locateNextElementWithKey (Key const& k, ICursor& c) const
  342. { checkCursor(c);
  343.   return ivImpl.locateNextElementWithKey
  344.            (&k,
  345.             cvElementOps.keyOps.hash(k, ivImpl.noEntries()),
  346.             ((Cursor&)c).ivImpl
  347.            );
  348. }
  349.  
  350. template < class Element, class Key, class ElementOps >
  351. inline INumber IGHashKeyBag < Element, Key, ElementOps >::
  352. removeAllElementsWithKey (Key const& k)
  353. { return ivImpl.removeAllElementsWithKey
  354.                 (&k, cvElementOps.keyOps.hash(k, ivImpl.noEntries()));
  355. }
  356.  
  357. template < class Element, class Key, class ElementOps >
  358. inline INumber IGHashKeyBag < Element, Key, ElementOps >::
  359. numberOfDifferentKeys() const
  360. { return ivImpl.numberOfDifferentKeys ();
  361. }
  362.  
  363. template < class Element, class Key, class ElementOps >
  364. inline Boolean IGHashKeyBag < Element, Key, ElementOps >::
  365. setToNextWithDifferentKey (ICursor& c) const
  366. { return ivImpl.setToNextWithDifferentKey (((Cursor&)c).ivImpl);
  367. }
  368.