home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / iikssbst.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  10.4 KB  |  309 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. #include <new.h>
  19.  
  20. #pragma info (nocls, nocnd, nocns, nocnv, noext, nognr, novft)
  21. #pragma pack (4)
  22.  
  23. // -------------------------
  24. // IKeySortedSetAsBstTreeOps
  25. // -------------------------
  26.  
  27. // public members
  28.  
  29. template <class Element, class Key,
  30.           class ElementOps, class Implementation, size_t nodeSize>
  31. IKeySortedSetAsBstTreeOps <Element, Key,
  32.                            ElementOps, Implementation, nodeSize>::
  33. IKeySortedSetAsBstTreeOps (INumber numberOfElements)
  34. : Inherited (__isDTSClass (Element)),
  35.   ivElementOps (),
  36.   ivImpl (*this, numberOfElements)
  37. {
  38. }
  39.  
  40. template <class Element, class Key,
  41.           class ElementOps, class Implementation, size_t nodeSize>
  42. IKeySortedSetAsBstTreeOps <Element, Key,
  43.                            ElementOps, Implementation, nodeSize>::
  44. IKeySortedSetAsBstTreeOps (INumber numberOfElements, void* opsArg)
  45. : Inherited (__isDTSClass (Element)),
  46.   ivElementOps (opsArg),
  47.   ivImpl (*this, numberOfElements)
  48. {
  49. }
  50.  
  51. template <class Element, class Key,
  52.           class ElementOps, class Implementation, size_t nodeSize>
  53. IKeySortedSetAsBstTreeOps <Element, Key,
  54.                            ElementOps, Implementation, nodeSize>::
  55. IKeySortedSetAsBstTreeOps
  56.   (IKeySortedSetAsBstTreeOps
  57.     <Element, Key,
  58.      ElementOps, Implementation, nodeSize> const& collection)
  59. : Inherited (__isDTSClass (Element)),
  60.   ivElementOps (collection.ivElementOps),
  61.   ivImpl (*this, collection.ivImpl)
  62. {
  63. }
  64.  
  65. template <class Element, class Key,
  66.           class ElementOps, class Implementation, size_t nodeSize>
  67. IKeySortedSetAsBstTreeOps <Element, Key,
  68.                            ElementOps, Implementation, nodeSize>::
  69. ~IKeySortedSetAsBstTreeOps ()
  70. {
  71. }
  72.  
  73. template <class Element, class Key,
  74.           class ElementOps, class Implementation, size_t nodeSize>
  75. void
  76. IKeySortedSetAsBstTreeOps <Element, Key,
  77.                            ElementOps, Implementation, nodeSize>::
  78. Assign (void* element1, void const* element2) const
  79. { ivElementOps.Assign (*(Element*)element1,
  80.                        *(Element const*)element2);
  81. }
  82.  
  83. template <class Element, class Key,
  84.           class ElementOps, class Implementation, size_t nodeSize>
  85. IACollectionImpl*
  86. IKeySortedSetAsBstTreeOps <Element, Key,
  87.                            ElementOps, Implementation, nodeSize>::
  88. Clone () const
  89. { return (Implementation*) *new Self (*this);
  90. }
  91.  
  92. template <class Element, class Key,
  93.           class ElementOps, class Implementation, size_t nodeSize>
  94. long
  95. IKeySortedSetAsBstTreeOps <Element, Key,
  96.                            ElementOps, Implementation, nodeSize>::
  97. CompareKeys (void const* arg1, void const* arg2, IArgType argType) const
  98. { long comp;
  99.   switch (argType) {
  100.     case kElementElement: {
  101.       comp = ivElementOps.keyOps.Compare
  102.         (ivElementOps.Key (*(Element const*)arg1),
  103.          ivElementOps.Key (*(Element const*)arg2));
  104.       break;
  105.     }
  106.     case kElementKey: {
  107.       comp = ivElementOps.keyOps.Compare
  108.         (ivElementOps.Key (*(Element const*)arg1),
  109.          IKeyForOps ((Key const*)arg2));
  110.       break;
  111.     }
  112.     case kKeyKey: {
  113.       comp = ivElementOps.keyOps.Compare
  114.         (IKeyForOps ((Key const*)arg1), IKeyForOps ((Key const*)arg2));
  115.       break;
  116.     }
  117.   }
  118.   return comp;
  119. }
  120.  
  121. template <class Element, class Key,
  122.           class ElementOps, class Implementation, size_t nodeSize>
  123. long
  124. IKeySortedSetAsBstTreeOps <Element, Key,
  125.                            ElementOps, Implementation, nodeSize>::
  126. CompareKeys (void const* key, INumber index,
  127.              void const* arg, IArgType argType) const
  128. { long comp;
  129.   switch (argType) {
  130.     case kKey: {
  131.       comp = ivElementOps.keyOps.Compare
  132.         (((Key const*)key) [index], IKeyForOps ((Key const*)arg));
  133.       break;
  134.     }
  135.     case kElement: {
  136.       comp = ivElementOps.keyOps.Compare
  137.         (((Key const*)key) [index],
  138.          ivElementOps.Key (*(Element const*)arg));
  139.       break;
  140.     }
  141.   }
  142.   return comp;
  143. }
  144.  
  145. template <class Element, class Key,
  146.           class ElementOps, class Implementation, size_t nodeSize>
  147. void 
  148. IKeySortedSetAsBstTreeOps <Element, Key,
  149.                            ElementOps, Implementation, nodeSize>::
  150. CopyKey (void* to, INumber toIndex,
  151.          void const* from, INumber fromIndex) const
  152. { ((Key*)to) [toIndex] = ((Key*)from) [fromIndex];
  153. }
  154.  
  155. template <class Element, class Key,
  156.           class ElementOps, class Implementation, size_t nodeSize>
  157. void*
  158. IKeySortedSetAsBstTreeOps <Element, Key,
  159.                            ElementOps, Implementation, nodeSize>::
  160. CreateINode (void const* inode) const
  161. { void* node = ivElementOps.Allocate (sizeof (INode)
  162. #if defined (__DEBUG_ALLOC__)
  163.                                       , __FILE__, __LINE__
  164. #endif
  165.                                      );
  166.   ivImpl.CheckPointer (node);
  167.  
  168.   if (inode == 0) {
  169.     node = new (node) INode;
  170.   }
  171.   else {
  172.     node = new (node) INode (*(INode*)inode);
  173.  
  174.     for (INumber i = 0; i < ((INode*)node)->ivm; i++)
  175.       ((INode*)node)->ivPtrs [i] = ((INode*)inode)->ivPtrs [i];
  176.     for (i = 0; i < ((INode*)node)->ivm - 1; i++)
  177.       ((INode*)node)->ivKeys [i] = ((INode*)inode)->ivKeys [i];
  178.   }
  179.   return node;
  180. }
  181.  
  182. template <class Element, class Key,
  183.           class ElementOps, class Implementation, size_t nodeSize>
  184. void*
  185. IKeySortedSetAsBstTreeOps <Element, Key,
  186.                            ElementOps, Implementation, nodeSize>::
  187. CreateKey () const
  188. { return new Key;
  189. }
  190.  
  191. template <class Element, class Key,
  192.           class ElementOps, class Implementation, size_t nodeSize>
  193. void*
  194. IKeySortedSetAsBstTreeOps <Element, Key,
  195.                            ElementOps, Implementation, nodeSize>::
  196. CreateLNode (void const* element) const
  197. { void* node = ivElementOps.Allocate (sizeof (LNode)
  198. #if defined (__DEBUG_ALLOC__)
  199.                                       , __FILE__, __LINE__
  200. #endif
  201.                                      );
  202.   return
  203.     new (ivImpl.CheckPointer (node)) LNode (*(Element const*)element);
  204. }
  205.  
  206. template <class Element, class Key,
  207.           class ElementOps, class Implementation, size_t nodeSize>
  208. void
  209. IKeySortedSetAsBstTreeOps <Element, Key,
  210.                            ElementOps, Implementation, nodeSize>::
  211. DeleteINode (void* inode) const
  212. { ((INode*)inode)->~INode ();
  213.   ivElementOps.Deallocate (inode
  214. #if defined (__DEBUG_ALLOC__)
  215.                            , __FILE__, __LINE__
  216. #endif
  217.                           );
  218. }
  219.  
  220. template <class Element, class Key,
  221.           class ElementOps, class Implementation, size_t nodeSize>
  222. void
  223. IKeySortedSetAsBstTreeOps <Element, Key,
  224.                            ElementOps, Implementation, nodeSize>::
  225. DeleteKey (void* key) const
  226. { delete (Key*)key;
  227. }
  228.  
  229. template <class Element, class Key,
  230.           class ElementOps, class Implementation, size_t nodeSize>
  231. void
  232. IKeySortedSetAsBstTreeOps <Element, Key,
  233.                            ElementOps, Implementation, nodeSize>::
  234. DeleteLNode (void* lnode) const
  235. { ((LNode*)lnode)->~LNode ();
  236.   ivElementOps.Deallocate (lnode
  237. #if defined (__DEBUG_ALLOC__)
  238.                            , __FILE__, __LINE__
  239. #endif
  240.                           );
  241. }
  242.  
  243. template <class Element, class _Key,
  244.           class ElementOps, class Implementation, size_t nodeSize>
  245. void*
  246. IKeySortedSetAsBstTreeOps <Element, _Key,
  247.                            ElementOps, Implementation, nodeSize>::
  248. Key (void const* element) const
  249. { return IKeyFromOps (ivElementOps.Key (*(Element const*)element));
  250. }
  251.  
  252. template <class Element, class Key,
  253.           class ElementOps, class Implementation, size_t nodeSize>
  254. void*
  255. IKeySortedSetAsBstTreeOps <Element, Key,
  256.                            ElementOps, Implementation, nodeSize>::
  257. StreamIn (TStream& fromWhere) const
  258. { Element* element = ivElementOps.GetStreamable ();
  259.   ivElementOps.StreamIn (*element, fromWhere);
  260.   return (void*) element;
  261. }
  262.  
  263. template <class Element, class Key,
  264.           class ElementOps, class Implementation, size_t nodeSize>
  265. void
  266. IKeySortedSetAsBstTreeOps <Element, Key,
  267.                            ElementOps, Implementation, nodeSize>::
  268. StreamOut (void const* element, TStream& toWhere) const
  269. { ivElementOps.StreamOut (*(Element const*)element, toWhere);
  270. }
  271.  
  272. template <class Element, class Key,
  273.           class ElementOps, class Implementation, size_t nodeSize>
  274. TStream&
  275. IKeySortedSetAsBstTreeOps <Element, Key,
  276.                            ElementOps, Implementation, nodeSize>::
  277. operator<<= (TStream& fromWhere)
  278. { return (ivElementOps <<= fromWhere);
  279. }
  280.  
  281. template <class Element, class Key,
  282.           class ElementOps, class Implementation, size_t nodeSize>
  283. TStream&
  284. IKeySortedSetAsBstTreeOps <Element, Key,
  285.                            ElementOps, Implementation, nodeSize>::
  286. operator>>= (TStream& toWhere) const
  287. { return (ivElementOps >>= toWhere);
  288. }
  289.  
  290. template <class Element, class Key,
  291.           class ElementOps, class Implementation, size_t nodeSize>
  292. IKeySortedSetAsBstTreeOps <Element, Key,
  293.                            ElementOps, Implementation, nodeSize>::
  294. operator INumber () const
  295. { return IBSTORDER;
  296. }
  297.  
  298. template <class Element, class Key,
  299.           class ElementOps, class Implementation, size_t nodeSize>
  300. IKeySortedSetAsBstTreeOps <Element, Key,
  301.                            ElementOps, Implementation, nodeSize>::
  302. operator Implementation* ()
  303. { ivImpl.CheckPointer (this);
  304.   return &ivImpl;
  305. }
  306.  
  307. #pragma info (restore)
  308. #pragma pack ()
  309.