From ba705e930e31a84c2870b7c6000df2b4172cb57d Mon Sep 17 00:00:00 2001 From: Chunting Gu Date: Tue, 9 Apr 2019 15:39:58 +0800 Subject: [PATCH] Add VS2013 support back. --- webcc/base64.cc | 4 ++-- webcc/base64.h | 2 +- webcc/globals.cc | 2 +- webcc/globals.h | 33 ++++++++++++++++++++++++++++++++- webcc/soap_parameter.h | 21 +++++++++++++++++++++ webcc/url.h | 25 +++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 5 deletions(-) diff --git a/webcc/base64.cc b/webcc/base64.cc index 16b9103..f5db115 100644 --- a/webcc/base64.cc +++ b/webcc/base64.cc @@ -72,12 +72,12 @@ static const char kInverse[] = { }; // Return max chars needed to encode a base64 string. -inline std::size_t constexpr EncodedSize(std::size_t n) { +inline std::size_t EncodedSize(std::size_t n) { return 4 * ((n + 2) / 3); } // Return max bytes needed to decode a base64 string. -inline std::size_t constexpr DecodedSize(std::size_t n) { +inline std::size_t DecodedSize(std::size_t n) { // return 3 * n / 4; return n / 4 * 3; // requires n&3==0, smaller } diff --git a/webcc/base64.h b/webcc/base64.h index 2145adb..1733a85 100644 --- a/webcc/base64.h +++ b/webcc/base64.h @@ -1,7 +1,7 @@ #ifndef WEBCC_BASE64_H_ #define WEBCC_BASE64_H_ -#include +#include #include namespace webcc { diff --git a/webcc/globals.cc b/webcc/globals.cc index f0ed99f..13bc9a6 100644 --- a/webcc/globals.cc +++ b/webcc/globals.cc @@ -19,7 +19,7 @@ static bool ReadFile(const std::string& path, std::string* output) { } auto size = ifs.tellg(); - output->resize(size, '\0'); + output->resize((std::size_t)size, '\0'); ifs.seekg(0); ifs.read(&(*output)[0], size); // TODO: Error handling diff --git a/webcc/globals.h b/webcc/globals.h index e5c7c41..d190fb4 100644 --- a/webcc/globals.h +++ b/webcc/globals.h @@ -5,6 +5,37 @@ #include #include +// ----------------------------------------------------------------------------- +// Macros + +#ifdef _MSC_VER + +#if _MSC_VER <= 1800 // VS 2013 + +// Does the compiler support "= default" for move copy constructor and +// move assignment operator? +#define WEBCC_DEFAULT_MOVE_COPY_ASSIGN 0 + +#define WEBCC_NOEXCEPT + +#else + +#define WEBCC_DEFAULT_MOVE_COPY_ASSIGN 1 + +#define WEBCC_NOEXCEPT noexcept + +#endif // _MSC_VER <= 1800 + +#else + +// GCC, Clang, etc. + +#define WEBCC_DEFAULT_MOVE_COPY_ASSIGN 1 + +#define WEBCC_NOEXCEPT noexcept + +#endif // _MSC_VER + namespace webcc { // ----------------------------------------------------------------------------- @@ -183,7 +214,7 @@ public: Error error() const { return error_; } // Note that `noexcept` is required by GCC. - const char* what() const noexcept override { + const char* what() const WEBCC_NOEXCEPT override{ return msg_.c_str(); } diff --git a/webcc/soap_parameter.h b/webcc/soap_parameter.h index 4975661..3671f3a 100644 --- a/webcc/soap_parameter.h +++ b/webcc/soap_parameter.h @@ -46,9 +46,30 @@ public: as_cdata_(false) { } +#if WEBCC_DEFAULT_MOVE_COPY_ASSIGN + SoapParameter(SoapParameter&&) = default; SoapParameter& operator=(SoapParameter&&) = default; +#else + + SoapParameter(SoapParameter&& rhs) + : key_(std::move(rhs.key_)), + value_(std::move(rhs.value_)), + as_cdata_(rhs.as_cdata_) { + } + + SoapParameter& operator=(SoapParameter&& rhs) { + if (&rhs != this) { + key_ = std::move(rhs.key_); + value_ = std::move(rhs.value_); + as_cdata_ = rhs.as_cdata_; + } + return *this; + } + +#endif // WEBCC_DEFAULT_MOVE_COPY_ASSIGN + const std::string& key() const { return key_; } const std::string& value() const { return value_; } diff --git a/webcc/url.h b/webcc/url.h index 22d8f38..ed4fa06 100644 --- a/webcc/url.h +++ b/webcc/url.h @@ -61,9 +61,34 @@ public: explicit Url(const std::string& str, bool decode = true); +#if WEBCC_DEFAULT_MOVE_COPY_ASSIGN + Url(Url&&) = default; Url& operator=(Url&&) = default; +#else + + Url(Url&& rhs) + : scheme_(std::move(rhs.scheme_)), + host_(std::move(rhs.host_)), + port_(std::move(rhs.port_)), + path_(std::move(rhs.path_)), + query_(std::move(rhs.query_)) { + } + + Url& operator=(Url&& rhs) { + if (&rhs != this) { + scheme_ = std::move(rhs.scheme_); + host_ = std::move(rhs.host_); + port_ = std::move(rhs.port_); + path_ = std::move(rhs.path_); + query_ = std::move(rhs.query_); + } + return *this; + } + +#endif // WEBCC_DEFAULT_MOVE_COPY_ASSIGN + void Init(const std::string& str, bool decode = true, bool clear = true); const std::string& scheme() const {