home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / TUTORIAL / ICLCC / TUTOR5 / EXAMPLE5.C next >
C/C++ Source or Header  |  1993-05-07  |  3KB  |  92 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. #include <iostream.h>
  19. #include <tstring.h>
  20. #include <string.h>
  21. #include <iglobals.h>
  22. #include <kperson.h>
  23.  
  24. //include <ikeyset.h>
  25. //typedef IKeySet <Person , String>  People;
  26.  
  27. #include <i......h>
  28. typedef I.......Set <......, ......>  People;
  29.  
  30. ostream & operator << ( ostream & sout, People people){
  31.    People::Cursor cursor(people);
  32.    cout << " Number of entries: " << people.numberOfElements() << " \n";
  33.  
  34.    for (cursor.setToFirst();cursor.isValid() ;cursor.setToNext() ) {
  35.       cout << "Name :" << people.elementAt(cursor).getName();
  36.       cout << " TelephoneNumber" <<  people.elementAt(cursor).getTel() << "\n";
  37.    } /* endfor */
  38.    return sout;
  39. }
  40.  
  41.  
  42. class MyIterator: public IConstantIterator <Person> {
  43.     applyTo(Person const & person){
  44.       cout << "TelephoneNumber" << person.getTel() << "\n" ;
  45.       return  True;
  46.   }
  47. };
  48.  
  49. Boolean nonUSNumber (Person const & person, void*) {
  50.    if(!strncmp(person.getTel().getText()," xxx",4)){
  51.       return True;
  52.     }
  53.     return False;
  54. }
  55.  
  56. int main () {
  57.         People people;
  58. //      ..............
  59.  
  60.         people.add(Person("T. Wappler"," xxx-344543") );
  61.         people.add(Person("J. Uhl"," 001-344111"));
  62.         people.add(Person("M. Blum"," xxx-245343"));
  63.         people.add(Person("C. Ludwig"," xxx-9456543"));
  64.         people.add(Person("F. Seliger"," xxx-34835473"));
  65.         people.add(Person("H. Wingert"," 001-12345633"));
  66.  
  67.  
  68.         cout << people;
  69.  
  70.        if (! people.removeElementWithKey("C. Ludwig")){
  71.           cout << "element not removed !\n" ;
  72.        }
  73.  
  74.         MyIterator printNumbers;
  75.         people.allElementsDo(printNumbers);
  76.  
  77.         People::Cursor cursor (people);
  78.  
  79.          if (people.locateElementWithKey("F. Seliger", cursor)){
  80.  
  81.           Person person(people.elementAt(cursor));
  82.           cout << person.getName() <<  person.getTel()  << "\n";
  83.         } else{
  84.              cout<< "Invalid cursor \n";
  85.         }
  86.  
  87.         people.removeAll(nonUSNumber);
  88.         cout << people;
  89.  
  90.         return 0;
  91. }
  92.