home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / intkyset / intkyset.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  2.2 KB  |  64 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. /*-------------------------------------------------------------*\
  19. |  intkyset.CPP  -  Integer Key Set for demonstration of using  |
  20. |                   a KeySet.                                   |
  21. \*-------------------------------------------------------------*/
  22. #include <iostream.h>
  23. #include <iglobals.h>
  24.  
  25. #include <iks.h>
  26.                       // Class DemoElement:
  27. #include "demoelem.h"
  28.  
  29. typedef IKeySet < DemoElement,int > TestKeySet;
  30.  
  31. ostream & operator << ( ostream & sout, TestKeySet const & t)
  32. { sout << t.numberOfElements() << " elements are in the set:" << endl;
  33.  
  34.   TestKeySet::Cursor cursor (t);
  35.  
  36.   //  forICursor(c)
  37.   // expands to
  38.   //  for ((c).setToFirst (); (c).isValid (); (c).setToNext ())
  39.  
  40.   forICursor (cursor)
  41.     sout << "   " << cursor.element () << endl;
  42.  
  43.   return sout << endl;
  44. }
  45.  
  46.  
  47. main()
  48. {
  49.   TestKeySet t;
  50.  
  51.   t.add(DemoElement(1,1));
  52.   t.add(DemoElement(2,4711));
  53.   t.add(DemoElement(3,1));
  54.   t.add(DemoElement(4,443));
  55.  
  56.   cout << t;
  57.  
  58.   t.removeElementWithKey (3);
  59.  
  60.   cout << t;
  61.  
  62.   return 0;
  63. }
  64.