home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Structs / Sets / BCSetU.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  5.3 KB  |  178 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 set 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. //  BCSetU.cpp
  10. //
  11. //  This file contains the definitions for the unbounded set.
  12.  
  13. #include "BCSetU.h"
  14.  
  15. template<class Item, BC_Index Buckets, class StorageManager>
  16. BC_TUnboundedSet<Item, Buckets, StorageManager>::BC_TUnboundedSet() {}
  17.  
  18. template<class Item, BC_Index Buckets, class StorageManager>
  19. BC_TUnboundedSet<Item, Buckets, StorageManager>::
  20.   BC_TUnboundedSet(BC_Index (*hash)(const Item&))
  21.     : fRep(hash) {}
  22.  
  23. template<class Item, BC_Index Buckets, class StorageManager>
  24. BC_TUnboundedSet<Item, Buckets, StorageManager>::
  25.   BC_TUnboundedSet(const BC_TUnboundedSet<Item, Buckets, StorageManager>& s)
  26.     : fRep(s.fRep) {}
  27.  
  28. template<class Item, BC_Index Buckets, class StorageManager>
  29. BC_TUnboundedSet<Item, Buckets, StorageManager>::~BC_TUnboundedSet() {}
  30.  
  31. template<class Item, BC_Index Buckets, class StorageManager>
  32. BC_TSet<Item>& BC_TUnboundedSet<Item, Buckets, StorageManager>::
  33.   operator=(const BC_TSet<Item>& s)
  34. {
  35.   return BC_TSet<Item>::operator=(s);
  36. }
  37.  
  38. template<class Item, BC_Index Buckets, class StorageManager>
  39. BC_TSet<Item>& BC_TUnboundedSet<Item, Buckets, StorageManager>::
  40.   operator=(const BC_TUnboundedSet<Item, Buckets, StorageManager>& s)
  41. {
  42.   fRep = s.fRep;
  43.   return *this;
  44. }
  45.  
  46. template<class Item, BC_Index Buckets, class StorageManager>
  47. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::
  48.   operator==(const BC_TSet<Item>& s) const
  49. {
  50.   return BC_TSet<Item>::operator==(s);
  51. }
  52.  
  53. template<class Item, BC_Index Buckets, class StorageManager>
  54. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::
  55.   operator==(const BC_TUnboundedSet<Item, Buckets, StorageManager>& s) const
  56. {
  57.   return (fRep == s.fRep);
  58. }
  59.  
  60. template<class Item, BC_Index Buckets, class StorageManager>
  61. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::
  62.   operator!=(const BC_TUnboundedSet<Item, Buckets, StorageManager>& s) const
  63. {
  64.   return !operator==(s);
  65. }
  66.  
  67. template<class Item, BC_Index Buckets, class StorageManager>
  68. void BC_TUnboundedSet<Item, Buckets, StorageManager>::
  69.   SetHashFunction(BC_Index (*hash)(const Item&))
  70. {
  71.   fRep.SetHashFunction(hash);
  72. }
  73.  
  74. template<class Item, BC_Index Buckets, class StorageManager>
  75. void BC_TUnboundedSet<Item, Buckets, StorageManager>::Clear()
  76. {
  77.   fRep.Clear();
  78. }
  79.  
  80. template<class Item, BC_Index Buckets, class StorageManager>
  81. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::Add(const Item& item)
  82. {
  83.   return fRep.Bind(item, 1);
  84. }
  85.  
  86. template<class Item, BC_Index Buckets, class StorageManager>
  87. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::Remove(const Item& item)
  88. {
  89.   return fRep.Unbind(item);
  90. }
  91.  
  92. template<class Item, BC_Index Buckets, class StorageManager>
  93. BC_Index BC_TUnboundedSet<Item, Buckets, StorageManager>::Extent() const
  94. {
  95.   return fRep.Extent();
  96. }
  97.  
  98. template<class Item, BC_Index Buckets, class StorageManager>
  99. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::IsEmpty() const
  100. {
  101.   return (fRep.Extent() == 0);
  102. }
  103.  
  104. template<class Item, BC_Index Buckets, class StorageManager>
  105. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::IsMember(const Item& item) const
  106. {
  107.   return fRep.IsBound(item);
  108. }
  109.  
  110. template<class Item, BC_Index Buckets, class StorageManager>
  111. void* BC_TUnboundedSet<Item, Buckets, StorageManager>::operator new(size_t s)
  112. {
  113.   return StorageManager::Allocate(s);
  114. }
  115.  
  116. template<class Item, BC_Index Buckets, class StorageManager>
  117. void BC_TUnboundedSet<Item, Buckets, StorageManager>::operator delete(void* p, size_t s)
  118. {
  119.   StorageManager::Deallocate(p, s);
  120. }
  121.  
  122. template<class Item, BC_Index Buckets, class StorageManager>
  123. void BC_TUnboundedSet<Item, Buckets, StorageManager>::Purge() 
  124. {
  125.   fRep.Clear();
  126. }
  127.  
  128. template<class Item, BC_Index Buckets, class StorageManager>
  129. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::
  130.   Attach(const Item& item, const BC_Boolean& value)
  131. {
  132.   return BC_TSet<Item>::Attach(item, value);
  133. }
  134.  
  135. template<class Item, BC_Index Buckets, class StorageManager>
  136. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::Attach(const Item& item)
  137. {
  138.   return fRep.Bind(item, 1);
  139. }
  140.  
  141. template<class Item, BC_Index Buckets, class StorageManager>
  142. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::Detach(const Item& item)
  143. {
  144.   return fRep.Unbind(item);
  145. }
  146.  
  147. template<class Item, BC_Index Buckets, class StorageManager>
  148. BC_Index BC_TUnboundedSet<Item, Buckets, StorageManager>::Cardinality() const
  149. {
  150.   return fRep.Extent();
  151. }
  152.  
  153. template<class Item, BC_Index Buckets, class StorageManager>
  154. BC_Index BC_TUnboundedSet<Item, Buckets, StorageManager>::NumberOfBuckets() const
  155. {
  156.   return Buckets;
  157. }
  158.  
  159. template<class Item, BC_Index Buckets, class StorageManager>
  160. BC_Index BC_TUnboundedSet<Item, Buckets, StorageManager>::Length(BC_Index bucket) const
  161. {
  162.   return fRep.Bucket(bucket)->Length();
  163. }
  164.  
  165. template<class Item, BC_Index Buckets, class StorageManager>
  166. BC_Boolean BC_TUnboundedSet<Item, Buckets, StorageManager>::
  167.   Exists(const Item& item) const
  168. {
  169.   return fRep.IsBound(item);
  170. }
  171.  
  172. template<class Item, BC_Index Buckets, class StorageManager>
  173. const Item& BC_TUnboundedSet<Item, Buckets, StorageManager>::
  174.   ItemAt(BC_Index bucket, BC_Index index) const
  175. {
  176.   return (*fRep.Bucket(bucket))[index].fItem;
  177. }
  178.