home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Structs / Maps / BCMapD.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  7.4 KB  |  228 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  Restricted Rights Legend
  5. //  Use, duplication, or disclosure is subject to restrictions as bag forth 
  6. //  in subdivision (c)(1)(ii) of the Rights in Technical Data and Computer 
  7. //  Software clause at DFARS 252.227-7013. 
  8. //
  9. //  BCMapD.cpp
  10. //
  11. //  This file contains the definitions for the dynamic map.
  12.  
  13. #include "BCMapD.h"
  14.  
  15. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  16. BC_TDynamicMap<Item, Value, Buckets, StorageManager>::BC_TDynamicMap() {}
  17.  
  18. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  19. BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  20.   BC_TDynamicMap(BC_Index (*hash)(const Item&))
  21.     : fRep(hash) {}
  22.  
  23. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  24. BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  25.   BC_TDynamicMap(BC_Index chunkSize)
  26. {
  27.   for (BC_Index index = 0; (index < Buckets); index++)
  28.     fRep.Bucket(index)->SetChunkSize(chunkSize);
  29. }
  30.  
  31. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  32. BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  33.   BC_TDynamicMap(const BC_TDynamicMap<Item, Value, Buckets, StorageManager>& m)
  34.     : fRep(m.fRep) {}
  35.  
  36. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  37. BC_TDynamicMap<Item, Value, Buckets, StorageManager>::~BC_TDynamicMap() {}
  38.  
  39. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  40. BC_TMap<Item, Value>& BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  41.   operator=(const BC_TMap<Item, Value>& m)
  42. {
  43.   return BC_TMap<Item, Value>::operator=(m);
  44. }
  45.  
  46. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  47. BC_TMap<Item, Value>& BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  48.   operator=(const BC_TDynamicMap<Item, Value, Buckets, StorageManager>& m)
  49. {
  50.   fRep = m.fRep;
  51.   return *this;
  52. }
  53.  
  54. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  55. BC_Boolean BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  56.   operator==(const BC_TMap<Item, Value>& m) const
  57. {
  58.   return BC_TMap<Item, Value>::operator==(m);
  59. }
  60.  
  61. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  62. BC_Boolean BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  63.   operator==(const BC_TDynamicMap<Item, Value, Buckets, StorageManager>& m) const
  64. {
  65.   return (fRep == m.fRep);
  66. }
  67.  
  68. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  69. BC_Boolean BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  70.   operator!=(const BC_TDynamicMap<Item, Value, Buckets, StorageManager>& m) const
  71. {
  72.   return !operator==(m);
  73. }
  74.  
  75. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  76. void BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  77.   SetHashFunction(BC_Index (*hash)(const Item&))
  78. {
  79.   fRep.SetHashFunction(hash);
  80. }
  81.  
  82. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  83. void BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  84.   SetChunkSize(BC_Index chunkSize)
  85. {
  86.   for (BC_Index index = 0; (index < Buckets); index++)
  87.     fRep.Bucket(index)->SetChunkSize(chunkSize);
  88. }
  89.  
  90. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  91. void BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  92.   Preallocate(BC_Index new_length)
  93. {
  94.   for (BC_Index index = 0; (index < Buckets); index++)
  95.     fRep.Bucket(index)->Preallocate(new_length);
  96. }
  97.  
  98. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  99. void BC_TDynamicMap<Item, Value, Buckets, StorageManager>::Clear()
  100. {
  101.   fRep.Clear();
  102. }
  103.  
  104. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  105. BC_Boolean BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  106.   Bind(const Item& item, const Value& value)
  107. {
  108.   return fRep.Bind(item, value);
  109. }
  110.  
  111. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  112. BC_Boolean BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  113.   Rebind(const Item& item, const Value& value)
  114. {
  115.   return fRep.Rebind(item, value);
  116. }
  117.  
  118. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  119. BC_Boolean BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  120.   Unbind(const Item& item)
  121. {
  122.   return fRep.Unbind(item);
  123. }
  124.  
  125. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  126. BC_Index BC_TDynamicMap<Item, Value, Buckets, StorageManager>::ChunkSize() const
  127. {
  128.   return fRep.Bucket(0)->ChunkSize();
  129. }
  130.  
  131. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  132. BC_Index BC_TDynamicMap<Item, Value, Buckets, StorageManager>::Extent() const
  133. {
  134.   return fRep.Extent();
  135. }
  136.  
  137. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  138. BC_Boolean BC_TDynamicMap<Item, Value, Buckets, StorageManager>::IsEmpty() const
  139. {
  140.   return (fRep.Extent() == 0);
  141. }
  142.  
  143. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  144. BC_Boolean BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  145.   IsBound(const Item& item) const
  146. {
  147.   return fRep.IsBound(item);
  148. }
  149.  
  150. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  151. const Value* BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  152.   ValueOf(const Item& item) const
  153. {
  154.   return fRep.ValueOf(item);
  155. }
  156.  
  157. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  158. Value* BC_TDynamicMap<Item, Value, Buckets, StorageManager>::ValueOf(const Item& item)
  159. {
  160.   return (Value*)(fRep.ValueOf(item));
  161. }
  162.  
  163. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  164. void* BC_TDynamicMap<Item, Value, Buckets, StorageManager>::operator new(size_t s)
  165. {
  166.   return StorageManager::Allocate(s);
  167. }
  168.  
  169. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  170. void BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  171.   operator delete(void* p, size_t s)
  172. {
  173.   StorageManager::Deallocate(p, s);
  174. }
  175.  
  176. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  177. void BC_TDynamicMap<Item, Value, Buckets, StorageManager>::Purge() 
  178. {
  179.   fRep.Clear();
  180. }
  181.  
  182. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  183. BC_Boolean BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  184.   Attach(const Item& item, const Value& value)
  185. {
  186.   return fRep.Bind(item, value);
  187. }
  188.  
  189. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  190. BC_Index BC_TDynamicMap<Item, Value, Buckets, StorageManager>::Cardinality() const
  191. {
  192.   return fRep.Extent();
  193. }
  194.  
  195. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  196. BC_Index BC_TDynamicMap<Item, Value, Buckets, StorageManager>::NumberOfBuckets() const
  197. {
  198.   return Buckets;
  199. }
  200.  
  201. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  202. BC_Index BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  203.   Length(BC_Index bucket) const
  204. {
  205.   return fRep.Bucket(bucket)->Length();
  206. }
  207.  
  208. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  209. BC_Boolean BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  210.   Exists(const Item& item) const
  211. {
  212.   return fRep.IsBound(item);
  213. }
  214.  
  215. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  216. const Item& BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  217.   ItemAt(BC_Index bucket, BC_Index index) const
  218. {
  219.   return (*fRep.Bucket(bucket))[index].fItem;
  220. }
  221.  
  222. template<class Item, class Value, BC_Index Buckets, class StorageManager>
  223. const Value& BC_TDynamicMap<Item, Value, Buckets, StorageManager>::
  224.   ValueAt(BC_Index bucket, BC_Index index) const
  225. {
  226.   return (*fRep.Bucket(bucket))[index].fValue;
  227. }
  228.