home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / CL187A.ZIP / EXAMP501.CPP < prev    next >
C/C++ Source or Header  |  1994-03-15  |  2KB  |  75 lines

  1. // examp501.cpp -- link with pitem.obj, cl.obj and graphics.lib.
  2. // Container Lite (CL v 1.87a)
  3. // (C) Copyright 1994  John Webster Small
  4. // All rights reserved
  5.  
  6. //#define CL_NO_TEMPLATES
  7.  
  8. #include "cl.h"        // endm, nextm
  9. #define BGI_PATHNAME "\\bc4\\bgi"
  10. #include "gconsole.cpp"
  11.  
  12. class Shape {
  13.     int x, y;
  14.     friend ostream& operator<<(ostream&,Shape&);
  15.     friend istream& operator>>(istream&,Shape&);
  16. public:
  17.     // default constructor required for stream
  18.     //    extraction
  19.     Shape   (const Shape& s)
  20.         { x = s.x; y = s.y; }
  21.     Shape   (int x = GETRANDX(),
  22.         int y = GETRANDY())
  23.         { this->x = x; this->y = y; }
  24.     int getx() { return x; }
  25.     int gety() { return y; }
  26.     Shape&  setxy(int x = GETRANDX(),
  27.         int y = GETRANDY())
  28.         { this->x = x; this->y = y;
  29.         return *this; }
  30.     virtual void show(int color = GETRANDCOLOR(),
  31.         int xxpose = 0, int yxpose = 0,
  32.         int scale = 1)
  33.         { PUTPIX(x,y,color); }
  34.     virtual char * name()
  35.         { return "shape (pixel)"; }
  36.     virtual ~Shape() {}
  37. };
  38.  
  39. // Shape stream insertion/extraction operators
  40. inline ostream& operator<<(ostream& os, Shape& s)
  41.     { return os << s.x << endm << s.y; }
  42. inline istream& operator>>(istream& is, Shape& s)
  43.     { return is >> s.x >> nextm >> s.y; }
  44.  
  45. #ifdef  CL_NO_TEMPLATES
  46.     #define   ITEM              Shape
  47.     #define   CL_CLONE_BYTES
  48.     #define   CL_STRM_OPS
  49.     #define   CL            Shapes
  50.     #include "cl.hf"
  51. #else
  52.     CL_CLONE_BYTES(Shape)
  53.     CL_STRM_OPS(Shape)
  54.     #define   Shapes CL<Shape>
  55. #endif
  56.  
  57. #define  ShapesFile "shapes.tmp"
  58.  
  59. main()
  60. {
  61.     openGraphics();
  62.     Shapes sb(CL_NEW | CL_DEL |
  63.         CL_SAVE,1000);
  64.     Shape s;
  65.     while (sb.insQNew(&s.setxy()));
  66.     sb.save(ShapesFile);
  67.     sb.allDel();
  68.     sb.load(ShapesFile);
  69.     while (++sb)  sb.get()->show();
  70.     cout << "Press <enter> to exit" << endl;
  71.     (void) cin.get();
  72.     closeGraphics();
  73.     return 0;
  74. }
  75.