home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / graph / graph.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  5.0 KB  |  145 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. |  graph.CPP  - demonstrate how to use collection class pointers |
  20. |                                      """"""""""""""""""""""""" |
  21. |  Different graphical shapes (curves, circles, lines)           |
  22. |  inherit from an abstract class  "graph".                      |
  23. |  Managed element pointers for these different shapes are       |
  24. |  stored in one collection, a key sorted set.                   |
  25. |  These pointers are used to draw the different shapes.         |
  26. \*--------------------------------------------------------------*/
  27.  
  28. #include <iostream.h>
  29. #include "graph.h"
  30. #include "line.h"
  31. #include "circle.h"
  32. #include "curve.h"
  33.  
  34. #include <iptr.h>
  35. #include <ikss.h>
  36.  
  37. typedef IMngElemPointer <Graphics> MngGraphicsPointer;
  38. typedef IKeySortedSet <MngGraphicsPointer, int> MngPointerKSet;
  39.  
  40. ostream & operator <<
  41.          (ostream & sout,
  42.           MngPointerKSet
  43.           const& mgdPointerKSet)
  44. {
  45.         MngGraphicsPointer drawObject;
  46.         MngPointerKSet::Cursor
  47.         gpsCursor(mgdPointerKSet);
  48.  
  49.    forICursor(gpsCursor)
  50.      {
  51.         drawObject = gpsCursor.element();
  52.  
  53.         sout << endl
  54.              << " Key is: " <<  drawObject->graphicsKey()
  55.              << endl
  56.              << " ID is: " <<  drawObject->id()
  57.              << endl;
  58.  
  59.         drawObject->draw();
  60.  
  61.      } /* endfor */
  62.  
  63.  
  64.    return sout;
  65. }
  66.  
  67.  
  68.  int main ()
  69.  
  70.  {
  71.  
  72.      MngPointerKSet graphMngPointerKSet;
  73.  
  74.      /**********************************************************/
  75.      /*   Adding  curve pointers, circle pointers and line     */
  76.      /*   pointers to the graphMngPointerKSet.                 */
  77.      /**********************************************************/
  78.  
  79.       //Creating curve objects and adding pointers to the collections
  80.  
  81.       MngGraphicsPointer pcurve1 (new Curve
  82.        (10, "Curve 1",
  83.        1.1, 4.3,
  84.        2.1, 6.4,
  85.        3.1, 9.7,
  86.        4.1, 6.5,
  87.        5.1, 7.4), IINIT);
  88.       MngGraphicsPointer pcurve2 (new Curve
  89.        (20 ,"Curve 2",
  90.        1.2, 3.9,
  91.        2.2, 5.9,
  92.        3.2, 8.8,
  93.        4.2, 7.5,
  94.        5.2, 9.4), IINIT);
  95.  
  96.       graphMngPointerKSet.add(pcurve1);
  97.       graphMngPointerKSet.add(pcurve2);
  98.  
  99.  
  100.       //Creating circle objects and adding pointers to the collections
  101.  
  102.       MngGraphicsPointer pcircle1 (new Circle
  103.        (40 , "Circle 1" , 1.0, 1.0, 1.0), IINIT);
  104.       MngGraphicsPointer pcircle2 (new Circle
  105.        (50 , "Circle  2", 2.0, 2.0, 2.0), IINIT);
  106.  
  107.       graphMngPointerKSet.add(pcircle1);
  108.       graphMngPointerKSet.add(pcircle2);
  109.  
  110.       //Creating line objects and adding pointers to the collections
  111.  
  112.       MngGraphicsPointer pline1 (new Line
  113.        (70 , "Line 1" , 1.1 , 1.1 , 5.1 , 5.1), IINIT);
  114.       MngGraphicsPointer pline2 (new Line
  115.        (80 , "Line 2" , 2.2 , 2.2 , 5.2 , 5.2), IINIT);
  116.       /** if you want to have a normal C-pointer: **/
  117.       Line* cPointerToLine = new Line
  118.        (90 , "Line 3" , 3.3 , 3.3 , 5.3 , 5.3);
  119.       MngGraphicsPointer pline3 (cPointerToLine, IINIT);
  120.  
  121.       graphMngPointerKSet.add(pline1);
  122.       graphMngPointerKSet.add(pline2);
  123.       graphMngPointerKSet.add(pline3);
  124.  
  125.       cout << "Drawing the shapes from the key set "
  126.            << "of Managed Pointers: "
  127.            << endl
  128.            << graphMngPointerKSet
  129.            << endl << " " << endl;
  130.  
  131.       graphMngPointerKSet.elementWithKey(70)->draw();
  132.       cPointerToLine->draw();
  133.       pline3->draw();
  134.  
  135.   /********************************************************/
  136.   /* Now we are about to end the program.                 */
  137.   /* The objects referenced by managed pointers are       */
  138.   /* automatically deleted. See what happens in the       */
  139.   /* output of the program.                               */
  140.   /********************************************************/
  141.  
  142.   return 0;
  143.  
  144.  }
  145.