From 251d8a975ccf8ee4a635f1b4bd510c13de4eff5a Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 21 Mar 2020 11:18:22 +0100 Subject: [PATCH 1/2] Set access token in CURLWrapper too if it is set in Instance. --- include/instance.hpp | 13 ++++--------- src/instance.cpp | 8 ++++++++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/instance.hpp b/include/instance.hpp index fb85a03..de21c19 100644 --- a/include/instance.hpp +++ b/include/instance.hpp @@ -57,13 +57,7 @@ public: * * @since 0.1.0 */ - explicit Instance(const string_view hostname, - const string_view access_token) - : _hostname{hostname} - , _baseuri{"https://" + _hostname} - , _access_token{access_token} - , _max_chars{0} - {} + explicit Instance(string_view hostname, string_view access_token); /*! * @brief Copy constructor. A new CURLWrapper is constructed. @@ -143,9 +137,10 @@ public: * * @since 0.1.0 */ - inline void set_access_token(string access_token) + inline void set_access_token(const string_view access_token) { - _access_token = move(access_token); + _access_token = access_token; + CURLWrapper::set_access_token(access_token); } /*! diff --git a/src/instance.cpp b/src/instance.cpp index fb8db81..f410b27 100644 --- a/src/instance.cpp +++ b/src/instance.cpp @@ -31,6 +31,14 @@ using std::regex; using std::regex_search; using std::smatch; +Instance::Instance(const string_view hostname, const string_view access_token) + : _hostname{hostname} + , _baseuri{"https://" + _hostname} + , _max_chars{0} +{ + set_access_token(access_token); +} + uint64_t Instance::get_max_chars() noexcept { constexpr uint64_t default_max_chars{500}; From 5bf1e9bf252233e5bda05b98041e1386537e8ae5 Mon Sep 17 00:00:00 2001 From: tastytea Date: Sat, 21 Mar 2020 11:27:02 +0100 Subject: [PATCH 2/2] Define copy constructor for instance. Needed because the underlying CURLWrapper is not copied but freshly created, so access_token, proxy, cainfo and useragent have to be set. --- include/instance.hpp | 2 +- src/instance.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/instance.hpp b/include/instance.hpp index de21c19..214be77 100644 --- a/include/instance.hpp +++ b/include/instance.hpp @@ -64,7 +64,7 @@ public: * * @since 0.5.2 */ - Instance(const Instance &other) = default; + Instance(const Instance &other); //! Move constructor Instance(Instance &&other) noexcept = delete; diff --git a/src/instance.cpp b/src/instance.cpp index f410b27..5056242 100644 --- a/src/instance.cpp +++ b/src/instance.cpp @@ -39,6 +39,21 @@ Instance::Instance(const string_view hostname, const string_view access_token) set_access_token(access_token); } +Instance::Instance(const Instance &other) + : CURLWrapper{other} + , _hostname{other._hostname} + , _baseuri{other._baseuri} + , _access_token{other._access_token} + , _max_chars{other._max_chars} + , _proxy{other._proxy} + , _post_formats{other._post_formats} + , _cainfo{other._cainfo} + , _useragent{other._useragent} +{ + CURLWrapper::setup_connection_properties(_proxy, _access_token, + _cainfo, _useragent); +} + uint64_t Instance::get_max_chars() noexcept { constexpr uint64_t default_max_chars{500};