Home | History | Annotate | Download | only in detail
      1 //
      2 // detail/base_from_completion_cond.hpp
      3 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      4 //
      5 // Copyright (c) 2003-2015 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 
     11 #ifndef ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
     12 #define ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
     13 
     14 
     15 #include "asio/detail/config.hpp"
     16 #include "asio/completion_condition.hpp"
     17 
     18 #include "asio/detail/push_options.hpp"
     19 
     20 namespace asio {
     21 namespace detail {
     22 
     23 template <typename CompletionCondition>
     24 class base_from_completion_cond
     25 {
     26 protected:
     27   explicit base_from_completion_cond(CompletionCondition completion_condition)
     28     : completion_condition_(completion_condition)
     29   {
     30   }
     31 
     32   std::size_t check_for_completion(
     33       const asio::error_code& ec,
     34       std::size_t total_transferred)
     35   {
     36     return detail::adapt_completion_condition_result(
     37         completion_condition_(ec, total_transferred));
     38   }
     39 
     40 private:
     41   CompletionCondition completion_condition_;
     42 };
     43 
     44 template <>
     45 class base_from_completion_cond<transfer_all_t>
     46 {
     47 protected:
     48   explicit base_from_completion_cond(transfer_all_t)
     49   {
     50   }
     51 
     52   static std::size_t check_for_completion(
     53       const asio::error_code& ec,
     54       std::size_t total_transferred)
     55   {
     56     return transfer_all_t()(ec, total_transferred);
     57   }
     58 };
     59 
     60 } // namespace detail
     61 } // namespace asio
     62 
     63 #include "asio/detail/pop_options.hpp"
     64 
     65 #endif // ASIO_DETAIL_BASE_FROM_COMPLETION_COND_HPP
     66