Add 1-arity and 2-arity binding to CompletionCall

This commit is contained in:
Vinnie Falco
2013-08-16 03:25:00 -07:00
parent 462a1394d7
commit d22b236d2d

View File

@@ -30,9 +30,31 @@ class CompletionCall
public: public:
typedef void result_type; typedef void result_type;
template <class Handler> // Construction from Handler with zero arguments
//
template <typename Handler>
CompletionCall (BOOST_ASIO_MOVE_ARG(Handler) handler) CompletionCall (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_call (new CallType <Handler> (BOOST_ASIO_MOVE_CAST(Handler)(handler))) : m_call (new CallType0 <Handler> (BOOST_ASIO_MOVE_CAST(Handler)(handler)))
{
}
// Creates a CompletionHandler with one parameter bound to Handler
// This can convert an ErrorCall to a CompletionCall, suitable
// for calling asio::io_service::post()
//
template <typename Handler, typename P1>
CompletionCall (BOOST_ASIO_MOVE_ARG(Handler) handler, P1 p1)
: m_call (new CallType1 <Handler, P1> (BOOST_ASIO_MOVE_CAST(Handler)(handler), p1))
{
}
// Creates a CompletionHandler with two parameters bound to Handler
// This can convert a TransferCall to a CompletionCall, suitable
// for calling asio::io_service::post()
//
template <typename Handler, typename P1, typename P2>
CompletionCall (BOOST_ASIO_MOVE_ARG(Handler) handler, P1 p1, P2 p2)
: m_call (new CallType2 <Handler, P1, P2> (BOOST_ASIO_MOVE_CAST(Handler)(handler), p1, p2))
{ {
} }
@@ -53,9 +75,9 @@ private:
}; };
template <class Handler> template <class Handler>
struct CallType : Call struct CallType0 : Call
{ {
CallType (BOOST_ASIO_MOVE_ARG(Handler) handler) CallType0 (BOOST_ASIO_MOVE_ARG(Handler) handler)
: m_handler (handler) : m_handler (handler)
{ {
} }
@@ -68,6 +90,44 @@ private:
Handler m_handler; Handler m_handler;
}; };
template <class Handler, typename P1>
struct CallType1 : Call
{
CallType1 (BOOST_ASIO_MOVE_ARG(Handler) handler, P1 p1)
: m_handler (handler)
, m_p1 (p1)
{
}
void operator() ()
{
m_handler (m_p1);
}
Handler m_handler;
P1 m_p1;
};
template <class Handler, typename P1, typename P2>
struct CallType2 : Call
{
CallType2 (BOOST_ASIO_MOVE_ARG(Handler) handler, P1 p1, P2 p2)
: m_handler (handler)
, m_p1 (p1)
, m_p2 (p2)
{
}
void operator() ()
{
m_handler (m_p1, m_p2);
}
Handler m_handler;
P1 m_p1;
P2 m_p2;
};
private: private:
SharedObjectPtr <Call> m_call; SharedObjectPtr <Call> m_call;
}; };