#include <CallBack.h>
Public Member Functions | |
Report () | |
virtual | ~Report () |
See RedirectCallback for how to define a callback interface class.
A Report is the instance of a callback interface, the sender addresses. Usg. a Report will define all interface methods to use the provided default implementation. The inherited callback interface itself is inaccessible from outside Report (and deived classes are encourgaged tokeep it that way). But it may be redirected to any real recipient using redirectTo.
A sender may invoke the callbacks by creating an instance of Send. Send provides the callback inteface via operator->. Additionally it triggers reportbegin and reportend (see ReportCallback).
What's to be done is, define the abstract callback interface and provide a reasonable default implementation:
struct InstCallback : public RedirectCallback<InstCallback> { virtual void start() = 0; virtual void progress() = 0; virtual void stop() = 0; };
void InstCallback::start() { ... } void InstCallback::progress() { ... } void InstCallback::stop() { ... }Create a Report class:
class InstReport : public Report<InstCallback> { virtual void reportbegin() { InstCallback::reportbegin(); } virtual void reportend() { InstCallback::reportend(); } virtual void start() { InstCallback::start(); } virtual void progress() { InstCallback::progress(); } virtual void stop() { InstCallback::stop(); } };
InstReport instReport;Send reports to instReport:
void inst() { InstReport::Send report( instReport ); 1 // construction of report report->start(); 2 ... report->progress(); 3 ... report->stop(); 4 } 5 // destruction of reportCreate a recipient:
class InstRecieve : public InstCallback { virtual void reportbegin() { ... } virtual void reportend() { ... } virtual void start() { ... } virtual void progress() { ... } virtual void stop() { ... } };
InstRecieve instRecieve;Let it recieve reports to instReport:
instReport.redirectTo( instRecieve );Invocation of inst() now triggers:
1 instRecieve->reportbegin(); 2 instRecieve->start(); 3 instRecieve->progress(); 4 instRecieve->stop(); 5 instRecieve->reportend();
Constructor & Destructor Documentation
|
Constructor. |
|
Destructor. |