home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ctdemo.zip / classes / @CLSLIB1.ZIP / cls / icclc / myuniver.cpp < prev    next >
C/C++ Source or Header  |  1994-06-23  |  3KB  |  139 lines

  1. #ifndef INCL_MYUNIVERSE
  2. #define INCL_MYUNIVERSE
  3.  
  4. #ifndef __FIRST__
  5. #define __FIRST__
  6. #define __IMPL__MYUNIVERSE
  7. #endif
  8.  
  9. /////V MyUniverse PCM f:\cls_ibm\cls\icclc 0 PM 20.10.94 19:37:13
  10.  
  11. /*
  12. /////H 
  13. 20.10.94 19:37 PM 0 copied from: MyUniverse TOS f:\cls_ibm\cls\icclc 0 PM 19.10.94 00:26:01
  14. 30.03.95 10:34 PM 0 archived: MyUniverse PCM f:\cls_ibm\cls\icclc 0 PM 20.10.94 19:37:13
  15. /////
  16. */
  17.  
  18. /////1
  19. #undef inline
  20.  
  21. #include <bsa.h>
  22.  
  23. /////I iostream.h @ @ @ @ pre 
  24. #include <iostream.h>
  25.  
  26. /////I stdio.h @ @ @ @ pre 
  27. #include <stdio.h>
  28.  
  29. /////I Planet @ @ @ @ class pre 
  30. #include <PLANET.CPP>
  31.  
  32. /////I TinyList @ @ @ <Planet> @ template class pre 
  33. #include <TINYLIST.CPP>
  34.  
  35. /////I isrtset.h @ @ @ ISortedSet<Planet> @ pre template 
  36. #include <isrtset.h>
  37.  
  38.  
  39. #ifndef __INLINE__
  40. #define inline
  41. #endif
  42.  
  43. /////C MyUniverse @ @ iccl 
  44. class MyUniverse
  45.  
  46. {
  47.  
  48. protected:
  49. /////D Planets @  @ instance protected 
  50.     TinyList<Planet>*     Planets;
  51.  
  52.  
  53. public:
  54.     int    expose ();
  55.     int    exposeReordered ();
  56.     MyUniverse ();
  57.     ~MyUniverse ();
  58. };
  59.  
  60.  
  61. /////2
  62. #undef inline
  63.  
  64.  
  65. #if (defined __INLINE__) || (defined __IMPL__MYUNIVERSE)
  66.  
  67. #ifndef __INLINE__
  68. #define inline
  69. #endif
  70.  
  71. /////
  72. #endif
  73.  
  74. /////3
  75. #undef inline
  76.  
  77. #ifdef __IMPL__MYUNIVERSE
  78. /////F expose @ @ instance public 
  79. int MyUniverse:: expose ()
  80. {
  81.     int        n;
  82.     Planet    *planet;
  83.  
  84.     puts( "Now comes my strange universe");
  85.  
  86.     for ( n=0, planet=Planets->first(); planet; planet=Planets->next(), n++ ) {
  87.         printf( "%s\n", planet->name());
  88.     }
  89.  
  90.     return n;    
  91. }
  92.  
  93. /////F exposeReordered @ @ instance public 
  94. int MyUniverse:: exposeReordered ()
  95. {
  96.     int        n;
  97.     Planet    *planet;
  98.  
  99.     //--- now we are using ICCL templates and own templates simultaneously
  100.     ISortedSet<Planet>  allPlanets;
  101.     SayPlanetName showPlanet;
  102.  
  103.     cout << "\n\n" << "All Planets of my strange universe (distance-sorted): \n";
  104.  
  105.     for ( n=0, planet=Planets->first(); planet; planet=Planets->next(), n++ ) {
  106.         allPlanets.add( *planet);
  107.     }
  108.  
  109.     allPlanets.allElementsDo( showPlanet);
  110.  
  111.     return n;    
  112. }
  113.  
  114. /////F MyUniverse @ @ instance public 
  115. MyUniverse:: MyUniverse ()
  116. {
  117.     Planets = new TinyList<Planet>;
  118.  
  119.     Planets->add( new Planet( "zaga", 100, 20, 30) );
  120.     Planets->add( new Planet( "shwall", 200, 10, 20) );
  121.     Planets->add( new Planet( "nurg", 50, 50, 50) );
  122. }
  123.  
  124. /////F ~MyUniverse @ @ instance public 
  125. MyUniverse:: ~MyUniverse ()
  126. {
  127.     Planet    *planet;
  128.  
  129.     for ( planet=Planets->first(); planet; planet=Planets->next() )
  130.         delete planet;
  131.  
  132.     delete Planets;
  133. }
  134.  
  135. /////
  136. #endif
  137.  
  138. #endif
  139.