home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / librw / RWModel.z / RWModel
Encoding:
Text File  |  1998-10-30  |  4.7 KB  |  133 lines

  1.  
  2.  
  3.  
  4. RRRRWWWWMMMMooooddddeeeellll((((3333CCCC++++++++))))                                                    RRRRWWWWMMMMooooddddeeeellll((((3333CCCC++++++++))))
  5.  
  6.  
  7.  
  8. NNNNaaaammmmeeee
  9.      RWModel - Rogue Wave library class
  10.  
  11. SSSSyyyynnnnooooppppssssiiiissss
  12.               #include <rw/model.h>
  13.  
  14.  
  15.  
  16.               ((((aaaabbbbssssttttrrrraaaacccctttt bbbbaaaasssseeee ccccllllaaaassssssss))))
  17.  
  18.  
  19.  
  20.  
  21. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn
  22.      This abstract base class has been designed to implement the "Model" leg
  23.      of a Model-View-Controller architecture.  A companion class,
  24.      RRRRWWWWMMMMooooddddeeeellllCCCClllliiiieeeennnntttt, supplies the "View" leg. It maintains a list of dependent
  25.      RRRRWWWWMMMMooooddddeeeellllCCCClllliiiieeeennnntttt objects.  When member function cccchhhhaaaannnnggggeeeedddd((((vvvvooooiiiidddd****)))) is called,
  26.      the list of dependents will be traversed, calling uuuuppppddddaaaatttteeeeFFFFrrrroooommmm((((RRRRWWWWMMMMooooddddeeeellll****,,,,
  27.      vvvvooooiiiidddd****)))) for each one, with itself as the first argument.  Subclasses of
  28.      RRRRWWWWMMMMooooddddeeeellllCCCClllliiiieeeennnntttt should be prepared to accept such a call.
  29.  
  30. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee
  31.      None
  32.  
  33. EEEExxxxaaaammmmpppplllleeee
  34.      This is an incomplete and somewhat contrived example in that it does not
  35.      completely define the classes involved.  "Dial" is assumed to be a
  36.      graphical representation of the internal settings of "Thermostat."  The
  37.      essential point is that there is a dependency relationship between the
  38.      "Thermostat" and the "Dial": when the setting of the thermostat is
  39.      changed, the dial must be notified so that it can update itself to
  40.      reflect the new setting of the thermostat.
  41.  
  42.               #include <rw/model.h>
  43.  
  44.  
  45.  
  46.               class Dial : public RWModelClient {
  47.           public:
  48.             virtual void     updateFrom(RWModel* m, void* d);
  49.           };
  50.  
  51.  
  52.               class Thermostat : public RWModel {
  53.  
  54.  
  55.  
  56.                 double setting;
  57.           public:
  58.             Thermostat( Dial* d )
  59.               { addDependent(d); }
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RRRRWWWWMMMMooooddddeeeellll((((3333CCCC++++++++))))                                                    RRRRWWWWMMMMooooddddeeeellll((((3333CCCC++++++++))))
  71.  
  72.  
  73.  
  74.             double temperature() const
  75.               { return setting; }
  76.             void setTemperature(double t)
  77.               { setting = t; changed(); }
  78.           };
  79.  
  80.  
  81.               void Dial::updateFrom(RWModel* m, void*) {
  82.  
  83.  
  84.  
  85.                 Thermostat* t = (Thermostat*)m;
  86.             double temp = t->temperature();
  87.             // Redraw graphic.
  88.           }
  89.  
  90. PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr
  91.               RRRRWWWWMMMMooooddddeeeellll();
  92.  
  93.  
  94.      When called by the specializing class, sets up the internal ordered list
  95.      of dependents.
  96.  
  97. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss
  98.               void
  99.           aaaaddddddddDDDDeeeeppppeeeennnnddddeeeennnntttt(RWModelClient* m);
  100.  
  101.  
  102.      Adds the object pointed to by mmmm to the list of dependents of self.
  103.  
  104.               void
  105.           rrrreeeemmmmoooovvvveeeeDDDDeeeeppppeeeennnnddddeeeennnntttt(RWModelClient* m);
  106.  
  107.  
  108.      Removes the object pointed to by mmmm from the list of dependents of self.
  109.  
  110.               virtual void
  111.           cccchhhhaaaannnnggggeeeedddd(void* d);
  112.  
  113.  
  114.      Traverse the internal list of dependents, calling member function
  115.      uuuuppppddddaaaatttteeeeFFFFrrrroooommmm((((RRRRWWWWMMMMooooddddeeeellll****,,,, vvvvooooiiiidddd****)))) for each one, with self as the first argument
  116.      and dddd as the second argument.
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.