1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 08:47:17 +01:00
SqMod/vendor/CPR/include/cpr/callback.h

90 lines
3.4 KiB
C
Raw Normal View History

2021-03-26 23:18:51 +01:00
#ifndef CPR_CALLBACK_H
#define CPR_CALLBACK_H
#include "cprtypes.h"
#include <functional>
#include <utility>
namespace cpr {
class ReadCallback {
public:
ReadCallback() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
2021-08-22 19:28:37 +02:00
ReadCallback(std::function<bool(char* buffer, size_t& size, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), size{-1}, callback{std::move(p_callback)} {}
ReadCallback(cpr_off_t p_size, std::function<bool(char* buffer, size_t& size, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), size{p_size}, callback{std::move(p_callback)} {}
bool operator()(char* buffer, size_t& size) const {
return callback(buffer, size, userdata);
}
2021-03-26 23:18:51 +01:00
2021-08-22 19:28:37 +02:00
intptr_t userdata;
2021-03-26 23:18:51 +01:00
cpr_off_t size{};
2021-08-22 19:28:37 +02:00
std::function<bool(char* buffer, size_t& size, intptr_t userdata)> callback;
2021-03-26 23:18:51 +01:00
};
class HeaderCallback {
public:
HeaderCallback() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
2021-08-22 19:28:37 +02:00
HeaderCallback(std::function<bool(std::string header, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {}
bool operator()(std::string header) const {
return callback(std::move(header), userdata);
}
2021-03-26 23:18:51 +01:00
2021-08-22 19:28:37 +02:00
intptr_t userdata;
std::function<bool(std::string header, intptr_t userdata)> callback;
2021-03-26 23:18:51 +01:00
};
class WriteCallback {
public:
WriteCallback() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
2021-08-22 19:28:37 +02:00
WriteCallback(std::function<bool(std::string data, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {}
bool operator()(std::string data) const {
return callback(std::move(data), userdata);
}
2021-03-26 23:18:51 +01:00
2021-08-22 19:28:37 +02:00
intptr_t userdata;
std::function<bool(std::string data, intptr_t userdata)> callback;
2021-03-26 23:18:51 +01:00
};
class ProgressCallback {
public:
ProgressCallback() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
2021-08-22 19:28:37 +02:00
ProgressCallback(std::function<bool(cpr_off_t downloadTotal, cpr_off_t downloadNow, cpr_off_t uploadTotal, cpr_off_t uploadNow, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {}
bool operator()(cpr_off_t downloadTotal, cpr_off_t downloadNow, cpr_off_t uploadTotal, cpr_off_t uploadNow) const {
return callback(downloadTotal, downloadNow, uploadTotal, uploadNow, userdata);
}
2021-03-26 23:18:51 +01:00
2021-08-22 19:28:37 +02:00
intptr_t userdata;
std::function<bool(size_t downloadTotal, size_t downloadNow, size_t uploadTotal, size_t uploadNow, intptr_t userdata)> callback;
2021-03-26 23:18:51 +01:00
};
class DebugCallback {
public:
enum class InfoType {
TEXT = 0,
HEADER_IN = 1,
HEADER_OUT = 2,
DATA_IN = 3,
DATA_OUT = 4,
SSL_DATA_IN = 5,
SSL_DATA_OUT = 6,
};
DebugCallback() = default;
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
2021-08-22 19:28:37 +02:00
DebugCallback(std::function<void(InfoType type, std::string data, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {}
void operator()(InfoType type, std::string data) const {
callback(type, std::move(data), userdata);
}
2021-03-26 23:18:51 +01:00
2021-08-22 19:28:37 +02:00
intptr_t userdata;
std::function<void(InfoType type, std::string data, intptr_t userdata)> callback;
2021-03-26 23:18:51 +01:00
};
} // namespace cpr
#endif