Home | History | Annotate | Download | only in asio
      1 //
      2 // async_result.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_ASYNC_RESULT_HPP
     12 #define ASIO_ASYNC_RESULT_HPP
     13 
     14 
     15 #include "asio/detail/config.hpp"
     16 #include "asio/handler_type.hpp"
     17 
     18 #include "asio/detail/push_options.hpp"
     19 
     20 namespace asio {
     21 
     22 /// An interface for customising the behaviour of an initiating function.
     23 /**
     24  * This template may be specialised for user-defined handler types.
     25  */
     26 template <typename Handler>
     27 class async_result
     28 {
     29 public:
     30   /// The return type of the initiating function.
     31   typedef void type;
     32 
     33   /// Construct an async result from a given handler.
     34   /**
     35    * When using a specalised async_result, the constructor has an opportunity
     36    * to initialise some state associated with the handler, which is then
     37    * returned from the initiating function.
     38    */
     39   explicit async_result(Handler&)
     40   {
     41   }
     42 
     43   /// Obtain the value to be returned from the initiating function.
     44   type get()
     45   {
     46   }
     47 };
     48 
     49 namespace detail {
     50 
     51 // Helper template to deduce the true type of a handler, capture a local copy
     52 // of the handler, and then create an async_result for the handler.
     53 template <typename Handler, typename Signature>
     54 struct async_result_init
     55 {
     56   explicit async_result_init(ASIO_MOVE_ARG(Handler) orig_handler)
     57     : handler(ASIO_MOVE_CAST(Handler)(orig_handler)),
     58       result(handler)
     59   {
     60   }
     61 
     62   typename handler_type<Handler, Signature>::type handler;
     63   async_result<typename handler_type<Handler, Signature>::type> result;
     64 };
     65 
     66 template <typename Handler, typename Signature>
     67 struct async_result_type_helper
     68 {
     69   typedef typename async_result<
     70       typename handler_type<Handler, Signature>::type
     71     >::type type;
     72 };
     73 
     74 } // namespace detail
     75 } // namespace asio
     76 
     77 #include "asio/detail/pop_options.hpp"
     78 
     79 # define ASIO_INITFN_RESULT_TYPE(h, sig)    typename ::asio::async_result<      typename ::asio::handler_type<h, sig>::type>::type
     80 
     81 #endif // ASIO_ASYNC_RESULT_HPP
     82