home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / SAMPLES / ICLCC / DEMOELEM.H < prev    next >
C/C++ Source or Header  |  1993-05-07  |  3KB  |  60 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. /*-------------------------------------------------------------*\
  19. |  demoelem.h  -  DemoElement for use with Key Collections      |
  20. \*-------------------------------------------------------------*/
  21. #ifndef _DEMOELEM_H
  22. #define _DEMOELEM_H
  23.  
  24. #include <stdlib.h>
  25. #include <iglobals.h>
  26. #include <iostream.h>
  27. #include <istdops.h>
  28.  
  29. class DemoElement {
  30.     int i;
  31.     int j;
  32. public:
  33.   DemoElement () : i(0), j(0) {}
  34.   DemoElement (int i,int j) : i (i), j(j) {}
  35.   operator int () const {return i;}
  36.  
  37.   Boolean operator == (DemoElement const& k) const
  38.   { return i == k.i && j == k.j; }
  39.  
  40.   Boolean operator < (DemoElement const& k) const
  41.   { return i < k.i || (i == k.i && j < k.j); }
  42.  
  43.   friend unsigned long hash (DemoElement const& k, unsigned long n)
  44.   { return k.i % n; }
  45.  
  46.   int const & geti() const { return i;}
  47.   int const & getj() const {return j;}
  48. };
  49.  
  50.  
  51. inline ostream & operator << (ostream &sout, DemoElement const& e) {
  52.   sout << e.geti() << "," << e.getj() ;
  53.   return sout;
  54. }
  55. // NOTE: You MUST return  a const & in the key function
  56. // otherwise you are returning a reference to a temporary
  57. inline int const& key (DemoElement const& k) {return k.geti();}
  58.  
  59. #endif
  60.