From 751a3539ae1d5e2d96d2189ac075b42420bc4b92 Mon Sep 17 00:00:00 2001 From: Chunting Gu Date: Tue, 15 Jun 2021 18:52:53 +0800 Subject: [PATCH] delete copy constructor and operator assign for most classes --- webcc/client_pool.h | 3 +++ webcc/client_session.h | 3 +++ webcc/globals.h | 4 ++-- webcc/message.h | 3 +++ webcc/parser.h | 3 +++ webcc/socket.h | 5 +++++ webcc/url.h | 5 +---- webcc/view.h | 5 +++++ 8 files changed, 25 insertions(+), 6 deletions(-) diff --git a/webcc/client_pool.h b/webcc/client_pool.h index 0ccd55a..59b648e 100644 --- a/webcc/client_pool.h +++ b/webcc/client_pool.h @@ -44,6 +44,9 @@ public: public: ClientPool() = default; + ClientPool(const ClientPool&) = delete; + ClientPool& operator=(const ClientPool&) = delete; + ~ClientPool(); ClientPtr Get(const Key& key) const; diff --git a/webcc/client_session.h b/webcc/client_session.h index cf6eac6..ce8e5f6 100644 --- a/webcc/client_session.h +++ b/webcc/client_session.h @@ -22,6 +22,9 @@ class ClientSession { public: explicit ClientSession(std::size_t buffer_size = 0); + ClientSession(const ClientSession&) = delete; + ClientSession& operator=(const ClientSession&) = delete; + ~ClientSession(); // Start Asio loop in a thread. diff --git a/webcc/globals.h b/webcc/globals.h index 7175898..7ef01aa 100644 --- a/webcc/globals.h +++ b/webcc/globals.h @@ -170,7 +170,7 @@ public: public: explicit Error(Code code = kOK, const std::string& message = "") - : code_(code), message_(message), timeout_(false) { + : code_(code), message_(message) { } // Note that `noexcept` is required by GCC. @@ -206,7 +206,7 @@ public: private: Code code_; std::string message_; - bool timeout_; + bool timeout_ = false; }; std::ostream& operator<<(std::ostream& os, const Error& error); diff --git a/webcc/message.h b/webcc/message.h index 73f5dbe..6728343 100644 --- a/webcc/message.h +++ b/webcc/message.h @@ -16,6 +16,9 @@ class Message { public: Message(); + Message(const Message&) = delete; + Message& operator=(const Message&) = delete; + virtual ~Message() = default; // --------------------------------------------------------------------------- diff --git a/webcc/parser.h b/webcc/parser.h index 498da0b..09c32c1 100644 --- a/webcc/parser.h +++ b/webcc/parser.h @@ -19,6 +19,9 @@ public: explicit BodyHandler(Message* message) : message_(message) { } + BodyHandler(const BodyHandler&) = delete; + BodyHandler& operator=(const BodyHandler&) = delete; + virtual ~BodyHandler() = default; virtual void AddContent(const char* data, std::size_t count) = 0; diff --git a/webcc/socket.h b/webcc/socket.h index 1a798a5..e6dad79 100644 --- a/webcc/socket.h +++ b/webcc/socket.h @@ -29,6 +29,11 @@ public: using ReadHandler = std::function; + SocketBase() = default; + + SocketBase(const SocketBase&) = delete; + SocketBase& operator=(const SocketBase&) = delete; + virtual ~SocketBase() = default; virtual void AsyncConnect(const std::string& host, const Endpoints& endpoints, diff --git a/webcc/url.h b/webcc/url.h index 4c907fe..bcd7efb 100644 --- a/webcc/url.h +++ b/webcc/url.h @@ -27,9 +27,6 @@ public: explicit Url(const std::string& str, bool encode = false); - Url(Url&&) = default; - Url& operator=(Url&&) = default; - const std::string& scheme() const { return scheme_; } @@ -134,7 +131,7 @@ public: std::regex operator()() const { std::regex::flag_type flags = std::regex::ECMAScript | std::regex::icase; - return std::regex(url_, flags); + return std::regex{ url_, flags }; } private: diff --git a/webcc/view.h b/webcc/view.h index 5ef254f..7964b3f 100644 --- a/webcc/view.h +++ b/webcc/view.h @@ -10,8 +10,13 @@ namespace webcc { class View { public: + View() = default; + virtual ~View() = default; + View(const View&) = delete; + View& operator=(const View&) = delete; + virtual ResponsePtr Handle(RequestPtr request) = 0; // Return true if you want the request data of the given method to be streamed