home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / BCPPOWL1.ZIP / CLSRC.ZIP / DICT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-28  |  3.5 KB  |  143 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. #if !defined( __ERREXIT_H )
  40. #include <errexit.h>
  41. #endif
  42.  
  43. // End Implementation Dependencies -------------------------------------------
  44.  
  45. // Member Function //
  46.  
  47. Dictionary::~Dictionary()
  48.  
  49. // Summary -----------------------------------------------------------------
  50. //
  51. //      Destructor for a Dictionary object.
  52. //
  53. //        We don't do anything here, because the destructor for HashTable
  54. //        will take care of destroying the contained objects.
  55. //
  56. // End ---------------------------------------------------------------------
  57. {
  58. }
  59. // End Destructor //
  60.  
  61.  
  62. // Member Function //
  63.  
  64. classType Dictionary::isA() const
  65.  
  66. // Summary -----------------------------------------------------------------
  67. //
  68. //         Returns the class type of a dictionary.
  69. //
  70. // End ---------------------------------------------------------------------
  71. {
  72.     return dictionaryClass; 
  73. }
  74. // End Member Function Dictionary::isA //
  75.  
  76.  
  77. // Member Function //
  78.  
  79. char *Dictionary::nameOf() const
  80.  
  81. // Summary -----------------------------------------------------------------
  82. //
  83. //         Returns a pointer to the character string "Dictionary."
  84. //
  85. // End ---------------------------------------------------------------------
  86. {
  87.     return "Dictionary";
  88. }
  89. // End Member Function Dictionary::nameOf //
  90.  
  91.  
  92. // Member Function //
  93.  
  94. Association& Dictionary::lookup( const Object& toLookUp ) const
  95.  
  96. // Summary -----------------------------------------------------------------
  97. //
  98. //         Looks up an object in the dictionary.
  99. //
  100. // Parameters
  101. //
  102. //         toLookUp
  103. //
  104. //         The object to be searched for in the dictionary.
  105. //
  106. // End ---------------------------------------------------------------------
  107. {
  108.     Association toFind( (Object&)toLookUp, NOOBJECT );
  109.     // OK to cast to non-const object here, since it doesn't get
  110.     // put into a dictionary, but is only used for comparisons.
  111.  
  112.     Association& found = (Association&)findMember( toFind );
  113.     return found;
  114. }
  115. // End Member Function Dictionary::lookup //
  116.  
  117.  
  118. // Member Function //
  119.  
  120. void Dictionary::add( Object& objectToAdd )
  121.  
  122. // Summary -----------------------------------------------------------------
  123. //
  124. //         Adds an object of type Association to the dictionary.
  125. //
  126. // Parameters
  127. //
  128. //         objectToAdd
  129. //
  130. //         The object to be added to the dictionary.
  131. //
  132. // End ---------------------------------------------------------------------
  133. {
  134.     if( !objectToAdd.isAssociation() )
  135.         ClasslibErrorExit("Error:  Object must be association type.",
  136.                       __ENOTASSOC);
  137.     else
  138.     {
  139.         Set::add( objectToAdd );
  140.     }
  141. }
  142. // End Member Function Dictionary::add //
  143.