home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / include / iikbhsh.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  7.7 KB  |  239 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. // IKeyBagAsHshTableOps
  25. // --------------------
  26.  
  27. // public members
  28.  
  29. template <class Element, class Key,
  30.           class ElementOps, class Implementation>
  31. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  32. IKeyBagAsHshTableOps (INumber numberOfElements)
  33. : Inherited (__isDTSClass (Element)),
  34.   ivElementOps (),
  35.   ivImpl (*this, numberOfElements)
  36. {
  37. }
  38.  
  39. template <class Element, class Key,
  40.           class ElementOps, class Implementation>
  41. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  42. IKeyBagAsHshTableOps (INumber numberOfElements, void* opsArg)
  43. : Inherited (__isDTSClass (Element)),
  44.   ivElementOps (opsArg),
  45.   ivImpl (*this, numberOfElements)
  46. {
  47. }
  48.  
  49. template <class Element, class Key,
  50.           class ElementOps, class Implementation>
  51. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  52. IKeyBagAsHshTableOps
  53.   (IKeyBagAsHshTableOps
  54.     <Element, Key, ElementOps, Implementation> const& collection)
  55. : Inherited (__isDTSClass (Element)),
  56.   ivElementOps (collection.ivElementOps),
  57.   ivImpl (*this, collection.ivImpl)
  58. {
  59. }
  60.  
  61. template <class Element, class Key,
  62.           class ElementOps, class Implementation>
  63. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  64. ~IKeyBagAsHshTableOps ()
  65. {
  66. }
  67.  
  68. template <class Element, class Key,
  69.           class ElementOps, class Implementation>
  70. void
  71. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  72. Assign (void* element1, void const* element2) const
  73. { ivElementOps.Assign (*(Element*)element1,
  74.                        *(Element const*)element2);
  75. }
  76.  
  77. template <class Element, class _Key,
  78.           class ElementOps, class Implementation>
  79. IACollectionImpl*
  80. IKeyBagAsHshTableOps <Element, _Key, ElementOps, Implementation>::
  81. Clone () const
  82. { return (Implementation*) *new Self (*this);
  83. }
  84.  
  85. template <class Element, class Key,
  86.           class ElementOps, class Implementation>
  87. void*
  88. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  89. CreateNode (void const* element) const
  90. { void* node = ivElementOps.Allocate (sizeof (Node)
  91. #if defined (__DEBUG_ALLOC__)
  92.                                       , __FILE__, __LINE__
  93. #endif
  94.                                      );
  95.   return new (ivImpl.CheckPointer (node))
  96.     Node (*(Element const*)element);
  97. }
  98.  
  99. template <class Element, class Key,
  100.           class ElementOps, class Implementation>
  101. void*
  102. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  103. CreateNodes (INumber n) const
  104. { return ivElementOps.Allocate ((size_t) (sizeof (Node*) * n)
  105. #if defined (__DEBUG_ALLOC__)
  106.                                 , __FILE__, __LINE__
  107. #endif
  108.                                );
  109. }
  110.  
  111. template <class Element, class Key,
  112.           class ElementOps, class Implementation>
  113. void
  114. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  115. DeleteNode (void* node) const
  116. { ((Node*)node)->~Node ();
  117.   ivElementOps.Deallocate (node
  118. #if defined (__DEBUG_ALLOC__)
  119.                            , __FILE__, __LINE__
  120. #endif
  121.                           );
  122. }
  123.  
  124. template <class Element, class Key,
  125.           class ElementOps, class Implementation>
  126. void
  127. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  128. DeleteNodes (void* nodes) const
  129. { ivElementOps.Deallocate (nodes
  130. #if defined (__DEBUG_ALLOC__)
  131.                            , __FILE__, __LINE__
  132. #endif
  133.                           );
  134. }
  135.  
  136. template <class Element, class _Key,
  137.           class ElementOps, class Implementation>
  138. IBoolean
  139. IKeyBagAsHshTableOps <Element, _Key, ElementOps, Implementation>::
  140. EqualKeys (void const* arg1, void const* arg2, IArgType argType) const
  141. { IBoolean result;
  142.   switch (argType) {
  143.     case kElementElement: {
  144.       result = ivElementOps.keyOps.Equal
  145.         (ivElementOps.Key (*(Element const*)arg1),
  146.          ivElementOps.Key (*(Element const*)arg2));
  147.       break;
  148.     }
  149.     case kElementKey: {
  150.       result = ivElementOps.keyOps.Equal
  151.         (ivElementOps.Key (*(Element const*)arg1),
  152.          IKeyForOps ((_Key const*)arg2));
  153.       break;
  154.     }
  155.    case kKeyKey: {
  156.       result = ivElementOps.keyOps.Equal
  157.         (IKeyForOps ((_Key const*)arg1),
  158.          IKeyForOps ((_Key const*)arg2));
  159.       break;
  160.     }
  161.  
  162.   }
  163.   return result;
  164. }
  165.  
  166. template <class Element, class _Key,
  167.           class ElementOps, class Implementation>
  168. unsigned long
  169. IKeyBagAsHshTableOps <Element, _Key, ElementOps, Implementation>::
  170. HashKey (void const* arg, unsigned long h, IArgType argType) const
  171. { unsigned long hashValue;
  172.   switch (argType) {
  173.     case kElement: {
  174.       hashValue = ivElementOps.keyOps.Hash
  175.         (ivElementOps.Key (*(Element const*)arg), h);
  176.       break;
  177.     }
  178.     case kKey: {
  179.       hashValue = ivElementOps.keyOps.Hash
  180.         (IKeyForOps ((_Key const*)arg), h);
  181.       break;
  182.     }
  183.   }
  184.   return hashValue;
  185. }
  186.  
  187. template <class Element, class _Key,
  188.           class ElementOps, class Implementation>
  189. void*
  190. IKeyBagAsHshTableOps <Element, _Key, ElementOps, Implementation>::
  191. Key (void const* element) const
  192. { return IKeyFromOps (ivElementOps.Key (*(Element const*)element));
  193. }
  194.  
  195. template <class Element, class Key,
  196.           class ElementOps, class Implementation>
  197. void*
  198. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  199. StreamIn (TStream& fromWhere) const
  200. { Element* element = ivElementOps.GetStreamable ();
  201.   ivElementOps.StreamIn (*element, fromWhere);
  202.   return (void*) element;
  203. }
  204.  
  205. template <class Element, class Key,
  206.           class ElementOps, class Implementation>
  207. void
  208. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  209. StreamOut (void const* element, TStream& toWhere) const
  210. { ivElementOps.StreamOut (*(Element const*)element, toWhere);
  211. }
  212.  
  213. template <class Element, class Key,
  214.           class ElementOps, class Implementation>
  215. TStream&
  216. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  217. operator<<= (TStream& fromWhere)
  218. { return (ivElementOps <<= fromWhere);
  219. }
  220.  
  221. template <class Element, class Key,
  222.           class ElementOps, class Implementation>
  223. TStream&
  224. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  225. operator>>= (TStream& toWhere) const
  226. { return (ivElementOps >>= toWhere);
  227. }
  228.  
  229. template <class Element, class Key,
  230.           class ElementOps, class Implementation>
  231. IKeyBagAsHshTableOps <Element, Key, ElementOps, Implementation>::
  232. operator Implementation* ()
  233. { ivImpl.CheckPointer (this);
  234.   return &ivImpl;
  235. }
  236.  
  237. #pragma info (restore)
  238. #pragma pack ()
  239.