home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / IDIOMS.ZIP / 9-11.C < prev    next >
Text File  |  1991-12-04  |  847b  |  35 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. int
  7. Thing::docutover() {
  8.     if (!updateCountVal) {
  9.         updateCountVal = refCountVal;
  10.     }
  11.     return !--updateCountVal;
  12. }
  13.  
  14. typedef Thing *Thingp;
  15.  
  16. void
  17. Shape::dataUpdate(Thingp &oldExemplar,
  18.                    const Thingp newExemplar) {
  19.     Thing *saveRep;
  20.     Shape *sp;
  21.     for (Listiter<Shape*> p = allShapes;
  22.         p.next(sp);  p++) {
  23.         if (sp->rep->type() == &oldExemplar) {
  24.         if (p->rep->docutover()) {
  25.                 saveRep = sp->rep;
  26.                 sp->rep = (ShapeRep*)sp->rep->cutover();
  27.                 delete saveRep;
  28.             }
  29.         }
  30.     }
  31.     saveRep = oldExemplar;
  32.     oldExemplar = newExemplar;
  33.     delete saveRep;
  34. }
  35.