home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / SAMPLES / ICLCC / ANIMAL.H next >
C/C++ Source or Header  |  1993-05-07  |  3KB  |  66 lines

  1. /******************************************************************************/
  2. /*                                                                            */
  3. /* COPYRIGHT:                                                                 */
  4. /* ----------                                                                 */
  5. /* Copyright (C) International Business Machines Corp., 1991,1992.            */
  6. /*                                                                            */
  7. /* DISCLAIMER OF WARRANTIES:                                                  */
  8. /* -------------------------                                                  */
  9. /* The following [enclosed] code is sample code created by IBM                */
  10. /* Corporation.  This sample code is not part of any standard IBM product     */
  11. /* and is provided to you solely for the purpose of assisting you in the      */
  12. /* development of your applications.  The code is provided "AS IS",           */
  13. /* without warranty of any kind.  IBM shall not be liable for any damages     */
  14. /* arising out of your use of the sample code, even if they have been         */
  15. /* advised of the possibility of such damages.                                */
  16. /*                                                                            */
  17. /******************************************************************************/
  18. // animal.h  -  Class Animal for use with the example animals.C
  19.  
  20.                              // For definition of Boolean:
  21.   #include <iglobals.h>
  22.                              // Class ToyString:
  23.   #include "toystrng.h"
  24.  
  25. class Animal {
  26.   ToyString nm;
  27.   ToyString attr;
  28.  
  29. public:
  30.  
  31.   Animal(char* n, char* a) : nm(n), attr(a)  {}
  32.  
  33.   // For copy constructor we use the compiler generated default.
  34.  
  35.   // For assignment we use the compiler generated default.
  36.  
  37.   Boolean operator==(Animal const& p) const  {
  38.      return  ((nm == p.nm) && (attr == p.attr));
  39.   }
  40.  
  41.   ToyString const& name() const {
  42.      return nm;
  43.   }
  44.  
  45.   ToyString const& attribute() const {
  46.      return attr;
  47.   }
  48.  
  49.   friend ostream& operator<<(ostream& os, Animal const& p)  {
  50.      return os << "The " << p.name().text()
  51.                << " is " << p.attribute().text() << ".\n";
  52.   }
  53.  
  54. };
  55.  
  56.   // Key access:
  57. inline ToyString const& key(Animal const& p)  {
  58.   return p.name();
  59. }
  60.  
  61.   // We need a hash function for the key type as well.
  62.   // Let's just use the default provided for char*.
  63. inline unsigned long hash(ToyString const& ts, unsigned long n) {
  64.   return hash(ts.text(), n);
  65. }
  66.