home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / ANIMALS / ANIMAL.H next >
Text File  |  1995-03-15  |  2KB  |  61 lines

  1. /*************************************************************************
  2.   IBM C/C++ Tools Version 3.00 - Collection Class Library
  3.  (C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
  4.  IBM.  All Rights Reserved.  US Government Users Restricted Rights - Use,
  5.  duplication or disclosure restricted by GSA ADP Schedule Contract with
  6.  IBM Corp.
  7.  *************************************************************************/
  8.  
  9. // animal.h  -  Class Animal for use with the example animals.C
  10.  
  11.  
  12.   #include <iglobals.h>           // For definition of Boolean:
  13. #if defined (_SUN)
  14.   #include <istring.h>          // Class IString:
  15. #else
  16.   #include <istring.hpp>          // Class IString:
  17. #endif
  18.   #include <iostream.h>
  19.  
  20. class Animal {
  21.   IString nm;
  22.   IString attr;
  23.  
  24. public:
  25.  
  26.   Animal(IString n, IString a) : nm(n), attr(a)  {}
  27.  
  28.   // For copy constructor we use the compiler generated default.
  29.  
  30.   // For assignment we use the compiler generated default.
  31.  
  32.   IBoolean operator==(Animal const& p) const  {
  33.      return  ((nm == p.name()) && (attr == p.attribute()));
  34.   }
  35.  
  36.   IString const& name() const {
  37.      return nm;
  38.   }
  39.  
  40.   IString const& attribute() const {
  41.      return attr;
  42.   }
  43.  
  44.   friend ostream& operator<<(ostream& os, Animal const& p)  {
  45.      return os << "The " << p.name() << " is " << p.attribute()
  46.      << "." << endl;
  47.   }
  48.  
  49. };
  50.  
  51.   // Key access:
  52. inline IString const& key(Animal const& p)  {
  53.   return p.name();
  54. }
  55.  
  56.   // We need a hash function for the key type as well.
  57.   // Let's just use the default provided for IString.
  58. inline unsigned long hash(Animal const& animal, unsigned long n) {
  59.   return hash(animal.name(), n);
  60. }
  61.