wrapped_handler.hpp
Go to the documentation of this file.
00001 //
00002 // wrapped_handler.hpp
00003 // ~~~~~~~~~~~~~~~~~~~
00004 //
00005 // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
00006 //
00007 // Distributed under the Boost Software License, Version 1.0. (See accompanying
00008 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00009 //
00010 
00011 #ifndef ASIO_DETAIL_WRAPPED_HANDLER_HPP
00012 #define ASIO_DETAIL_WRAPPED_HANDLER_HPP
00013 
00014 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
00015 # pragma once
00016 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
00017 
00018 #include "asio/detail/push_options.hpp"
00019 
00020 #include "asio/detail/push_options.hpp"
00021 #include <boost/type_traits.hpp>
00022 #include "asio/detail/pop_options.hpp"
00023 
00024 #include "asio/detail/bind_handler.hpp"
00025 #include "asio/detail/handler_alloc_helpers.hpp"
00026 #include "asio/detail/handler_invoke_helpers.hpp"
00027 
00028 namespace asio {
00029 namespace detail {
00030 
00031 template <typename Dispatcher, typename Handler>
00032 class wrapped_handler
00033 {
00034 public:
00035   typedef void result_type;
00036 
00037   wrapped_handler(
00038       typename boost::add_reference<Dispatcher>::type dispatcher,
00039       Handler handler)
00040     : dispatcher_(dispatcher),
00041       handler_(handler)
00042   {
00043   }
00044 
00045   void operator()()
00046   {
00047     dispatcher_.dispatch(handler_);
00048   }
00049 
00050   void operator()() const
00051   {
00052     dispatcher_.dispatch(handler_);
00053   }
00054 
00055   template <typename Arg1>
00056   void operator()(const Arg1& arg1)
00057   {
00058     dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
00059   }
00060 
00061   template <typename Arg1>
00062   void operator()(const Arg1& arg1) const
00063   {
00064     dispatcher_.dispatch(detail::bind_handler(handler_, arg1));
00065   }
00066 
00067   template <typename Arg1, typename Arg2>
00068   void operator()(const Arg1& arg1, const Arg2& arg2)
00069   {
00070     dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
00071   }
00072 
00073   template <typename Arg1, typename Arg2>
00074   void operator()(const Arg1& arg1, const Arg2& arg2) const
00075   {
00076     dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2));
00077   }
00078 
00079   template <typename Arg1, typename Arg2, typename Arg3>
00080   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
00081   {
00082     dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
00083   }
00084 
00085   template <typename Arg1, typename Arg2, typename Arg3>
00086   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) const
00087   {
00088     dispatcher_.dispatch(detail::bind_handler(handler_, arg1, arg2, arg3));
00089   }
00090 
00091   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
00092   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
00093       const Arg4& arg4)
00094   {
00095     dispatcher_.dispatch(
00096         detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
00097   }
00098 
00099   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4>
00100   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
00101       const Arg4& arg4) const
00102   {
00103     dispatcher_.dispatch(
00104         detail::bind_handler(handler_, arg1, arg2, arg3, arg4));
00105   }
00106 
00107   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
00108       typename Arg5>
00109   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
00110       const Arg4& arg4, const Arg5& arg5)
00111   {
00112     dispatcher_.dispatch(
00113         detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
00114   }
00115 
00116   template <typename Arg1, typename Arg2, typename Arg3, typename Arg4,
00117       typename Arg5>
00118   void operator()(const Arg1& arg1, const Arg2& arg2, const Arg3& arg3,
00119       const Arg4& arg4, const Arg5& arg5) const
00120   {
00121     dispatcher_.dispatch(
00122         detail::bind_handler(handler_, arg1, arg2, arg3, arg4, arg5));
00123   }
00124 
00125 //private:
00126   Dispatcher dispatcher_;
00127   Handler handler_;
00128 };
00129 
00130 template <typename Handler, typename Context>
00131 class rewrapped_handler
00132 {
00133 public:
00134   explicit rewrapped_handler(const Handler& handler, const Context& context)
00135     : handler_(handler),
00136       context_(context)
00137   {
00138   }
00139 
00140   void operator()()
00141   {
00142     handler_();
00143   }
00144 
00145   void operator()() const
00146   {
00147     handler_();
00148   }
00149 
00150 //private:
00151   Handler handler_;
00152   Context context_;
00153 };
00154 
00155 template <typename Dispatcher, typename Handler>
00156 inline void* asio_handler_allocate(std::size_t size,
00157     wrapped_handler<Dispatcher, Handler>* this_handler)
00158 {
00159   return asio_handler_alloc_helpers::allocate(
00160       size, &this_handler->handler_);
00161 }
00162 
00163 template <typename Dispatcher, typename Handler>
00164 inline void asio_handler_deallocate(void* pointer, std::size_t size,
00165     wrapped_handler<Dispatcher, Handler>* this_handler)
00166 {
00167   asio_handler_alloc_helpers::deallocate(
00168       pointer, size, &this_handler->handler_);
00169 }
00170 
00171 template <typename Function, typename Dispatcher, typename Handler>
00172 inline void asio_handler_invoke(const Function& function,
00173     wrapped_handler<Dispatcher, Handler>* this_handler)
00174 {
00175   this_handler->dispatcher_.dispatch(
00176       rewrapped_handler<Function, Handler>(
00177         function, this_handler->handler_));
00178 }
00179 
00180 template <typename Handler, typename Context>
00181 inline void* asio_handler_allocate(std::size_t size,
00182     rewrapped_handler<Handler, Context>* this_handler)
00183 {
00184   return asio_handler_alloc_helpers::allocate(
00185       size, &this_handler->context_);
00186 }
00187 
00188 template <typename Handler, typename Context>
00189 inline void asio_handler_deallocate(void* pointer, std::size_t size,
00190     rewrapped_handler<Handler, Context>* this_handler)
00191 {
00192   asio_handler_alloc_helpers::deallocate(
00193       pointer, size, &this_handler->context_);
00194 }
00195 
00196 template <typename Function, typename Handler, typename Context>
00197 inline void asio_handler_invoke(const Function& function,
00198     rewrapped_handler<Handler, Context>* this_handler)
00199 {
00200   asio_handler_invoke_helpers::invoke(
00201       function, &this_handler->context_);
00202 }
00203 
00204 } // namespace detail
00205 } // namespace asio
00206 
00207 #include "asio/detail/pop_options.hpp"
00208 
00209 #endif // ASIO_DETAIL_WRAPPED_HANDLER_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


Castor
Author(s): Carpe Noctem
autogenerated on Fri Nov 8 2013 11:05:40