home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 12.ddi / CLASSINC.PAK / ASSOC.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  10.7 KB  |  342 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  ASSOC.H                                                               */
  4. /*                                                                        */
  5. /*  Copyright (c) 1993 Borland International                              */
  6. /*  All Rights Reserved                                                   */
  7. /*                                                                        */
  8. /*------------------------------------------------------------------------*/
  9.  
  10. #if !defined( __CLASSLIB_ASSOC_H )
  11. #define __CLASSLIB_ASSOC_H
  12.  
  13. #if !defined( __CLASSLIB_DEFS_H )
  14. #include "classlib\defs.h"
  15. #endif  // __CLASSLIB_DEFS_H
  16.  
  17. #if !defined( __CLASSLIB_ALLOCTR_H )
  18. #include "classlib\alloctr.h"
  19. #endif  // __CLASSLIB_ALLOCTR_H
  20.  
  21. #if !defined( __CLASSLIB_VOIDP_H )
  22. #include "classlib\voidp.h"
  23. #endif  // __CLASSLIB_VOIDP_H
  24.  
  25. #if !defined( __CLASSLIB_HASHIMP_H )
  26. #include "classlib\hashimp.h"
  27. #endif  // __CLASSLIB_HASHIMP_H
  28.  
  29. #pragma option -Vo-
  30. #if defined( BI_CLASSLIB_NO_po )
  31. #pragma option -po-
  32. #endif
  33.  
  34. /*------------------------------------------------------------------------*/
  35. /*                                                                        */
  36. /*  template <class K,class V,class A> class TMDDAssociation              */
  37. /*                                                                        */
  38. /*  Managed association (direct key, direct value)                        */
  39. /*                                                                        */
  40. /*  Implements a binding of a key (K) and value (V).  Assumes that        */
  41. /*  K has a HashValue() member function or a global function with         */
  42. /*  the following prototype exists:                                       */
  43. /*                                                                        */
  44. /*      unsigned HashValue( K& );                                         */
  45. /*                                                                        */
  46. /*------------------------------------------------------------------------*/
  47.  
  48. template <class K,class V,class A> class TMDDAssociation
  49. {
  50. public:
  51.  
  52.     TMDDAssociation()
  53.         {
  54.         }
  55.         
  56.     TMDDAssociation( const K& k, const V& v ) :
  57.         KeyData(k),
  58.         ValueData(v)
  59.         {
  60.         }
  61.         
  62.     unsigned HashValue() const
  63.         {
  64.         return ::HashValue( KeyData );
  65.         }
  66.         
  67.     const K& Key() const
  68.         {
  69.         return KeyData;
  70.         }
  71.         
  72.     const V& Value() const
  73.         {
  74.         return ValueData;
  75.         }
  76.         
  77.     int operator == (const TMDDAssociation<K,V,A> & a) const
  78.         {
  79.         return KeyData == a.KeyData;
  80.         }
  81.  
  82.     void DeleteElements()
  83.         {
  84.         }
  85.         
  86. protected:
  87.  
  88.     K KeyData;
  89.     V ValueData;
  90. };
  91.  
  92. /*------------------------------------------------------------------------*/
  93. /*                                                                        */
  94. /*  template <class K,class V> class TDDAssociation                       */
  95. /*                                                                        */
  96. /*  Standard association (direct key, direct value)                       */
  97. /*                                                                        */
  98. /*------------------------------------------------------------------------*/
  99.  
  100. template <class K,class V> class TDDAssociation :
  101.     public TMDDAssociation<K,V,TStandardAllocator>
  102. {
  103. public:
  104.  
  105.     TDDAssociation() :
  106.         TMDDAssociation<K,V,TStandardAllocator>()
  107.         {
  108.         }
  109.         
  110.     TDDAssociation( const K& k, const V& v ) :
  111.         TMDDAssociation<K,V,TStandardAllocator>( k, v )
  112.         {
  113.         }
  114. };
  115.  
  116. /*------------------------------------------------------------------------*/
  117. /*                                                                        */
  118. /*  template <class K,class V,class A> class TMDIAssociation              */
  119. /*                                                                        */
  120. /*  Managed association (direct key, indirect value)                      */
  121. /*                                                                        */
  122. /*------------------------------------------------------------------------*/
  123.  
  124. template <class K,class V,class A> class TMDIAssociation :
  125.     private TMDDAssociation<K,TVoidPointer,A>
  126. {
  127.  
  128.     typedef TMDDAssociation<K,TVoidPointer,A> Parent;
  129.  
  130. public:
  131.  
  132.     TMDIAssociation() :
  133.         TMDDAssociation<K,TVoidPointer,A>()
  134.         {
  135.         }
  136.         
  137.     TMDIAssociation( const K& k, V *v ) : 
  138.         TMDDAssociation<K,TVoidPointer,A>( k, v )
  139.         {
  140.         }
  141.  
  142.     const V *Value() const
  143.         {
  144.         return STATIC_CAST(V *,STATIC_CAST(void *,(TMDDAssociation<K,TVoidPointer,A>::Value())));
  145.         }
  146.  
  147.     int operator == (const TMDIAssociation<K,V,A> & a) const
  148.         {
  149.         return Parent::operator ==(a);
  150.         }
  151.  
  152.     Parent::HashValue;
  153.     Parent::Key;
  154.  
  155.     void DeleteElements()
  156.         {
  157.         delete CONST_CAST(V *,Value());
  158.         }
  159.         
  160. };
  161.  
  162. /*------------------------------------------------------------------------*/
  163. /*                                                                        */
  164. /*  template <class K,class V> class TDIAssociation                       */
  165. /*                                                                        */
  166. /*  Standard association (direct key, indirect value)                     */
  167. /*                                                                        */
  168. /*------------------------------------------------------------------------*/
  169.  
  170. template <class K,class V> class TDIAssociation :
  171.     public TMDIAssociation<K,V,TStandardAllocator>
  172. {
  173. public:
  174.  
  175.     TDIAssociation() :
  176.         TMDIAssociation<K,V,TStandardAllocator>()
  177.         {
  178.         }
  179.         
  180.     TDIAssociation( const K& k, V *v ) :
  181.         TMDIAssociation<K,V,TStandardAllocator>( k, v )
  182.         {
  183.         }
  184. };
  185.  
  186.  
  187. /*------------------------------------------------------------------------*/
  188. /*                                                                        */
  189. /*  template <class K,class V,class A> class TMIDAssociation              */
  190. /*                                                                        */
  191. /*  Managed association (indirect key, direct value)                      */
  192. /*                                                                        */
  193. /*------------------------------------------------------------------------*/
  194.  
  195. template <class K,class V,class A> class TMIDAssociation :
  196.     private TMDDAssociation<TVoidPointer,V,A>
  197. {
  198.  
  199.     typedef TMDDAssociation<TVoidPointer,V,A> Parent;
  200.  
  201. public:
  202.  
  203.     TMIDAssociation() :
  204.         TMDDAssociation<TVoidPointer,V,A>()
  205.         {
  206.         }
  207.         
  208.     TMIDAssociation( K *k, const V& v ) : 
  209.         TMDDAssociation<TVoidPointer,V,A>( k, v )
  210.         {
  211.         }
  212.         
  213.     const K *Key() const
  214.         {
  215.         return STATIC_CAST(K *, STATIC_CAST(void *, Parent::Key()));
  216.         }
  217.  
  218.     int operator == (const TMIDAssociation<K,V,A>& a) const
  219.         {
  220.         return *Key() == *a.Key();
  221.         }
  222.  
  223.     Parent::HashValue;
  224.     Parent::Value;
  225.  
  226.     void DeleteElements()
  227.         {
  228.         delete CONST_CAST(K *,Key());
  229.         }
  230.         
  231. };
  232.  
  233. /*------------------------------------------------------------------------*/
  234. /*                                                                        */
  235. /*  template <class K,class V> class TIDAssociation                       */
  236. /*                                                                        */
  237. /*  Standard association (indirect key, direct value)                     */
  238. /*                                                                        */
  239. /*------------------------------------------------------------------------*/
  240.  
  241. template <class K,class V> class TIDAssociation :
  242.     public TMIDAssociation<K,V,TStandardAllocator>
  243. {
  244. public:
  245.  
  246.     TIDAssociation() :
  247.         TMIDAssociation<K,V,TStandardAllocator>()
  248.         {
  249.         }
  250.         
  251.     TIDAssociation( K *k, const V& v ) :
  252.         TMIDAssociation<K,V,TStandardAllocator>( k, v )
  253.         {
  254.         }
  255. };
  256.  
  257.  
  258. /*------------------------------------------------------------------------*/
  259. /*                                                                        */
  260. /*  template <class K,class V,class A> class TMIIAssociation              */
  261. /*                                                                        */
  262. /*  Managed association (indirect key, indirect value)                    */
  263. /*                                                                        */
  264. /*------------------------------------------------------------------------*/
  265.  
  266. template <class K,class V,class A> class TMIIAssociation :
  267.     private TMDDAssociation<TVoidPointer,TVoidPointer,A>
  268. {
  269.  
  270.     typedef TMDDAssociation<TVoidPointer,TVoidPointer,A> Parent;
  271.  
  272. public:
  273.  
  274.     TMIIAssociation() :
  275.         TMDDAssociation<TVoidPointer,TVoidPointer,A>()
  276.         {
  277.         }
  278.         
  279.     TMIIAssociation( K *k, V *v ) : 
  280.         TMDDAssociation<TVoidPointer,TVoidPointer,A>
  281.             ( k, v )
  282.         {
  283.         }
  284.         
  285.     const K *Key() const
  286.         {
  287.         return STATIC_CAST(K *, STATIC_CAST(void *, Parent::Key()));
  288.         }
  289.         
  290.     const V *Value() const
  291.         {
  292.         return STATIC_CAST(V *, STATIC_CAST(void *, Parent::Value()));
  293.         }
  294.         
  295.     int operator == (const TMIIAssociation<K,V,A>& a) const
  296.         {
  297.         return *Key() == *a.Key();
  298.         }
  299.  
  300.     Parent::HashValue;
  301.  
  302.     void DeleteElements()
  303.         {
  304.         delete CONST_CAST(K *,Key());
  305.         delete CONST_CAST(V *,Value());
  306.         }
  307.         
  308. };
  309.  
  310. /*------------------------------------------------------------------------*/
  311. /*                                                                        */
  312. /*  template <class K,class V> class TIIAssociation                       */
  313. /*                                                                        */
  314. /*  Standard association (indirect key, indirect value)                   */
  315. /*                                                                        */
  316. /*------------------------------------------------------------------------*/
  317.  
  318. template <class K,class V> class TIIAssociation :
  319.     public TMIIAssociation<K,V,TStandardAllocator>
  320. {
  321. public:
  322.  
  323.     TIIAssociation() :
  324.         TMIIAssociation<K,V,TStandardAllocator>()
  325.         {
  326.         }
  327.         
  328.     TIIAssociation( K *k, V *v ) :
  329.         TMIIAssociation<K,V,TStandardAllocator>( k, v )
  330.         {
  331.         }
  332. };
  333.  
  334.  
  335. #if defined( BI_CLASSLIB_NO_po )
  336. #pragma option -po.
  337. #endif
  338.  
  339. #pragma option -Vo.
  340.  
  341. #endif  // __CLASSLIB_ASSOC_H
  342.