base_from_completion_cond.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // detail/base_from_completion_cond.hpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2019 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_BASE_FROM_COMPLETION_COND_HPP
  11. #define BOOST_ASIO_DETAIL_BASE_FROM_COMPLETION_COND_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/config.hpp>
  16. #include <boost/asio/completion_condition.hpp>
  17. #include <boost/asio/detail/push_options.hpp>
  18. namespace boost {
  19. namespace asio {
  20. namespace detail {
  21. template <typename CompletionCondition>
  22. class base_from_completion_cond
  23. {
  24. protected:
  25. explicit base_from_completion_cond(CompletionCondition& completion_condition)
  26. : completion_condition_(
  27. BOOST_ASIO_MOVE_CAST(CompletionCondition)(completion_condition))
  28. {
  29. }
  30. std::size_t check_for_completion(
  31. const boost::system::error_code& ec,
  32. std::size_t total_transferred)
  33. {
  34. return detail::adapt_completion_condition_result(
  35. completion_condition_(ec, total_transferred));
  36. }
  37. private:
  38. CompletionCondition completion_condition_;
  39. };
  40. template <>
  41. class base_from_completion_cond<transfer_all_t>
  42. {
  43. protected:
  44. explicit base_from_completion_cond(transfer_all_t)
  45. {
  46. }
  47. static std::size_t check_for_completion(
  48. const boost::system::error_code& ec,
  49. std::size_t total_transferred)
  50. {
  51. return transfer_all_t()(ec, total_transferred);
  52. }
  53. };
  54. } // namespace detail
  55. } // namespace asio
  56. } // namespace boost
  57. #include <boost/asio/detail/pop_options.hpp>
  58. #endif // BOOST_ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP