home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c081_11 / 11.ddi / CLASSSRC.ZIP / DICT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-13  |  3.4 KB  |  142 lines

  1. // Borland C++ - (C) Copyright 1991 by Borland International
  2.  
  3. // Contents ----------------------------------------------------------------
  4. //
  5. //         Dictionary::isA
  6. //         Dictionary::nameOf
  7. //         Dictionary::lookup
  8. //         Dictionary::add
  9. //
  10. // Description
  11. //
  12. //         Implementation of member functions for class Dictionary.
  13. //
  14. // End ---------------------------------------------------------------------
  15.  
  16. // Interface Dependencies ---------------------------------------------------
  17.  
  18. #ifndef __OBJECT_H
  19. #include <object.h>
  20. #endif
  21.  
  22. #ifndef __DICT_H
  23. #include <dict.h>
  24. #endif
  25.  
  26. // End Interface Dependencies ------------------------------------------------
  27.  
  28.  
  29. // Implementation Dependencies ----------------------------------------------
  30.  
  31. #ifndef __CONTAIN_H
  32. #include <contain.h>
  33. #endif
  34.  
  35. #ifndef __ASSOC_H
  36. #include <assoc.h>
  37. #endif
  38.  
  39. // End Implementation Dependencies -------------------------------------------
  40.  
  41.  
  42. // Member Function //
  43.  
  44. Dictionary::~Dictionary()
  45.  
  46. // Summary -----------------------------------------------------------------
  47. //
  48. //      Destructor for a Dictionary object.
  49. //
  50. //        We don't do anything here, because the destructor for HashTable
  51. //        will take care of destroying the contained objects.
  52. //
  53. // End ---------------------------------------------------------------------
  54. {
  55. }
  56. // End Destructor //
  57.  
  58.  
  59. // Member Function //
  60.  
  61. classType Dictionary::isA() const
  62.  
  63. // Summary -----------------------------------------------------------------
  64. //
  65. //         Returns the class type of a dictionary.
  66. //
  67. // End ---------------------------------------------------------------------
  68. {
  69.     return dictionaryClass; 
  70. }
  71. // End Member Function Dictionary::isA //
  72.  
  73.  
  74. // Member Function //
  75.  
  76. char *Dictionary::nameOf() const
  77.  
  78. // Summary -----------------------------------------------------------------
  79. //
  80. //         Returns a pointer to the character string "Dictionary."
  81. //
  82. // End ---------------------------------------------------------------------
  83. {
  84.     return "Dictionary";
  85. }
  86. // End Member Function Dictionary::nameOf //
  87.  
  88.  
  89. // Member Function //
  90.  
  91. Association& Dictionary::lookup( const Object& toLookUp ) const
  92.  
  93. // Summary -----------------------------------------------------------------
  94. //
  95. //         Looks up an object in the dictionary.
  96. //
  97. // Parameters
  98. //
  99. //         toLookUp
  100. //
  101. //         The object to be searched for in the dictionary.
  102. //
  103. // End ---------------------------------------------------------------------
  104. {
  105.     Association toFind( (Object&)toLookUp, NOOBJECT );
  106.     // OK to cast to non-const object here, since it doesn't get
  107.     // put into a dictionary, but is only used for comparisons.
  108.  
  109.     Association& found = (Association&)findMember( toFind );
  110.     return found;
  111. }
  112. // End Member Function Dictionary::lookup //
  113.  
  114.  
  115. // Member Function //
  116.  
  117. void Dictionary::add( Object& objectToAdd )
  118.  
  119. // Summary -----------------------------------------------------------------
  120. //
  121. //         Adds an object of type Association to the dictionary.
  122. //
  123. // Parameters
  124. //
  125. //         objectToAdd
  126. //
  127. //         The object to be added to the dictionary.
  128. //
  129. // End ---------------------------------------------------------------------
  130. {
  131.     if( !objectToAdd.isAssociation() )
  132.     {
  133.         cerr << "Error:  Object must be association type.";
  134.         exit( __ENOTASSOC );
  135.     }
  136.     else
  137.     {
  138.         Set::add( objectToAdd );
  139.     }
  140. }
  141. // End Member Function Dictionary::add //
  142.