From aee64d6e1708f3d688cb80b6ab0236fc04eee888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Fri, 10 Jan 2020 12:46:49 +0100 Subject: [PATCH] added move ctor and assignment --- JWT/include/Poco/JWT/Token.h | 6 ++++++ JWT/src/Token.cpp | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/JWT/include/Poco/JWT/Token.h b/JWT/include/Poco/JWT/Token.h index 86fb6531f..44c7fedfd 100644 --- a/JWT/include/Poco/JWT/Token.h +++ b/JWT/include/Poco/JWT/Token.h @@ -61,12 +61,18 @@ public: Token(const Token& token); /// Creates a JSON Web Token by copying another one. + Token(Token&& token) noexcept; + /// Creates a JSON Web Token by moving another one. + ~Token(); /// Destroys the Token. Token& operator = (const Token& token); /// Assignment operator. + Token& operator = (Token&& token) noexcept; + /// Move assignment operator. + Token& operator = (const std::string& token); /// Parses and assigns serialized JWT. diff --git a/JWT/src/Token.cpp b/JWT/src/Token.cpp index cba8c5cee..2e072d1cd 100644 --- a/JWT/src/Token.cpp +++ b/JWT/src/Token.cpp @@ -59,6 +59,14 @@ Token::Token(const Token& token): } +Token::Token(Token&& token) noexcept: + _pHeader(std::move(token._pHeader)), + _pPayload(std::move(token._pPayload)), + _signature(std::move(token._signature)) +{ +} + + Token::Token(const std::string& header, const std::string& payload, const std::string& signature) { assign(header, payload, signature); @@ -86,6 +94,16 @@ Token& Token::operator = (const Token& token) } +Token& Token::operator = (Token&& token) noexcept +{ + _pHeader = std::move(token._pHeader); + _pPayload = std::move(token._pPayload); + _signature = std::move(token._signature); + + return *this; +} + + Token& Token::operator = (const std::string& token) { std::vector parts = Serializer::split(token);