Boost logo

Boost :

From: Jesse Jones (jesjones_at_[hidden])
Date: 2001-05-10 22:14:29


>The way I'd do this is more like:
>
>class MyControl
>{
>public:
>
> MyControl();
> void DoCommand1();
>
>protected:
>
> virtual void onActivate();
> virtual void onDeactivate();
> virtual void onClick();
>
>private:
>
> std::list<Command> cmds_;
>};
>
>MyControl::MyControl()
>{
> cmds_.push_back(Command(L"cmd1", bind(this, &MyControl::DoCommand1)));
>// and so on
>}
>
>void MyControl::onActivate()
>{
> for_each(cmds_.begin(), cmds_.end(), bind(&Command::onActivate));
>}
>
>void MyControl::onDeactivate()
>{
> for_each(cmds_.begin(), cmds_.end(), bind(&Command::onDeactivate));
>}
>
>void MyControl::onClick()
>{
> for_each(cmds_.begin(), cmds_.end(), bind(&Command::onClick));
>}
>
>Did I understand the design correctly?

Of course. :-)

>Actually I'd go a step further and define
>
>class Commands
>{
>public:
>
> Commands() {}
>
> void push_back(wstring name, function<void> const & f);
> void onActivate();
> void onDeactivate();
> void onClick();
>
>private:
>
> std::list<Command> cmds_;
>};
>
>and then reuse Commands for each control.

This is good and arguably better than what I'm currently using. Now
*I'm* not sure whether we really need a callback class. :-) I will
say that if boost had a callback class I would probably use it
(although maybe not with menu commands).

   -- Jesse


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk