handler_base_from_member.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // handler_base_from_member.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_DETAIL_HANDLER_BASE_FROM_MEMBER_HPP
  11. #define BOOST_ASIO_DETAIL_HANDLER_BASE_FROM_MEMBER_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/push_options.hpp>
  16. #include <boost/asio/detail/handler_alloc_helpers.hpp>
  17. #include <boost/asio/detail/handler_invoke_helpers.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace detail {
  21. // Base class for classes that need a handler data member. Forwards the custom
  22. // allocation and invocation hooks to the contained handler.
  23. template <typename Handler>
  24. class handler_base_from_member
  25. {
  26. public:
  27. handler_base_from_member(Handler handler)
  28. : handler_(handler)
  29. {
  30. }
  31. //protected:
  32. Handler handler_;
  33. protected:
  34. // Protected destructor to prevent deletion through this type.
  35. ~handler_base_from_member()
  36. {
  37. }
  38. };
  39. template <typename Handler>
  40. inline void* asio_handler_allocate(std::size_t size,
  41. handler_base_from_member<Handler>* this_handler)
  42. {
  43. return boost_asio_handler_alloc_helpers::allocate(
  44. size, &this_handler->handler_);
  45. }
  46. template <typename Handler>
  47. inline void asio_handler_deallocate(void* pointer, std::size_t size,
  48. handler_base_from_member<Handler>* this_handler)
  49. {
  50. boost_asio_handler_alloc_helpers::deallocate(
  51. pointer, size, &this_handler->handler_);
  52. }
  53. template <typename Function, typename Handler>
  54. inline void asio_handler_invoke(const Function& function,
  55. handler_base_from_member<Handler>* this_handler)
  56. {
  57. boost_asio_handler_invoke_helpers::invoke(
  58. function, &this_handler->handler_);
  59. }
  60. } // namespace detail
  61. } // namespace asio
  62. } // namespace boost
  63. #include <boost/asio/detail/pop_options.hpp>
  64. #endif // BOOST_ASIO_DETAIL_HANDLER_BASE_FROM_MEMBER_HPP