home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / ESHAPRP.H < prev    next >
C/C++ Source or Header  |  1991-12-04  |  4KB  |  107 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 R P . H                         //
  9. //                                                            //
  10. //         Interface for class ShapeRep.                      //
  11. //                                                            //
  12. //************************************************************//
  13.  
  14. #define _SHAPEREP_H
  15. #ifndef _SHAPE_H
  16. #include "eshape.h"
  17. #endif
  18. #ifndef _COORDINATE_H
  19. #include "ecoord.h"
  20. #endif
  21.  
  22. class ShapeRep: public Thing {
  23. public:
  24.     /* all user-defined operators go here.  Note that, because
  25.      * of the use of operator->, this signature does not have
  26.      * to be mimicked in the Shape class.  However, the Shape's
  27.      * rep field has to be appropriately typed.  Assignment
  28.      * operators do not go here, but in the Shape class.
  29.      *
  30.      * return_type should either be a primitive
  31.      * type, or of type Shape, of type Shape&, or
  32.      * a concrete data type
  33.      */
  34.     virtual void rotate(double);
  35.     virtual void move(Coordinate);
  36.     virtual void draw();
  37.     virtual void erase();
  38.  
  39.     // constructors
  40.     Shape make(Coordinate,Thingp);
  41.     Shape make(Coordinate,Coordinate,Thingp);
  42.     Shape make(Coordinate,Coordinate,Coordinate,Thingp);
  43.  
  44.     // these are overridden in the derived classes;
  45.     // their default action is to call the ones above,
  46.     // with Thingp suitably defaulted
  47.     virtual Shape make();
  48.     virtual Shape make(Coordinate);
  49.     virtual Shape make(Coordinate,Coordinate);
  50.     virtual Shape make(Coordinate,Coordinate,Coordinate);
  51.  
  52.     // routine to mark this object as used for the
  53.     // Baker algorithm
  54.     virtual void mark();
  55.  
  56.     // type returns a pointer to an object's exemplar
  57.     Thing *type();
  58.  
  59.     // Do garbage collection.  If the argument is zero,
  60.     // sweep the current pool;  if non-zero, build a
  61.     // new pool to hold objects of the designated size,
  62.     // and forget about the old pool
  63.     virtual void gc(size_t = 0);
  64.  
  65.     // class constructors
  66.     ShapeRep();
  67.     ~ShapeRep();
  68.     ShapeRep(Exemplar);
  69.  
  70.     // used to orchestrate order of initialization of
  71.     // static, class-specific information
  72.     static void init();
  73. protected:
  74.     friend class Shape;
  75.     Coordinate center;
  76.  
  77.     // this is the "type field"
  78.     Top *exemplarPointer;
  79.  
  80.     // memory management state variables:  Space
  81.     // is FromSpace or ToSpace; gcmark is the mark
  82.     // bit for marking objects under Baker;  inUse
  83.     // means that this object has been returned to
  84.     // a caller for use, but that it hasn't yet been
  85.     // reclaimed by the garbage collector
  86.     unsigned char space:1, gcmark:1, inUse:1;
  87. protected:
  88.     // do common processing for (the sweep phase of)
  89.     // Baker garbage collection
  90.     static void gcCommon(size_t nbytes,
  91.         const size_t poolInitialized,
  92.         const int PoolSize, Char_p &h);
  93.  
  94.     // These two "constants" designate From space and
  95.     // To space for the Baker algorithm.  They are flipped
  96.     // every garbage collection cycle
  97.     static unsigned char FromSpace, ToSpace;
  98.  
  99.     // general memory management operators, which use the
  100.     // pool operated on by gc
  101.     static void *operator new(size_t);
  102.     static void operator delete(void *);
  103.  
  104.     // a typeless shape usable as a default return value
  105.     static Shape *aShape;
  106. };
  107.