home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / ESHAPE.H < prev    next >
C/C++ Source or Header  |  1991-12-04  |  3KB  |  102 lines

  1. /* Copyright (c) 1992 by AT&T Bell Laboratories. */
  2. /* Advanced C++ Programming Styles and Idioms */
  3. /* James O. Coplien */
  4. /* All rights reserved. */
  5.  
  6. //************************************************************//
  7. //                                                            //
  8. //     F I L E :    E S H A P E . H                           //
  9. //                                                            //
  10. //         Interface for class Shape                          //
  11. //                                                            //
  12. //************************************************************//
  13.  
  14. // Class Shape is the user interface to the entire graphics
  15. // package--all other classes are just used for internal
  16. // implementation
  17.  
  18. #ifndef _SHAPE_H
  19. #define _SHAPE_H
  20. #include "ek.h"
  21. #endif
  22. #include "List.h"
  23.  
  24. // forward reference declaration
  25. class ShapeRep;
  26.  
  27. class Shape: public Top {    // Top defined in k.h
  28. public:
  29.     // forwards all operations to rep
  30.     ShapeRep *operator->() const {
  31.         return rep;
  32.     }
  33.  
  34.     // constructors and orthodox canonical form
  35.     Shape();
  36.     Shape(ShapeRep&);
  37.     ~Shape();
  38.     Shape(Shape& x);
  39.     Shape& operator=(Shape& x);
  40.  
  41.     // yield type of letter object
  42.     Top *type();
  43.     // replace one exemplar with a new version,
  44.     // updating its instances using the user-
  45.     // provided cutover function
  46.     void dataUpdate(Thingp&, const Thingp);
  47.  
  48.     // general purpose function that can be loaded
  49.     // by a user to do whatever they want
  50.     Top *doit();
  51.  
  52.     // garbage collector for Shape empire
  53.     void gc();
  54.  
  55.     // routines for exemplars to register and
  56.     // unregister themselves with Shape
  57.     void Register(ShapeRep*);
  58.     void UnRegister(ShapeRep*);
  59.  
  60.     // initializes class variables
  61.     static void init();    // class initialization
  62. private:
  63.     friend ShapeRep;
  64.     // operator new is called only from ShapeRep.
  65.     // operator delete is unused
  66.     static void *operator new(size_t s) {
  67.         return ::operator new(s);
  68.     }
  69.     static void operator delete(void *) { }
  70.  
  71.     // keep a list of all instances of myself
  72.     static List<Topp> *allShapes;
  73.  
  74.     // keep a list of all exemplars of things
  75.     // derived from ShapeRep
  76.     static List<Thingp> *allShapeExemplars;
  77.  
  78.     // pointer to the business end of an actual Shape
  79.     ShapeRep *rep;
  80. };
  81.  
  82. typedef Shape *Shapepointer;
  83.  
  84. // pointer to the Shape exemplar, dynamically
  85. // created by Shape::init
  86. extern Shape *shape;         // exemplar
  87.  
  88. class Point: public Shape {
  89. public:
  90.     // . . . .
  91.     ShapeRep *operator->() const;
  92.     Point();
  93.     ~Point();
  94. } point;
  95.  
  96. // users shouldn't have to know about, or include,
  97. // the header file for ShapeRep
  98.  
  99. #ifndef _SHAPEREP_H
  100. #include "eshaprp.h"
  101. #endif
  102.