added move ctor and assignment

This commit is contained in:
Günter Obiltschnig 2020-01-10 12:46:49 +01:00
parent b55db12286
commit aee64d6e17
2 changed files with 24 additions and 0 deletions

View File

@ -61,12 +61,18 @@ public:
Token(const Token& token); Token(const Token& token);
/// Creates a JSON Web Token by copying another one. /// Creates a JSON Web Token by copying another one.
Token(Token&& token) noexcept;
/// Creates a JSON Web Token by moving another one.
~Token(); ~Token();
/// Destroys the Token. /// Destroys the Token.
Token& operator = (const Token& token); Token& operator = (const Token& token);
/// Assignment operator. /// Assignment operator.
Token& operator = (Token&& token) noexcept;
/// Move assignment operator.
Token& operator = (const std::string& token); Token& operator = (const std::string& token);
/// Parses and assigns serialized JWT. /// Parses and assigns serialized JWT.

View File

@ -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) Token::Token(const std::string& header, const std::string& payload, const std::string& signature)
{ {
assign(header, payload, 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) Token& Token::operator = (const std::string& token)
{ {
std::vector<std::string> parts = Serializer::split(token); std::vector<std::string> parts = Serializer::split(token);