home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / cm / cmtassoc.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-06  |  3.3 KB  |  152 lines

  1. // CmTAssoc.cc
  2. // -----------------------------------------------------------------
  3. // Compendium - C++ Container Class Library
  4. // Copyright (C) 1992-1994, Glenn M. Poorman, All rights reserved
  5. // -----------------------------------------------------------------
  6. // Association template implementation.
  7. // -----------------------------------------------------------------
  8.  
  9.  
  10. // "CmTAssociation" constructs a new association with the specified
  11. // key and object.
  12. //
  13. template <class T, class O>
  14. CmTAssociation<T,O>::CmTAssociation(const T& k, const O& o)
  15. {
  16.   _key    = k;
  17.   _object = o;
  18. }
  19.  
  20.  
  21. // "CmTAssociation" constructs a new association with the specified
  22. // key.
  23. //
  24. template <class T, class O>
  25. CmTAssociation<T,O>::CmTAssociation(const T& k)
  26. {
  27.   _key = k;
  28. }
  29.  
  30.  
  31. // "CmTAssociation" is the association copy constructor.
  32. //
  33. template <class T, class O>
  34. CmTAssociation<T,O>::CmTAssociation(const CmTAssociation<T,O>& A)
  35. {
  36.   _key    = A._key;
  37.   _object = A._object;
  38. }
  39.  
  40.  
  41. // "=" assignment operator copies the specified association into this
  42. // association.
  43. //
  44. template <class T, class O> CmTAssociation<T,O>&
  45. CmTAssociation<T,O>::operator=(const CmTAssociation<T,O>& A)
  46. {
  47.   if (&A != this)
  48.   {
  49.     _key    = A._key;
  50.     _object = A._object;
  51.   }
  52.   return *this;
  53. }
  54.  
  55.  
  56. // "set" sets a new key and object value.
  57. //
  58. template <class T, class O>
  59. void CmTAssociation<T,O>::set(const T& k, const O& o)
  60. {
  61.   _key    = k;
  62.   _object = o;
  63. }
  64.  
  65.  
  66. // "key" returns the key value.
  67. //
  68. template <class T, class O> const T& CmTAssociation<T,O>::key() const
  69. {
  70.   return _key;
  71. }
  72.  
  73.  
  74. // "key" sets a new key value.
  75. //
  76. template <class T, class O> void CmTAssociation<T,O>::key(const T& k)
  77. {
  78.   _key = k;
  79. }
  80.  
  81.  
  82. // "object" returns the object value.
  83. //
  84. template <class T, class O> const O& CmTAssociation<T,O>::object() const
  85. {
  86.   return _object;
  87. }
  88.  
  89.  
  90. // "object" sets a new object value.
  91. //
  92. template <class T, class O> void CmTAssociation<T,O>::object(const O& o)
  93. {
  94.   _object = o;
  95. }
  96.  
  97.  
  98. // "==" checks to see if two associations are equal.
  99. //
  100. template <class T, class O>
  101. Bool CmTAssociation<T,O>::operator==(const CmTAssociation<T,O>& A) const
  102. {
  103.   return (_key == A._key);
  104. }
  105.  
  106.  
  107. // "!=" checks to see if two associations are not equal.
  108. //
  109. template <class T, class O>
  110. Bool CmTAssociation<T,O>::operator!=(const CmTAssociation<T,O>& A) const
  111. {
  112.   return (_key != A._key);
  113. }
  114.  
  115.  
  116. // "<" checks if this association is less than the specified association.
  117. //
  118. template <class T, class O>
  119. Bool CmTAssociation<T,O>::operator<(const CmTAssociation<T,O>& A) const
  120. {
  121.   return (_key < A._key);
  122. }
  123.  
  124.  
  125. // ">" checks if this association is greater than the specified association.
  126. //
  127. template <class T, class O>
  128. Bool CmTAssociation<T,O>::operator>(const CmTAssociation<T,O>& A) const
  129. {
  130.   return (_key > A._key);
  131. }
  132.  
  133.  
  134. // "<=" checks if this association is less than or equal to the specified
  135. // association.
  136. //
  137. template <class T, class O>
  138. Bool CmTAssociation<T,O>::operator<=(const CmTAssociation<T,O>& A) const
  139. {
  140.   return (_key <= A._key);
  141. }
  142.  
  143.  
  144. // ">=" checks if this association is greater than or equal to the specified
  145. // association.
  146. //
  147. template <class T, class O>
  148. Bool CmTAssociation<T,O>::operator>=(const CmTAssociation<T,O>& A) const
  149. {
  150.   return (_key >= A._key);
  151. }
  152.