home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWMMMMooooddddeeeellll((((3333CCCC++++++++)))) RRRRWWWWMMMMooooddddeeeellll((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWModel - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/model.h> ((((aaaabbbbssssttttrrrraaaacccctttt bbbbaaaasssseeee ccccllllaaaassssssss)))) DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This abstract base class has been designed to implement the "Model" leg of a Model-View-Controller architecture. A companion class, RRRRWWWWMMMMooooddddeeeellllCCCClllliiiieeeennnntttt, supplies the "View" leg. It maintains a list of dependent RRRRWWWWMMMMooooddddeeeellllCCCClllliiiieeeennnntttt objects. When member function cccchhhhaaaannnnggggeeeedddd((((vvvvooooiiiidddd****)))) is called, the list of dependents will be traversed, calling uuuuppppddddaaaatttteeeeFFFFrrrroooommmm((((RRRRWWWWMMMMooooddddeeeellll****,,,, vvvvooooiiiidddd****)))) for each one, with itself as the first argument. Subclasses of RRRRWWWWMMMMooooddddeeeellllCCCClllliiiieeeennnntttt should be prepared to accept such a call. PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee None EEEExxxxaaaammmmpppplllleeee This is an incomplete and somewhat contrived example in that it does not completely define the classes involved. "Dial" is assumed to be a graphical representation of the internal settings of "Thermostat." The essential point is that there is a dependency relationship between the "Thermostat" and the "Dial": when the setting of the thermostat is changed, the dial must be notified so that it can update itself to reflect the new setting of the thermostat. #include <rw/model.h> class Dial : public RWModelClient { public: virtual void updateFrom(RWModel* m, void* d); }; class Thermostat : public RWModel { double setting; public: Thermostat( Dial* d ) { addDependent(d); } PPPPaaaaggggeeee 1111 RRRRWWWWMMMMooooddddeeeellll((((3333CCCC++++++++)))) RRRRWWWWMMMMooooddddeeeellll((((3333CCCC++++++++)))) double temperature() const { return setting; } void setTemperature(double t) { setting = t; changed(); } }; void Dial::updateFrom(RWModel* m, void*) { Thermostat* t = (Thermostat*)m; double temp = t->temperature(); // Redraw graphic. } PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrr RRRRWWWWMMMMooooddddeeeellll(); When called by the specializing class, sets up the internal ordered list of dependents. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaaddddddddDDDDeeeeppppeeeennnnddddeeeennnntttt(RWModelClient* m); Adds the object pointed to by mmmm to the list of dependents of self. void rrrreeeemmmmoooovvvveeeeDDDDeeeeppppeeeennnnddddeeeennnntttt(RWModelClient* m); Removes the object pointed to by mmmm from the list of dependents of self. virtual void cccchhhhaaaannnnggggeeeedddd(void* d); Traverse the internal list of dependents, calling member function uuuuppppddddaaaatttteeeeFFFFrrrroooommmm((((RRRRWWWWMMMMooooddddeeeellll****,,,, vvvvooooiiiidddd****)))) for each one, with self as the first argument and dddd as the second argument. PPPPaaaaggggeeee 2222