bind_handler.hpp
Go to the documentation of this file.
00001 //
00002 // bind_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_BIND_HANDLER_HPP
00012 #define ASIO_DETAIL_BIND_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/handler_alloc_helpers.hpp"
00021 #include "asio/detail/handler_invoke_helpers.hpp"
00022 
00023 namespace asio {
00024 namespace detail {
00025 
00026 template <typename Handler, typename Arg1>
00027 class binder1
00028 {
00029 public:
00030   binder1(const Handler& handler, const Arg1& arg1)
00031     : handler_(handler),
00032       arg1_(arg1)
00033   {
00034   }
00035 
00036   void operator()()
00037   {
00038     handler_(arg1_);
00039   }
00040 
00041   void operator()() const
00042   {
00043     handler_(arg1_);
00044   }
00045 
00046 //private:
00047   Handler handler_;
00048   Arg1 arg1_;
00049 };
00050 
00051 template <typename Handler, typename Arg1>
00052 inline void* asio_handler_allocate(std::size_t size,
00053     binder1<Handler, Arg1>* this_handler)
00054 {
00055   return asio_handler_alloc_helpers::allocate(
00056       size, &this_handler->handler_);
00057 }
00058 
00059 template <typename Handler, typename Arg1>
00060 inline void asio_handler_deallocate(void* pointer, std::size_t size,
00061     binder1<Handler, Arg1>* this_handler)
00062 {
00063   asio_handler_alloc_helpers::deallocate(
00064       pointer, size, &this_handler->handler_);
00065 }
00066 
00067 template <typename Function, typename Handler, typename Arg1>
00068 inline void asio_handler_invoke(const Function& function,
00069     binder1<Handler, Arg1>* this_handler)
00070 {
00071   asio_handler_invoke_helpers::invoke(
00072       function, &this_handler->handler_);
00073 }
00074 
00075 template <typename Handler, typename Arg1>
00076 inline binder1<Handler, Arg1> bind_handler(const Handler& handler,
00077     const Arg1& arg1)
00078 {
00079   return binder1<Handler, Arg1>(handler, arg1);
00080 }
00081 
00082 template <typename Handler, typename Arg1, typename Arg2>
00083 class binder2
00084 {
00085 public:
00086   binder2(const Handler& handler, const Arg1& arg1, const Arg2& arg2)
00087     : handler_(handler),
00088       arg1_(arg1),
00089       arg2_(arg2)
00090   {
00091   }
00092 
00093   void operator()()
00094   {
00095     handler_(arg1_, arg2_);
00096   }
00097 
00098   void operator()() const
00099   {
00100     handler_(arg1_, arg2_);
00101   }
00102 
00103 //private:
00104   Handler handler_;
00105   Arg1 arg1_;
00106   Arg2 arg2_;
00107 };
00108 
00109 template <typename Handler, typename Arg1, typename Arg2>
00110 inline void* asio_handler_allocate(std::size_t size,
00111     binder2<Handler, Arg1, Arg2>* this_handler)
00112 {
00113   return asio_handler_alloc_helpers::allocate(
00114       size, &this_handler->handler_);
00115 }
00116 
00117 template <typename Handler, typename Arg1, typename Arg2>
00118 inline void asio_handler_deallocate(void* pointer, std::size_t size,
00119     binder2<Handler, Arg1, Arg2>* this_handler)
00120 {
00121   asio_handler_alloc_helpers::deallocate(
00122       pointer, size, &this_handler->handler_);
00123 }
00124 
00125 template <typename Function, typename Handler, typename Arg1, typename Arg2>
00126 inline void asio_handler_invoke(const Function& function,
00127     binder2<Handler, Arg1, Arg2>* this_handler)
00128 {
00129   asio_handler_invoke_helpers::invoke(
00130       function, &this_handler->handler_);
00131 }
00132 
00133 template <typename Handler, typename Arg1, typename Arg2>
00134 inline binder2<Handler, Arg1, Arg2> bind_handler(const Handler& handler,
00135     const Arg1& arg1, const Arg2& arg2)
00136 {
00137   return binder2<Handler, Arg1, Arg2>(handler, arg1, arg2);
00138 }
00139 
00140 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
00141 class binder3
00142 {
00143 public:
00144   binder3(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
00145       const Arg3& arg3)
00146     : handler_(handler),
00147       arg1_(arg1),
00148       arg2_(arg2),
00149       arg3_(arg3)
00150   {
00151   }
00152 
00153   void operator()()
00154   {
00155     handler_(arg1_, arg2_, arg3_);
00156   }
00157 
00158   void operator()() const
00159   {
00160     handler_(arg1_, arg2_, arg3_);
00161   }
00162 
00163 //private:
00164   Handler handler_;
00165   Arg1 arg1_;
00166   Arg2 arg2_;
00167   Arg3 arg3_;
00168 };
00169 
00170 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
00171 inline void* asio_handler_allocate(std::size_t size,
00172     binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
00173 {
00174   return asio_handler_alloc_helpers::allocate(
00175       size, &this_handler->handler_);
00176 }
00177 
00178 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
00179 inline void asio_handler_deallocate(void* pointer, std::size_t size,
00180     binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
00181 {
00182   asio_handler_alloc_helpers::deallocate(
00183       pointer, size, &this_handler->handler_);
00184 }
00185 
00186 template <typename Function, typename Handler, typename Arg1, typename Arg2,
00187     typename Arg3>
00188 inline void asio_handler_invoke(const Function& function,
00189     binder3<Handler, Arg1, Arg2, Arg3>* this_handler)
00190 {
00191   asio_handler_invoke_helpers::invoke(
00192       function, &this_handler->handler_);
00193 }
00194 
00195 template <typename Handler, typename Arg1, typename Arg2, typename Arg3>
00196 inline binder3<Handler, Arg1, Arg2, Arg3> bind_handler(const Handler& handler,
00197     const Arg1& arg1, const Arg2& arg2, const Arg3& arg3)
00198 {
00199   return binder3<Handler, Arg1, Arg2, Arg3>(handler, arg1, arg2, arg3);
00200 }
00201 
00202 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
00203     typename Arg4>
00204 class binder4
00205 {
00206 public:
00207   binder4(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
00208       const Arg3& arg3, const Arg4& arg4)
00209     : handler_(handler),
00210       arg1_(arg1),
00211       arg2_(arg2),
00212       arg3_(arg3),
00213       arg4_(arg4)
00214   {
00215   }
00216 
00217   void operator()()
00218   {
00219     handler_(arg1_, arg2_, arg3_, arg4_);
00220   }
00221 
00222   void operator()() const
00223   {
00224     handler_(arg1_, arg2_, arg3_, arg4_);
00225   }
00226 
00227 //private:
00228   Handler handler_;
00229   Arg1 arg1_;
00230   Arg2 arg2_;
00231   Arg3 arg3_;
00232   Arg4 arg4_;
00233 };
00234 
00235 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
00236     typename Arg4>
00237 inline void* asio_handler_allocate(std::size_t size,
00238     binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
00239 {
00240   return asio_handler_alloc_helpers::allocate(
00241       size, &this_handler->handler_);
00242 }
00243 
00244 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
00245     typename Arg4>
00246 inline void asio_handler_deallocate(void* pointer, std::size_t size,
00247     binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
00248 {
00249   asio_handler_alloc_helpers::deallocate(
00250       pointer, size, &this_handler->handler_);
00251 }
00252 
00253 template <typename Function, typename Handler, typename Arg1, typename Arg2,
00254     typename Arg3, typename Arg4>
00255 inline void asio_handler_invoke(const Function& function,
00256     binder4<Handler, Arg1, Arg2, Arg3, Arg4>* this_handler)
00257 {
00258   asio_handler_invoke_helpers::invoke(
00259       function, &this_handler->handler_);
00260 }
00261 
00262 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
00263     typename Arg4>
00264 inline binder4<Handler, Arg1, Arg2, Arg3, Arg4> bind_handler(
00265     const Handler& handler, const Arg1& arg1, const Arg2& arg2,
00266     const Arg3& arg3, const Arg4& arg4)
00267 {
00268   return binder4<Handler, Arg1, Arg2, Arg3, Arg4>(handler, arg1, arg2, arg3,
00269       arg4);
00270 }
00271 
00272 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
00273     typename Arg4, typename Arg5>
00274 class binder5
00275 {
00276 public:
00277   binder5(const Handler& handler, const Arg1& arg1, const Arg2& arg2,
00278       const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
00279     : handler_(handler),
00280       arg1_(arg1),
00281       arg2_(arg2),
00282       arg3_(arg3),
00283       arg4_(arg4),
00284       arg5_(arg5)
00285   {
00286   }
00287 
00288   void operator()()
00289   {
00290     handler_(arg1_, arg2_, arg3_, arg4_, arg5_);
00291   }
00292 
00293   void operator()() const
00294   {
00295     handler_(arg1_, arg2_, arg3_, arg4_, arg5_);
00296   }
00297 
00298 //private:
00299   Handler handler_;
00300   Arg1 arg1_;
00301   Arg2 arg2_;
00302   Arg3 arg3_;
00303   Arg4 arg4_;
00304   Arg5 arg5_;
00305 };
00306 
00307 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
00308     typename Arg4, typename Arg5>
00309 inline void* asio_handler_allocate(std::size_t size,
00310     binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
00311 {
00312   return asio_handler_alloc_helpers::allocate(
00313       size, &this_handler->handler_);
00314 }
00315 
00316 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
00317     typename Arg4, typename Arg5>
00318 inline void asio_handler_deallocate(void* pointer, std::size_t size,
00319     binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
00320 {
00321   asio_handler_alloc_helpers::deallocate(
00322       pointer, size, &this_handler->handler_);
00323 }
00324 
00325 template <typename Function, typename Handler, typename Arg1, typename Arg2,
00326     typename Arg3, typename Arg4, typename Arg5>
00327 inline void asio_handler_invoke(const Function& function,
00328     binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>* this_handler)
00329 {
00330   asio_handler_invoke_helpers::invoke(
00331       function, &this_handler->handler_);
00332 }
00333 
00334 template <typename Handler, typename Arg1, typename Arg2, typename Arg3,
00335     typename Arg4, typename Arg5>
00336 inline binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5> bind_handler(
00337     const Handler& handler, const Arg1& arg1, const Arg2& arg2,
00338     const Arg3& arg3, const Arg4& arg4, const Arg5& arg5)
00339 {
00340   return binder5<Handler, Arg1, Arg2, Arg3, Arg4, Arg5>(handler, arg1, arg2,
00341       arg3, arg4, arg5);
00342 }
00343 
00344 } // namespace detail
00345 } // namespace asio
00346 
00347 #include "asio/detail/pop_options.hpp"
00348 
00349 #endif // ASIO_DETAIL_BIND_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:39