home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / SAMPLES / ICLCC / INTKYSET.C < prev    next >
C/C++ Source or Header  |  1993-05-07  |  3KB  |  69 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. |  intkyset.C  -  Integer Key Set for demonstration of using    |
  20. |                 a KeySet.                                     |
  21. \*-------------------------------------------------------------*/
  22. #include <iostream.h>
  23. #include <iglobals.h>
  24. #include <icursor.h>
  25.  
  26. #include <ikeyset.h>
  27.  
  28.                       // Class DemoElement:
  29. #include "demoelem.h"
  30.  
  31.  
  32. typedef IKeySet < DemoElement,int > TestKeySet;
  33.  
  34.  
  35. ostream & operator << ( ostream & sout, TestKeySet const & t){
  36.   sout << t.numberOfElements() << " elements are in the set:\n";
  37.  
  38.   TestKeySet::Cursor cursor (t);
  39.   //  forCursor(c)
  40.   // expands to
  41.   //  for ((c).setToFirst (); (c).isValid (); (c).setToNext ())
  42.  
  43.   forCursor (cursor)
  44.     sout << "   " << cursor.element() << "\n";
  45.  
  46.   return sout << "\n";
  47. }
  48.  
  49.  
  50. main(){
  51.   TestKeySet t;
  52.  try {
  53.      t.add(DemoElement(1,1));
  54.      t.add(DemoElement(2,4711));
  55.      t.add(DemoElement(3,1));
  56.      t.add(DemoElement(4,443));
  57.  
  58.      cout << t;
  59.  
  60.      t.removeElementWithKey (3);
  61.      cout << t;
  62.    }
  63.  catch (IException & exception) {
  64.    cout << exception.name() << " : " << exception.text();
  65.    }
  66.  
  67.   return 0;
  68. }
  69.