Boost logo

Boost :

From: simon meiklejohn (simon_at_[hidden])
Date: 2005-12-13 06:20:23


As you may have noticed i'm quite keen on a 'base class'
for the Asio Dispatcher concept - for two reasons.

1. an easy path to inject custom dispatchers into a system.
(clearly cant replace demuxer at will this way though)

2. a convenient type for passing dispatchers of any kind
around the system, eg. to parameterise components
with a dispatch policy without forcing the components
to be templates themselves (presumably they would need
to be if they had to store an instance of 'any' kind of dispatcher)

Is it feasible to accomplish something like this with a class
something like the following (but more correct hopefully)

class polymorphic_dispatcher
{
public:
    template<typename T>
    polymorphic_dispatcher( T& non_poly_dispatcher )
    {
        wrap_ = boost::bind( &T::wrap, non_poly_dispatcher );
        post_ = boost::bind( &T::post, non_poly_dispatcher );
        dispatch_ = boost::bind( &T::dispatch, non_poly_dispatcher );
    }
    template<typename T>
    boost::function<void (void)> wrap( T func )
   {
        return wrap_(func);
    }
    template<typename T>
    boost::function<void (void)> wrap( T func )
   {
        return wrap_(func);
    }
    // dispatch likewise
private:
    boost:::function<....> wrap_; // ellipsis cause i've no idea what
should be in there
    boost:::function<....> post_;
    boost:::function<....> dispatch_;
};

now then

    asio::locking_dispatcher disp1;
    asio::demuxer disp2;
    polymorphic_dispatcher disp3(disp1), disp4(disp2);

Little tools like these (assuming feasible etc) would be great additions
to asio.

Cheers

Simon


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