ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

343 lines
8.8 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <artyomtnk@yahoo.com>
  4. //
  5. // See accompanying file COPYING.TXT file for licensing details.
  6. //
  7. ///////////////////////////////////////////////////////////////////////////////
  8. #ifndef CPPCMS_IMPL_BINDER
  9. #define CPPCMS_IMPL_BINDER
  10. #include <booster/aio/types.h>
  11. #include <booster/callback.h>
  12. namespace cppcms {
  13. namespace impl {
  14. // booster::aio::handler
  15. template<typename F,typename S>
  16. struct handler_binder_p0 : public booster::aio::handler::callable_type {
  17. F f_;
  18. S s_;
  19. handler_binder_p0(F const &f,S const &s) : f_(f), s_(s) {}
  20. void operator()()
  21. {
  22. ((*s_).*f_)();
  23. }
  24. };
  25. template<typename C,typename S>
  26. booster::aio::handler::pointer_type mfunc_to_handler(void (C::*f)(),S s)
  27. {
  28. return new handler_binder_p0<void (C::*)(),S>(f,s);
  29. }
  30. template<typename F,typename S,typename P1>
  31. struct handler_binder_p1 : public booster::aio::handler::callable_type {
  32. F f_;
  33. S s_;
  34. P1 p1_;
  35. handler_binder_p1(F const &f,S const &s, P1 const &p1) : f_(f), s_(s), p1_(p1) {}
  36. void operator()()
  37. {
  38. ((*s_).*f_)(p1_);
  39. }
  40. };
  41. template<typename C,typename S,typename P1,typename P1in>
  42. booster::aio::handler::pointer_type mfunc_to_handler(void (C::*f)(P1),S s,P1in const &p1)
  43. {
  44. return new handler_binder_p1<void (C::*)(P1),S,P1in>(f,s,p1);
  45. }
  46. template<typename F,typename S,typename P1,typename P2>
  47. struct handler_binder_p2 : public booster::aio::handler::callable_type {
  48. F f_;
  49. S s_;
  50. P1 p1_;
  51. P2 p2_;
  52. handler_binder_p2(F const &f,S const &s, P1 const &p1,P2 const &p2) : f_(f), s_(s), p1_(p1),p2_(p2) {}
  53. void operator()()
  54. {
  55. ((*s_).*f_)(p1_,p2_);
  56. }
  57. };
  58. template<typename C,typename S,typename P1,typename P2,typename P1in,typename P2in>
  59. booster::aio::handler::pointer_type mfunc_to_handler(void (C::*f)(P1,P2),S s,P1in const &p1,P2in const &p2)
  60. {
  61. return new handler_binder_p2<void (C::*)(P1,P2),S,P1in,P2in>(f,s,p1,p2);
  62. }
  63. // booster::aio::event_handler
  64. template<typename F,typename S>
  65. struct event_handler_binder_p0 : public booster::aio::event_handler::callable_type {
  66. F f_;
  67. S s_;
  68. event_handler_binder_p0(F const &f,S const &s) : f_(f), s_(s) {}
  69. void operator()(booster::system::error_code const &e)
  70. {
  71. ((*s_).*f_)(e);
  72. }
  73. };
  74. template<typename C,typename S>
  75. booster::aio::event_handler::pointer_type mfunc_to_event_handler(void (C::*f)(booster::system::error_code const &e),S s)
  76. {
  77. return new event_handler_binder_p0<void (C::*)(booster::system::error_code const &),S>(f,s);
  78. }
  79. template<typename F,typename S,typename P1>
  80. struct event_handler_binder_p1 : public booster::aio::event_handler::callable_type {
  81. F f_;
  82. S s_;
  83. P1 p1_;
  84. event_handler_binder_p1(F const &f,S const &s, P1 const &p1) : f_(f), s_(s), p1_(p1) {}
  85. void operator()(booster::system::error_code const &e)
  86. {
  87. ((*s_).*f_)(e,p1_);
  88. }
  89. };
  90. template<typename C,typename S,typename P1,typename P1in>
  91. booster::aio::event_handler::pointer_type mfunc_to_event_handler(void (C::*f)(booster::system::error_code const &,P1),S s,P1in const &p1)
  92. {
  93. return new event_handler_binder_p1<void (C::*)(booster::system::error_code const &,P1),S,P1in>(f,s,p1);
  94. }
  95. template<typename F,typename S,typename P1,typename P2>
  96. struct event_handler_binder_p2 : public booster::aio::event_handler::callable_type {
  97. F f_;
  98. S s_;
  99. P1 p1_;
  100. P2 p2_;
  101. event_handler_binder_p2(F const &f,S const &s, P1 const &p1,P2 const &p2) : f_(f), s_(s), p1_(p1),p2_(p2) {}
  102. void operator()(booster::system::error_code const &e)
  103. {
  104. ((*s_).*f_)(e,p1_,p2_);
  105. }
  106. };
  107. template<typename C,typename S,typename P1,typename P2,typename P1in,typename P2in>
  108. booster::aio::event_handler::pointer_type mfunc_to_event_handler(void (C::*f)(booster::system::error_code const &,P1,P2),S s,P1in const &p1,P2in const &p2)
  109. {
  110. return new event_handler_binder_p2<void (C::*)(booster::system::error_code const &,P1,P2),S,P1in,P2in>(f,s,p1,p2);
  111. }
  112. // booster::aio::io_handler
  113. template<typename F,typename S>
  114. struct io_handler_binder_p0 : public booster::aio::io_handler::callable_type {
  115. F f_;
  116. S s_;
  117. io_handler_binder_p0(F const &f,S const &s) : f_(f), s_(s) {}
  118. void operator()(booster::system::error_code const &e,size_t l)
  119. {
  120. ((*s_).*f_)(e,l);
  121. }
  122. };
  123. template<typename C,typename S>
  124. booster::aio::io_handler::pointer_type mfunc_to_io_handler(void (C::*f)(booster::system::error_code const &,size_t),S s)
  125. {
  126. return new io_handler_binder_p0<void (C::*)(booster::system::error_code const &,size_t),S>(f,s);
  127. }
  128. template<typename F,typename S,typename P1>
  129. struct io_handler_binder_p1 : public booster::aio::io_handler::callable_type {
  130. F f_;
  131. S s_;
  132. P1 p1_;
  133. io_handler_binder_p1(F const &f,S const &s, P1 const &p1) : f_(f), s_(s), p1_(p1) {}
  134. void operator()(booster::system::error_code const &e,size_t l)
  135. {
  136. ((*s_).*f_)(e,l,p1_);
  137. }
  138. };
  139. template<typename C,typename S,typename P1,typename P1in>
  140. booster::aio::io_handler::pointer_type mfunc_to_io_handler(void (C::*f)(booster::system::error_code const &,size_t,P1),S s,P1in const &p1)
  141. {
  142. return new io_handler_binder_p1<void (C::*)(booster::system::error_code const &,size_t,P1),S,P1in>(f,s,p1);
  143. }
  144. template<typename F,typename S,typename P1,typename P2>
  145. struct io_handler_binder_p2 : public booster::aio::io_handler::callable_type {
  146. F f_;
  147. S s_;
  148. P1 p1_;
  149. P2 p2_;
  150. io_handler_binder_p2(F const &f,S const &s, P1 const &p1,P2 const &p2) : f_(f), s_(s), p1_(p1),p2_(p2) {}
  151. void operator()(booster::system::error_code const &e,size_t l)
  152. {
  153. ((*s_).*f_)(e,l,p1_,p2_);
  154. }
  155. };
  156. template<typename C,typename S,typename P1,typename P2,typename P1in,typename P2in>
  157. booster::aio::io_handler::pointer_type mfunc_to_io_handler(void (C::*f)(booster::system::error_code const &,size_t,P1,P2),S s,P1in const &p1,P2in const &p2)
  158. {
  159. return new io_handler_binder_p2<void (C::*)(booster::system::error_code const &,size_t,P1,P2),S,P1in,P2in>(f,s,p1,p2);
  160. }
  161. //// NON Member Functions
  162. // booster::aio::handler
  163. template<typename F,typename P1>
  164. struct handler_fbinder_p1 : public booster::aio::handler::callable_type {
  165. F f_;
  166. P1 p1_;
  167. handler_fbinder_p1(F const &f, P1 const &p1) : f_(f), p1_(p1) {}
  168. void operator()()
  169. {
  170. f_(p1_);
  171. }
  172. };
  173. template<typename C,typename P1>
  174. booster::aio::handler::pointer_type func_to_handler(C const &f,P1 const &p1)
  175. {
  176. return new handler_fbinder_p1<C,P1>(f,p1);
  177. }
  178. template<typename F,typename P1,typename P2>
  179. struct handler_fbinder_p2 : public booster::aio::handler::callable_type {
  180. F f_;
  181. P1 p1_;
  182. P2 p2_;
  183. handler_fbinder_p2(F const &f, P1 const &p1,P2 const &p2) : f_(f), p1_(p1),p2_(p2) {}
  184. void operator()()
  185. {
  186. f_(p1_,p2_);
  187. }
  188. };
  189. template<typename C,typename P1,typename P2>
  190. booster::aio::handler::pointer_type func_to_handler(C const &f,P1 const &p1,P2 const &p2)
  191. {
  192. return new handler_fbinder_p2<C,P1,P2>(f,p1,p2);
  193. }
  194. // booster::aio::event_handler
  195. template<typename F,typename P1>
  196. struct event_handler_fbinder_p1 : public booster::aio::event_handler::callable_type {
  197. F f_;
  198. P1 p1_;
  199. event_handler_fbinder_p1(F const &f, P1 const &p1) : f_(f), p1_(p1) {}
  200. void operator()(booster::system::error_code const &e)
  201. {
  202. f_(e,p1_);
  203. }
  204. };
  205. template<typename C,typename P1>
  206. booster::aio::event_handler::pointer_type func_to_event_handler(C const &f,P1 const &p1)
  207. {
  208. return new event_handler_fbinder_p1<C,P1>(f,p1);
  209. }
  210. template<typename F,typename P1,typename P2>
  211. struct event_handler_fbinder_p2 : public booster::aio::event_handler::callable_type {
  212. F f_;
  213. P1 p1_;
  214. P2 p2_;
  215. event_handler_fbinder_p2(F const &f, P1 const &p1,P2 const &p2) : f_(f), p1_(p1),p2_(p2) {}
  216. void operator()(booster::system::error_code const &e)
  217. {
  218. f_(e,p1_,p2_);
  219. }
  220. };
  221. template<typename C,typename P1,typename P2>
  222. booster::aio::event_handler::pointer_type func_to_event_handler(C const &f,P1 const &p1,P2 const &p2)
  223. {
  224. return new event_handler_fbinder_p2<C,P1,P2>(f,p1,p2);
  225. }
  226. // booster::aio::io_handler
  227. template<typename F,typename P1>
  228. struct io_handler_fbinder_p1 : public booster::aio::io_handler::callable_type {
  229. F f_;
  230. P1 p1_;
  231. io_handler_fbinder_p1(F const &f, P1 const &p1) : f_(f), p1_(p1) {}
  232. void operator()(booster::system::error_code const &e,size_t l)
  233. {
  234. f_(e,l,p1_);
  235. }
  236. };
  237. template<typename C,typename P1>
  238. booster::aio::io_handler::pointer_type func_to_io_handler(C f,P1 const &p1)
  239. {
  240. return new io_handler_fbinder_p1<C,P1>(f,p1);
  241. }
  242. template<typename F,typename P1,typename P2>
  243. struct io_handler_fbinder_p2 : public booster::aio::io_handler::callable_type {
  244. F f_;
  245. P1 p1_;
  246. P2 p2_;
  247. io_handler_fbinder_p2(F const &f, P1 const &p1,P2 const &p2) : f_(f), p1_(p1),p2_(p2) {}
  248. void operator()(booster::system::error_code const &e,size_t l)
  249. {
  250. f_(e,l,p1_,p2_);
  251. }
  252. };
  253. template<typename C,typename P1,typename P2>
  254. booster::aio::io_handler::pointer_type func_to_io_handler(C f,P1 const &p1,P2 const &p2)
  255. {
  256. return new io_handler_fbinder_p2<C,P1,P2>(f,p1,p2);
  257. }
  258. } // impl
  259. } // cppcms
  260. #endif