Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-03 09:31:03

0001 //
0002 // Copyright (c) 2019-2025 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_DETAIL_ANY_RESUMABLE_REF_HPP
0009 #define BOOST_MYSQL_DETAIL_ANY_RESUMABLE_REF_HPP
0010 
0011 #include <boost/mysql/detail/next_action.hpp>
0012 
0013 #include <cstddef>
0014 #include <type_traits>
0015 
0016 namespace boost {
0017 namespace mysql {
0018 namespace detail {
0019 
0020 class any_resumable_ref
0021 {
0022 public:
0023     using fn_t = next_action (*)(void*, error_code, std::size_t);
0024 
0025     template <class T, class = typename std::enable_if<!std::is_same<T, any_resumable_ref>::value>::type>
0026     explicit any_resumable_ref(T& op) noexcept : algo_(&op), fn_(&do_resume<T>)
0027     {
0028     }
0029 
0030     // Allow using standalone functions
0031     any_resumable_ref(void* algo, fn_t fn) noexcept : algo_(algo), fn_(fn) {}
0032 
0033     next_action resume(error_code ec, std::size_t bytes_transferred)
0034     {
0035         return fn_(algo_, ec, bytes_transferred);
0036     }
0037 
0038 private:
0039     template <class T>
0040     static next_action do_resume(void* self, error_code ec, std::size_t bytes_transferred)
0041     {
0042         return static_cast<T*>(self)->resume(ec, bytes_transferred);
0043     }
0044 
0045     void* algo_{};
0046     fn_t fn_{};
0047 };
0048 
0049 }  // namespace detail
0050 }  // namespace mysql
0051 }  // namespace boost
0052 
0053 #endif