Boost logo

Boost :

From: Christopher Kohlhoff (chris_at_[hidden])
Date: 2005-12-14 18:30:58


Hi Simon,

--- simon meiklejohn <simon_at_[hidden]> wrote:
> Is it feasible to accomplish something like this with a class
> something like the following (but more correct hopefully)
<snip code>

Yes, I think it's feasible. It would probably be something more
like:

class abstract_dispatcher
{
public:
  virtual ~abstract_dispatcher();
  virtual void post(function<void(void)> f) = 0;
  virtual void dispatch(function<void(void)> f) = 0;

  // Note: non-virtual template member function. Can reuse
  // asio::detail::wrapper_handler to implement it.
  template <typename Handler>
  unspecified wrap(Handler h);
};

template <typename Dispatcher_Impl>
class dispatcher : public abstract_dispatcher
{
public:
  // Forwarding constructors here ...

  void post(function<void(void)> f) { impl_.post(f); }
  void dispatch(function<void(void)> f) { impl_.dispatch(f); }

private:
  Dispatcher_Impl impl_;
};

And to use:

// An abstract dispatcher that owns its implementation
dispatcher<my_dispatcher> d(... args here ...);

// An abstract dispatcher that doesn't own the implementation.
demuxer d1;
...
dispatcher<demuxer&> d2(d1);

Cheers,
Chris


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