Add moveability

This commit is contained in:
Bob Polis 2023-11-05 17:12:30 +00:00
parent b798539502
commit 5c53dc88e7
2 changed files with 21 additions and 3 deletions

View File

@ -3,6 +3,7 @@
#include <vector>
#include <cstring>
#include <stdexcept>
#include <utility>
using namespace sc;
@ -26,6 +27,21 @@ requester::~requester() {
curl_global_cleanup();
}
requester::requester(requester&& other) :
_h {std::move(other._h)}, _logger {other._logger}, _text {std::move(other._text)}
{
other._h = nullptr;
other._logger = nullptr;
other._text = "";
}
requester& requester::operator=(requester&& other) {
std::swap(_h, other._h);
std::swap(_logger, other._logger);
std::swap(_text, other._text);
return *this;
}
std::string requester::get(const std::string &url) {
_text = "";
curl_easy_setopt(_h.get(), CURLOPT_URL, url.c_str());

View File

@ -17,11 +17,13 @@ namespace sc {
requester();
~requester();
// forbid copying and moving
// forbid copying
requester(const requester&) = delete;
requester& operator=(const requester&) = delete;
requester(requester&&) = delete;
requester& operator=(requester&&) = delete;
// allow move
requester(requester&&);
requester& operator=(requester&&);
// optional logger
void logger(sc::logger* logger) { _logger = logger; }