From 5c53dc88e70f90281ae136a2ea62f12a7ef0df49 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Sun, 5 Nov 2023 17:12:30 +0000 Subject: [PATCH] Add moveability --- src/requester.cpp | 16 ++++++++++++++++ src/requester.hpp | 8 +++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/requester.cpp b/src/requester.cpp index 304af8d..01424f6 100644 --- a/src/requester.cpp +++ b/src/requester.cpp @@ -3,6 +3,7 @@ #include #include #include +#include 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()); diff --git a/src/requester.hpp b/src/requester.hpp index c64e6b8..166480e 100644 --- a/src/requester.hpp +++ b/src/requester.hpp @@ -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; }