home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / GRAPH / GRAPH.CPP < prev    next >
Text File  |  1995-03-15  |  4KB  |  136 lines

  1. /*************************************************************************
  2.   IBM C/C++ Tools Version 3.00 - Collection Class Library
  3.  (C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
  4.  IBM.  All Rights Reserved.  US Government Users Restricted Rights - Use,
  5.  duplication or disclosure restricted by GSA ADP Schedule Contract with
  6.  IBM Corp.
  7.  *************************************************************************/
  8.  
  9. /*--------------------------------------------------------------*\
  10. |  graph.CPP  - demonstrate how to use collection class pointers |
  11. |                                      """"""""""""""""""""""""" |
  12. |  Different graphical shapes (curves, circles, lines)           |
  13. |  inherit from an abstract class  "graph".                      |
  14. |  Managed element pointers for these different shapes are       |
  15. |  stored in one collection, a key sorted set.                   |
  16. |  These pointers are used to draw the different shapes.         |
  17. \*--------------------------------------------------------------*/
  18.  
  19. #include <iostream.h>
  20. #include "graph.h"
  21. #include "line.h"
  22. #include "circle.h"
  23. #include "curve.h"
  24.  
  25. #include <iptr.h>
  26. #include <iksset.h>
  27.  
  28. typedef IMngElemPointer <Graphics> MngGraphicsPointer;
  29. typedef IKeySortedSet <MngGraphicsPointer, int> MngPointerKSet;
  30.  
  31. ostream & operator <<
  32.          (ostream & sout,
  33.           MngPointerKSet
  34.           const& mgdPointerKSet)
  35. {
  36.         MngGraphicsPointer drawObject;
  37.         MngPointerKSet::Cursor
  38.         gpsCursor(mgdPointerKSet);
  39.  
  40.    forCursor(gpsCursor)
  41.      {
  42.         drawObject = gpsCursor.element();
  43.  
  44.         sout << endl
  45.              << " Key is: " <<  drawObject->graphicsKey()
  46.              << endl
  47.              << " ID is: " <<  drawObject->id()
  48.              << endl;
  49.  
  50.         drawObject->draw();
  51.  
  52.      } /* endfor */
  53.  
  54.  
  55.    return sout;
  56. }
  57.  
  58.  
  59.  int main ()
  60.  
  61.  {
  62.  
  63.      MngPointerKSet graphMngPointerKSet;
  64.  
  65.      /**********************************************************/
  66.      /*   Adding  curve pointers, circle pointers and line     */
  67.      /*   pointers to the graphMngPointerKSet.                 */
  68.      /**********************************************************/
  69.  
  70.       //Creating curve objects and adding pointers to the collections
  71.  
  72.       MngGraphicsPointer pcurve1 (new Curve
  73.        (10, "Curve 1",
  74.        1.1, 4.3,
  75.        2.1, 6.4,
  76.        3.1, 9.7,
  77.        4.1, 6.5,
  78.        5.1, 7.4), IINIT);
  79.       MngGraphicsPointer pcurve2 (new Curve
  80.        (20 ,"Curve 2",
  81.        1.2, 3.9,
  82.        2.2, 5.9,
  83.        3.2, 8.8,
  84.        4.2, 7.5,
  85.        5.2, 9.4), IINIT);
  86.  
  87.       graphMngPointerKSet.add(pcurve1);
  88.       graphMngPointerKSet.add(pcurve2);
  89.  
  90.  
  91.       //Creating circle objects and adding pointers to the collections
  92.  
  93.       MngGraphicsPointer pcircle1 (new Circle
  94.        (40 , "Circle 1" , 1.0, 1.0, 1.0), IINIT);
  95.       MngGraphicsPointer pcircle2 (new Circle
  96.        (50 , "Circle  2", 2.0, 2.0, 2.0), IINIT);
  97.  
  98.       graphMngPointerKSet.add(pcircle1);
  99.       graphMngPointerKSet.add(pcircle2);
  100.  
  101.       //Creating line objects and adding pointers to the collections
  102.  
  103.       MngGraphicsPointer pline1 (new Line
  104.        (70 , "Line 1" , 1.1 , 1.1 , 5.1 , 5.1), IINIT);
  105.       MngGraphicsPointer pline2 (new Line
  106.        (80 , "Line 2" , 2.2 , 2.2 , 5.2 , 5.2), IINIT);
  107.       /** if you want to have a normal C-pointer: **/
  108.       Line* cPointerToLine = new Line
  109.        (90 , "Line 3" , 3.3 , 3.3 , 5.3 , 5.3);
  110.       MngGraphicsPointer pline3 (cPointerToLine, IINIT);
  111.  
  112.       graphMngPointerKSet.add(pline1);
  113.       graphMngPointerKSet.add(pline2);
  114.       graphMngPointerKSet.add(pline3);
  115.  
  116.       cout << "Drawing the shapes from the key set "
  117.            << "of Managed Pointers: "
  118.            << endl
  119.            << graphMngPointerKSet
  120.            << endl << " " << endl;
  121.  
  122.       graphMngPointerKSet.elementWithKey(70)->draw();
  123.       cPointerToLine->draw();
  124.       pline3->draw();
  125.  
  126.   /********************************************************/
  127.   /* Now we are about to end the program.                 */
  128.   /* The objects referenced by managed pointers are       */
  129.   /* automatically deleted. See what happens in the       */
  130.   /* output of the program.                               */
  131.   /********************************************************/
  132.  
  133.   return 0;
  134.  
  135.  }
  136.