title: multiple callback handlers
body: <p>Consider the snippet:</p>
  
  <pre><code># include &lt;iostream&gt;
  
  # include &lt;boost/scoped_ptr.hpp&gt;
  # include &lt;boost/shared_ptr.hpp&gt;
  
  # include &lt;boost/function.hpp&gt;
  # include &lt;boost/array.hpp&gt;
  # include &lt;boost/asio.hpp&gt;
  # include &lt;boost/thread.hpp&gt;
  # include &lt;boost/thread/locks.hpp&gt;
  # include &lt;boost/bind.hpp&gt;
  # include &lt;boost/noncopyable.hpp&gt;
  
  # include &lt;boost/variant.hpp&gt;
  
  
  class DataLink {};
  class Metadata {};
  class Image {};
  
   typedef boost::function&lt;void( DataLink const&amp;, Metadata const&amp; , Image const&amp; )&gt; Handler ; 
   typedef boost::function&lt;void( Metadata const&amp; , Image const&amp; )&gt; Handler2 ; 
   typedef boost::function&lt;void( Image const&amp; )&gt; Handler3 ; 
  
  typedef boost::variant&lt;DataLink, Metadata, Image&gt; Variant; 
  
  
  
  enum callbackHandler { link_enum, meta_enum, image_enum };
  class Worker {
    Handler  callBack ;
    //Handler2 callBack2 ;
    //Handler3 callBack3 ;
  
    DataLink dlink;
    Metadata meta ;
    Image    img ;
  
    callbackHandler handlerEnum ;
  
  public :
    Worker ( const Handler&amp; handler ) 
    : callBack ( handler ) 
     {}
    //Worker ( const Handler2&amp; handler ) 
    //: callBack2 ( handler ) 
    // {}
    //Worker ( const Handler3&amp; handler ) 
    //: callBack3 ( handler ) 
    // {}
  
    void Image ( ) {
      // update the img object 
      // invoke call back 
      handlerEnum = image_enum ;
      //const std::type_info&amp; xxx = callBack.target_type();
      //std::cout &lt;&lt; xxx.raw_name() &lt;&lt; std::endl;
      callBack ( dlink, meta, img ) ;
    }
  
    void Metadata ( ) {
      // update the meta object 
      // invoke call back 
      handlerEnum = meta_enum ;
      callBack ( dlink, meta, img ) ;
    }
  
    void Dlink ( ) {
      // update the link object 
      // invoke call back 
      handlerEnum = link_enum ;
      callBack ( dlink, meta, img ) ;
    }
  
    callbackHandler getHandlerType() { return handlerEnum ; }
  };
  
  class Foo {
    Worker *ptrWorker ;
  public :
    Foo () 
    : ptrWorker( 0 ) 
    {}
  
    void callback ( DataLink const&amp; d, Metadata const&amp; m , Image const&amp;  i ) {
      callbackHandler tt = ptrWorker-&gt;getHandlerType();
      if ( tt == image_enum ) {
        std::cout &lt;&lt;  "Image object " &lt;&lt; std::endl;
      }
      if ( tt == meta_enum ) {
        std::cout &lt;&lt;  "Meta object " &lt;&lt; std::endl;
      }
      if ( tt == link_enum ) {
        std::cout &lt;&lt;  "Link object " &lt;&lt; std::endl;
      }
  
    }
    bool start () {
      ptrWorker = new ( std::nothrow ) Worker ( boost::bind ( &amp;Foo::callback, this, _1, _2, _3 ) );
      if ( !ptrWorker ) {
        return - 1 ;
      }
    }
    void testWorker() {
      ptrWorker-&gt;Image() ;
      ptrWorker-&gt;Metadata() ;
      ptrWorker-&gt;Dlink() ;
    }
  };
  
  int main() {
    Foo f;
    f.start() ;
    f.testWorker() ;
    std::cin.get() ;
  }
  </code></pre>
  
  <p>The commented out constructors allows me to add support for Handler2 and Handler3, however is there a way to determine the handler that was passed to the constructor of the Worker class?   At present the member functions Metadata, Image and Dlink use the 'callBack' object.  I'll need to make a distinction if the user handler passed in another handler - say Handler2</p>
  
  <p>The fact that I need to use enums to implement, what is effectively my own type-system (in the line of a discrimatory union - aka, a variant), is also a sure sign that the design needs a little re-thinking so in that case I'm open for a redesign. Having to have N-1 dummy handlers (ie, at any one time only one handler is being used and the others are just there doing nothing) defined in the class screams confused and low cohesive object model but who knows.</p>