home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / animals / animal.h next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  2.3 KB  |  66 lines

  1. /**********************************************************************
  2. *                                                                     *
  3. *  IBM(R) VisualAge(TM) for C++ for Windows(R), Version 3.5           *
  4. *                                                                     *
  5. *  PID: 5622-880                                                      *
  6. *  - Licensed Material - Program-Property of IBM                      *
  7. *  (C) Copyright IBM Corp. 1991, 1995 - All Right Reserved.           *
  8. *                                                                     *
  9. *  US Government Users Restricted Rights - Use, duplication or        *
  10. *  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.  *
  11. *                                                                     *
  12. *  VisualAge, and IBM are trademarks or registered trademarks of      *
  13. *  International Business Machines Corporation.                       *
  14. *  Windows is a registered trademark of Microsoft Corporation.        *
  15. *                                                                     *
  16. **********************************************************************/
  17.  
  18. // animal.h  -  Class Animal for use with the example animals.C
  19.  
  20.  
  21.   #include <iglobals.h>           // For definition of Boolean:
  22.   #include <istring.hpp>          // Class IString:
  23.   #include <iostream.h>
  24.  
  25. class Animal {
  26.   IString nm;
  27.   IString attr;
  28.  
  29. public:
  30.  
  31.   Animal(IString n, IString 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.   IBoolean operator==(Animal const& p) const  {
  38.      return  ((nm == p.name()) && (attr == p.attribute()));
  39.   }
  40.  
  41.   IString const& name() const {
  42.      return nm;
  43.   }
  44.  
  45.   IString const& attribute() const {
  46.      return attr;
  47.   }
  48.  
  49.   friend ostream& operator<<(ostream& os, Animal const& p)  {
  50.      return os << "The " << p.name() << " is " << p.attribute()
  51.      << "." << endl;
  52.   }
  53.  
  54. };
  55.  
  56.   // Key access:
  57. inline IString 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 IString.
  63. inline unsigned long hash(Animal const& animal, unsigned long n) {
  64.   return hash(animal.name(), n);
  65. }
  66.