home *** CD-ROM | disk | FTP | other *** search
/ The Devil's Doorknob BBS Capture (1996-2003) / devilsdoorknobbbscapture1996-2003.iso / Dloads / OTHERUTI / TCPP10-8.ZIP / CLASSEXM.ZIP / LOOKUP.CPP < prev    next >
C/C++ Source or Header  |  1990-09-26  |  6KB  |  203 lines

  1. //
  2. // This file contains proprietary information of Borland International.
  3. // Copying or reproduction without prior written approval is prohibited.
  4. //
  5. // Copyright (c) 1990
  6. // Borland International
  7. // 1800 Scotts Valley Dr.
  8. // Scotts Valley, CA 95066
  9. // (408) 438-8400
  10. //
  11.  
  12. // Contents ----------------------------------------------------------------
  13. //
  14. //      CLASSDEFINITIONS
  15. //      classNames
  16. //      classDefs
  17. //
  18. //      main
  19. //
  20. // Description
  21. //
  22. //      C++ class library example program.  Creates a dictionary from
  23. //      the descriptions of each of the classes in the class Object
  24. //      hierarchy.
  25. //
  26. // End ---------------------------------------------------------------------
  27.  
  28. // Interface Dependencies ---------------------------------------------------
  29. // End Interface Dependencies ------------------------------------------------
  30.  
  31. // Implementation Dependencies ----------------------------------------------
  32.  
  33. #ifndef __IOSTREAM_H
  34. #include <iostream.h>    // stream i/o
  35. #define __IOSTREAM_H
  36. #endif
  37.  
  38. #ifndef __DICT_H
  39. #include <dict.h>        // class Dictionary
  40. #endif
  41.  
  42. #ifndef __ASSOC_H
  43. #include <assoc.h>        // class Association
  44. #endif
  45.  
  46. #ifndef __STRNG_H
  47. #include <strng.h>        // class String
  48. #endif
  49.  
  50. // End Implementation Dependencies -------------------------------------------
  51.  
  52.  
  53. // Macro //
  54.  
  55. #define CLASSDEFINITIONS 23
  56.  
  57. // Description -------------------------------------------------------------
  58. //
  59. //     Defines the number of definitions in the dictionary.
  60. //
  61. // End ---------------------------------------------------------------------
  62.  
  63.  
  64. // Variable //
  65.  
  66. static char *classNames[CLASSDEFINITIONS] =
  67.     {
  68.         "Object",
  69.         "Error",
  70.         "Sortable",
  71.         "Association",
  72.         "String",
  73.         "Container",
  74.         "Stack",
  75.         "Queue",
  76.         "Deque",
  77.         "Collection",
  78.         "HashTable",
  79.         "Bag",
  80.         "Set",
  81.         "Dictionary",
  82.         "AbstractArray",
  83.         "Array",
  84.         "SortedArray",
  85.         "List",
  86.         "DoubleList",
  87.         "ContainerIterator",
  88.         "ArrayIterator",
  89.         "ListIterator",
  90.         "DoubleListIterator"
  91.     };
  92.  
  93.  
  94. // Description -------------------------------------------------------------
  95. //
  96. //     Used by the main routine to create the dictionary.
  97. //
  98. // End ---------------------------------------------------------------------
  99.  
  100.  
  101. // Variable //
  102.  
  103. static char *classDefs[CLASSDEFINITIONS] =
  104.     {
  105.         "The abstract base class of the hierarchy.\n",
  106.         "Used to indicate the presence of no object reference.\n",
  107.         "Used in ordered collections.\n",
  108.         "A key/value pair, used by the class Dictionary.\n",
  109.         "An example of an instance class, derived from class Sortable.\n",
  110.         "An abstract base class for all classes which contain other objects.\n",
  111.         "A LIFO container class.\n",
  112.         "A FIFO container class.\n",
  113.         "A double-ended container class, allowing both FIFO and LIFO access.\n",
  114.         "An abstract base class for classes which may be tested for membership.\n",
  115.         "A fast lookup implementation of a collection.\n",
  116.         "A collection class implemented by a hash table.\n",
  117.         "A collection in which there may be only one copy of each member.\n",
  118.         "A set of association object, with a lookup function.\n",
  119.         "An abstract base class for arrays.\n",
  120.         "A fixed or expandable array.\n",
  121.         "An array in which objects at successive indices are in order.\n",
  122.         "A collection class in which objects are linked together.\n",
  123.         "A collection of objects which are part of two lists.\n",
  124.         "A class which, when instantiated, is used to iterate over a collection.\n",
  125.         "An iterator which is used on array objects.\n",
  126.         "An iterator which is used on list objects.\n",
  127.         "An iterator which is used on double list objects.\n"
  128.     };
  129.  
  130.  
  131. // Description -------------------------------------------------------------
  132. //
  133. //     Used by the main routine to create the dictionary.
  134. //
  135. // End ---------------------------------------------------------------------
  136.  
  137.  
  138. // Function //
  139.  
  140. int main( int argc, char *argv[] )
  141.  
  142. // Summary -----------------------------------------------------------------
  143. //
  144. //     Dictionary example program.  This program creates a dictionary
  145. //     and inserts strings into the dictionary, then looks up a given
  146. //     string.
  147. //
  148. // Parameters
  149. //
  150. //     argc
  151. //
  152. //     The number of arguments passed to our program from the command line.
  153. //
  154. //     argv
  155. //
  156. //     The array of character pointers which was given on the command line.
  157. //
  158. // Functional Description
  159. //
  160. //     A dictionary object is a container class for association objects.
  161. //     An association is an object which keeps together a key and
  162. //     a value.  In our example, both the key and the value will be
  163. //     String objects.
  164. //
  165. //     We make a dictionary object on the heap, then add associations
  166. //     to the dictionary.  When these associations have been added, we
  167. //     look up the given string in the dictionary and display its
  168. //     definition.
  169. //
  170. // End ---------------------------------------------------------------------
  171. {
  172.     if ( argc != 2 )
  173.     {
  174.         cerr << "Usage:  lookup classname\n";
  175.         return 1;
  176.     }
  177.  
  178.     Dictionary& classDefinitions = *( new Dictionary );
  179.  
  180.     for ( int i = 0; i < CLASSDEFINITIONS; i++ )
  181.     {
  182.         String& className = *( new String( classNames[i] ) );
  183.         String& classDef = *( new String( classDefs[i] ) );
  184.         Association& entry = *(new Association( className, classDef ) );
  185.  
  186.         classDefinitions.add( entry );
  187.  
  188.     } // end for all class definitions
  189.  
  190.     Association& definition =
  191.                     classDefinitions.lookup ( *(new String ( argv[1] ) ) );
  192.     if ( definition == NOOBJECT )
  193.     {
  194.         cout << "A definition for " << argv[1] << " was not found in the dictionary.\n";
  195.     }
  196.     else
  197.     {
  198.         cout << definition;
  199.     }
  200. }
  201. // End Function main //
  202.  
  203.