/** This file is a part of the rcw project Copyright (C) 2021 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ #ifndef RCW_READ_WRITE_CBACK_HPP #define RCW_READ_WRITE_CBACK_HPP #include //size_t #include #include //forward #include //sequence_tuple #include "string.hpp" namespace rcw{ namespace detail{ template struct curl_cback_invoker_helper{ Func&& func; std::tuple args; template size_t operator()(rexy::sequence_tuple, Ts&&... ts){ return std::forward(func)(std::forward(ts)..., std::get(args)...); } }; struct curl_cback_invoker{ virtual ~curl_cback_invoker(void) = default; virtual size_t operator()(char* data, size_t size, size_t nmemb) = 0; }; template struct curl_cback_invoker_impl : public curl_cback_invoker{ curl_cback_invoker_helper helper; curl_cback_invoker_impl(const curl_cback_invoker_impl&) = default; template curl_cback_invoker_impl(Fn&& f, Ts&&... ts): helper{std::forward(f), {std::forward(ts)...}}{} size_t operator()(char* data, size_t size, size_t nmemb)override{ return helper(rexy::sequence_gen_t{}, data, size, nmemb); } }; template curl_cback_invoker_impl(Func&&, Args&&...) -> curl_cback_invoker_impl; } size_t curl_write_callback(char* data, size_t size, size_t nmemb, void* userdata); size_t curl_read_callback(char* data, size_t size, size_t nmemb, void* userdata); struct default_curl_write_callback{ string data; size_t operator()(char* d, size_t size, size_t nmemb); }; struct default_curl_read_callback{ const char* data; size_t length; size_t offset = 0; size_t operator()(char* d, size_t size, size_t nmemb); }; } #endif