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