diff --git a/Crypto/include/Poco/Crypto/CipherKey.h b/Crypto/include/Poco/Crypto/CipherKey.h index 02042ec88..358556468 100644 --- a/Crypto/include/Poco/Crypto/CipherKey.h +++ b/Crypto/include/Poco/Crypto/CipherKey.h @@ -38,7 +38,7 @@ class Crypto_API CipherKey /// file. /// /// To create a key using a human-readable password - /// string, use the following code. We create a AES Cipher and + /// string, use the following code. We create a AES Cipher and /// use a salt value to make the key more robust: /// /// std::string password = "secret"; @@ -68,16 +68,16 @@ public: /// an iteration count of at least 1000. }; - CipherKey(const std::string& name, - const std::string& passphrase, + CipherKey(const std::string& name, + const std::string& passphrase, const std::string& salt = "", int iterationCount = DEFAULT_ITERATION_COUNT, const std::string& digest = "md5"); /// Creates a new CipherKeyImpl object using the given /// cipher name, passphrase, salt value, iteration count and digest. - CipherKey(const std::string& name, - const ByteVec& key, + CipherKey(const std::string& name, + const ByteVec& key, const ByteVec& iv); /// Creates a new CipherKeyImpl object using the given cipher /// name, key and initialization vector (IV). @@ -87,12 +87,24 @@ public: /// a custom IV size. CipherKey(const std::string& name); - /// Creates a new CipherKeyImpl object. Autoinitializes key and + /// Creates a new CipherKeyImpl object. Autoinitializes key and /// initialization vector. + CipherKey(const CipherKey& other); + /// Copy constructor. + + CipherKey(CipherKey&& other) noexcept; + /// Copy constructor. + ~CipherKey(); /// Destroys the CipherKeyImpl. + CipherKey& operator = (const CipherKey& other); + /// Assignment. + + CipherKey& operator = (CipherKey&& other) noexcept; + /// Move assignment. + const std::string& name() const; /// Returns the name of the Cipher. @@ -107,7 +119,7 @@ public: Mode mode() const; /// Returns the Cipher's mode of operation. - + const ByteVec& getKey() const; /// Returns the key for the Cipher. diff --git a/Crypto/include/Poco/Crypto/ECKey.h b/Crypto/include/Poco/Crypto/ECKey.h index 14f2ac0a1..e2abb928f 100644 --- a/Crypto/include/Poco/Crypto/ECKey.h +++ b/Crypto/include/Poco/Crypto/ECKey.h @@ -32,7 +32,7 @@ class X509Certificate; class PKCS12Container; -class Crypto_API ECKey : public KeyPair +class Crypto_API ECKey: public KeyPair /// This class stores an EC key pair, consisting /// of private and public key. Storage of the private /// key is optional. @@ -73,9 +73,21 @@ public: /// If a private key is specified, you don't need to specify a public key file. /// OpenSSL will auto-create the public key from the private key. + ECKey(const ECKey& key); + /// Creates the ECKey by copying another one. + + ECKey(ECKey&& key) noexcept; + /// Creates the ECKey by moving another one. + ~ECKey(); /// Destroys the ECKey. + ECKey& operator = (const ECKey& other); + /// Assignment. + + ECKey& operator = (ECKey&& other) noexcept; + /// Move assignment. + ECKeyImpl::Ptr impl() const; /// Returns the impl object. @@ -97,9 +109,6 @@ public: static bool hasCurve(const std::string& name); /// Returns true if the named curve is found, /// false otherwise. - -private: - ECKeyImpl::Ptr _pImpl; }; @@ -108,7 +117,7 @@ private: // inline ECKeyImpl::Ptr ECKey::impl() const { - return _pImpl; + return KeyPair::impl().cast(); } diff --git a/Crypto/include/Poco/Crypto/KeyPair.h b/Crypto/include/Poco/Crypto/KeyPair.h index b9a705f8f..6f14a5f8e 100644 --- a/Crypto/include/Poco/Crypto/KeyPair.h +++ b/Crypto/include/Poco/Crypto/KeyPair.h @@ -1,7 +1,6 @@ // // KeyPair.h // -// // Library: Crypto // Package: CryptoCore // Module: KeyPair @@ -48,6 +47,18 @@ public: explicit KeyPair(KeyPairImpl::Ptr pKeyPairImpl = 0); /// Extracts the RSA public key from the given certificate. + KeyPair(const KeyPair& other); + /// Copy constructor. + + KeyPair(KeyPair&& other) noexcept; + /// Move constructor. + + KeyPair& operator = (const KeyPair& other); + /// Assignment. + + KeyPair& operator = (KeyPair&& other) noexcept; + /// Move assignment. + virtual ~KeyPair(); /// Destroys the KeyPair. @@ -57,7 +68,7 @@ public: virtual void save(const std::string& publicKeyPairFile, const std::string& privateKeyPairFile = "", const std::string& privateKeyPairPassphrase = "") const; - /// Exports the public and private keys to the given files. + /// Exports the public and private keys to the given files. /// /// If an empty filename is specified, the corresponding key /// is not exported. @@ -78,7 +89,7 @@ public: Type type() const; /// Returns key pair type - + private: KeyPairImpl::Ptr _pImpl; }; @@ -87,7 +98,6 @@ private: // // inlines // - inline int KeyPair::size() const { return _pImpl->size(); @@ -115,6 +125,7 @@ inline const std::string& KeyPair::name() const return _pImpl->name(); } + inline KeyPairImpl::Ptr KeyPair::impl() const { return _pImpl; diff --git a/Crypto/include/Poco/Crypto/RSAKey.h b/Crypto/include/Poco/Crypto/RSAKey.h index ad9163ed4..51c97432f 100644 --- a/Crypto/include/Poco/Crypto/RSAKey.h +++ b/Crypto/include/Poco/Crypto/RSAKey.h @@ -31,7 +31,7 @@ class X509Certificate; class PKCS12Container; -class Crypto_API RSAKey : public KeyPair +class Crypto_API RSAKey: public KeyPair /// This class stores an RSA key pair, consisting /// of private and public key. Storage of the private /// key is optional. @@ -90,9 +90,21 @@ public: /// If a private key is specified, you don't need to specify a public key file. /// OpenSSL will auto-create the public key from the private key. + RSAKey(const RSAKey& other); + /// Copy constructor. + + RSAKey(RSAKey&& other) noexcept; + /// Move constructor. + ~RSAKey(); /// Destroys the RSAKey. + RSAKey& operator = (const RSAKey& other); + /// Assignment. + + RSAKey& operator = (RSAKey&& other) noexcept; + /// Move assignment. + RSAKeyImpl::ByteVec modulus() const; /// Returns the RSA modulus. @@ -104,9 +116,6 @@ public: RSAKeyImpl::Ptr impl() const; /// Returns the impl object. - -private: - RSAKeyImpl::Ptr _pImpl; }; @@ -115,7 +124,7 @@ private: // inline RSAKeyImpl::Ptr RSAKey::impl() const { - return _pImpl; + return KeyPair::impl().cast(); } diff --git a/Crypto/src/CipherKey.cpp b/Crypto/src/CipherKey.cpp index 275edd1c8..41217422b 100644 --- a/Crypto/src/CipherKey.cpp +++ b/Crypto/src/CipherKey.cpp @@ -41,9 +41,38 @@ CipherKey::CipherKey(const std::string& name): } +CipherKey::CipherKey(const CipherKey& other): + _pImpl(other._pImpl) +{ +} + + +CipherKey::CipherKey(CipherKey&& other) noexcept: + _pImpl(std::move(other._pImpl)) +{ +} + + CipherKey::~CipherKey() { } +CipherKey& CipherKey::operator = (const CipherKey& other) +{ + if (&other != this) + { + _pImpl = other._pImpl; + } + return *this; +} + + +CipherKey& CipherKey::operator = (CipherKey&& other) noexcept +{ + _pImpl = std::move(other._pImpl); + return *this; +} + + } } // namespace Poco::Crypto diff --git a/Crypto/src/ECKey.cpp b/Crypto/src/ECKey.cpp index 56b866377..105a7d3c3 100644 --- a/Crypto/src/ECKey.cpp +++ b/Crypto/src/ECKey.cpp @@ -22,47 +22,49 @@ namespace Crypto { ECKey::ECKey(const EVPPKey& key): - KeyPair(new ECKeyImpl(key)), - _pImpl(KeyPair::impl().cast()) + KeyPair(new ECKeyImpl(key)) { } ECKey::ECKey(const X509Certificate& cert): - KeyPair(new ECKeyImpl(cert)), - _pImpl(KeyPair::impl().cast()) + KeyPair(new ECKeyImpl(cert)) { } ECKey::ECKey(const PKCS12Container& cont): - KeyPair(new ECKeyImpl(cont)), - _pImpl(KeyPair::impl().cast()) + KeyPair(new ECKeyImpl(cont)) { } ECKey::ECKey(const std::string& eccGroup): - KeyPair(new ECKeyImpl(OBJ_txt2nid(eccGroup.c_str()))), - _pImpl(KeyPair::impl().cast()) + KeyPair(new ECKeyImpl(OBJ_txt2nid(eccGroup.c_str()))) { } -ECKey::ECKey(const std::string& publicKeyFile, - const std::string& privateKeyFile, - const std::string& privateKeyPassphrase): - KeyPair(new ECKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase)), - _pImpl(KeyPair::impl().cast()) +ECKey::ECKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase): + KeyPair(new ECKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase)) { } -ECKey::ECKey(std::istream* pPublicKeyStream, - std::istream* pPrivateKeyStream, - const std::string& privateKeyPassphrase): - KeyPair(new ECKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase)), - _pImpl(KeyPair::impl().cast()) +ECKey::ECKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase): + KeyPair(new ECKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase)) +{ +} + + +ECKey::ECKey(const ECKey& other): + KeyPair(other) +{ +} + + +ECKey::ECKey(ECKey&& other) noexcept: + KeyPair(std::move(other)) { } @@ -72,4 +74,18 @@ ECKey::~ECKey() } +ECKey& ECKey::operator = (const ECKey& other) +{ + KeyPair::operator = (other); + return *this; +} + + +ECKey& ECKey::operator = (ECKey&& other) noexcept +{ + KeyPair::operator = (std::move(other)); + return *this; +} + + } } // namespace Poco::Crypto diff --git a/Crypto/src/EVPPKey.cpp b/Crypto/src/EVPPKey.cpp index d6d9e1072..832add751 100644 --- a/Crypto/src/EVPPKey.cpp +++ b/Crypto/src/EVPPKey.cpp @@ -89,11 +89,10 @@ EVPPKey::EVPPKey(const EVPPKey& other) } -EVPPKey::EVPPKey(EVPPKey&& other) noexcept: +EVPPKey::EVPPKey(EVPPKey&& other) noexcept: _pEVPPKey(other._pEVPPKey) { other._pEVPPKey = nullptr; - poco_check_ptr(_pEVPPKey); } @@ -109,7 +108,6 @@ EVPPKey& EVPPKey::operator = (EVPPKey&& other) noexcept { _pEVPPKey = other._pEVPPKey; other._pEVPPKey = nullptr; - poco_check_ptr(_pEVPPKey); return *this; } diff --git a/Crypto/src/KeyPair.cpp b/Crypto/src/KeyPair.cpp index 1c650806b..25dc4f927 100644 --- a/Crypto/src/KeyPair.cpp +++ b/Crypto/src/KeyPair.cpp @@ -1,7 +1,6 @@ // // KeyPair.cpp // -// // Library: Crypto // Package: CryptoCore // Module: KeyPair @@ -21,7 +20,20 @@ namespace Poco { namespace Crypto { -KeyPair::KeyPair(KeyPairImpl::Ptr pKeyPairImpl): _pImpl(pKeyPairImpl) +KeyPair::KeyPair(KeyPairImpl::Ptr pKeyPairImpl): + _pImpl(pKeyPairImpl) +{ +} + + +KeyPair::KeyPair(const KeyPair& other): + _pImpl(other._pImpl) +{ +} + + +KeyPair::KeyPair(KeyPair&& other) noexcept: + _pImpl(std::move(other._pImpl)) { } @@ -31,4 +43,21 @@ KeyPair::~KeyPair() } +KeyPair& KeyPair::operator = (const KeyPair& other) +{ + if (&other != this) + { + _pImpl = other._pImpl; + } + return *this; +} + + +KeyPair& KeyPair::operator = (KeyPair&& other) noexcept +{ + _pImpl = std::move(other._pImpl); + return *this; +} + + } } // namespace Poco::Crypto diff --git a/Crypto/src/PKCS12Container.cpp b/Crypto/src/PKCS12Container.cpp index a99e7dfaf..9675d9af4 100644 --- a/Crypto/src/PKCS12Container.cpp +++ b/Crypto/src/PKCS12Container.cpp @@ -73,6 +73,17 @@ PKCS12Container::PKCS12Container(const PKCS12Container& other): } +PKCS12Container::PKCS12Container(PKCS12Container&& other) noexcept: + _pKey(other._pKey), + _pX509Cert(std::move(other._pX509Cert)), + _caCertList(std::move(other._caCertList)), + _caCertNames(std::move(other._caCertNames)), + _pkcsFriendlyName(std::move(other._pkcsFriendlyName)) +{ + other._pKey = nullptr; +} + + PKCS12Container& PKCS12Container::operator = (const PKCS12Container& other) { if (&other != this) @@ -88,17 +99,6 @@ PKCS12Container& PKCS12Container::operator = (const PKCS12Container& other) } -PKCS12Container::PKCS12Container(PKCS12Container&& other) noexcept: - _pKey(other._pKey), - _pX509Cert(std::move(other._pX509Cert)), - _caCertList(std::move(other._caCertList)), - _caCertNames(std::move(other._caCertNames)), - _pkcsFriendlyName(std::move(other._pkcsFriendlyName)) -{ - other._pKey = nullptr; -} - - PKCS12Container& PKCS12Container::operator = (PKCS12Container&& other) noexcept { if (_pKey) EVP_PKEY_free(_pKey); diff --git a/Crypto/src/RSAKey.cpp b/Crypto/src/RSAKey.cpp index b81a0281b..ef53be9b2 100644 --- a/Crypto/src/RSAKey.cpp +++ b/Crypto/src/RSAKey.cpp @@ -21,43 +21,49 @@ namespace Crypto { RSAKey::RSAKey(const EVPPKey& key): - KeyPair(new RSAKeyImpl(key)), - _pImpl(KeyPair::impl().cast()) + KeyPair(new RSAKeyImpl(key)) { } RSAKey::RSAKey(const X509Certificate& cert): - KeyPair(new RSAKeyImpl(cert)), - _pImpl(KeyPair::impl().cast()) + KeyPair(new RSAKeyImpl(cert)) { } RSAKey::RSAKey(const PKCS12Container& cont): - KeyPair(new RSAKeyImpl(cont)), - _pImpl(KeyPair::impl().cast()) + KeyPair(new RSAKeyImpl(cont)) { } RSAKey::RSAKey(KeyLength keyLength, Exponent exp): - KeyPair(new RSAKeyImpl(keyLength, (exp == EXP_LARGE) ? RSA_F4 : RSA_3)), - _pImpl(KeyPair::impl().cast()) + KeyPair(new RSAKeyImpl(keyLength, (exp == EXP_LARGE) ? RSA_F4 : RSA_3)) { } RSAKey::RSAKey(const std::string& publicKeyFile, const std::string& privateKeyFile, const std::string& privateKeyPassphrase): - KeyPair(new RSAKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase)), - _pImpl(KeyPair::impl().cast()) + KeyPair(new RSAKeyImpl(publicKeyFile, privateKeyFile, privateKeyPassphrase)) { } RSAKey::RSAKey(std::istream* pPublicKeyStream, std::istream* pPrivateKeyStream, const std::string& privateKeyPassphrase): - KeyPair(new RSAKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase)), - _pImpl(KeyPair::impl().cast()) + KeyPair(new RSAKeyImpl(pPublicKeyStream, pPrivateKeyStream, privateKeyPassphrase)) +{ +} + + +RSAKey::RSAKey(const RSAKey& other): + KeyPair(other) +{ +} + + +RSAKey::RSAKey(RSAKey&& other) noexcept: + KeyPair(std::move(other)) { } @@ -66,22 +72,37 @@ RSAKey::~RSAKey() { } + +RSAKey& RSAKey::operator = (const RSAKey& other) +{ + KeyPair::operator = (other); + return *this; +} + + +RSAKey& RSAKey::operator = (RSAKey&& other) noexcept +{ + KeyPair::operator = (std::move(other)); + return *this; +} + + RSAKeyImpl::ByteVec RSAKey::modulus() const { - return _pImpl->modulus(); + return impl()->modulus(); } RSAKeyImpl::ByteVec RSAKey::encryptionExponent() const { - return _pImpl->encryptionExponent(); + return impl()->encryptionExponent(); } RSAKeyImpl::ByteVec RSAKey::decryptionExponent() const { - return _pImpl->decryptionExponent(); + return impl()->decryptionExponent(); } -} } // namespace Poco::Crypto \ No newline at end of file +} } // namespace Poco::Crypto diff --git a/Crypto/src/X509Certificate.cpp b/Crypto/src/X509Certificate.cpp index 43e8469d4..dff55bec6 100644 --- a/Crypto/src/X509Certificate.cpp +++ b/Crypto/src/X509Certificate.cpp @@ -29,12 +29,14 @@ #include #include + #if OPENSSL_VERSION_NUMBER < 0x10100000L #define ASN1_STRING_get0_data ASN1_STRING_data #define X509_get0_notBefore X509_get_notBefore #define X509_get0_notAfter X509_get_notAfter #endif + namespace Poco { namespace Crypto { @@ -113,6 +115,7 @@ X509Certificate& X509Certificate::operator = (X509Certificate&& cert) noexcept _issuerName = std::move(cert._issuerName); _subjectName = std::move(cert._subjectName); _serialNumber = std::move(cert._serialNumber); + if (_pCert) X509_free(_pCert); _pCert = cert._pCert; cert._pCert = nullptr; return *this; } diff --git a/Data/src/MetaColumn.cpp b/Data/src/MetaColumn.cpp index 940a10a03..d333164fe 100644 --- a/Data/src/MetaColumn.cpp +++ b/Data/src/MetaColumn.cpp @@ -34,7 +34,7 @@ MetaColumn::MetaColumn(std::size_t position, ColumnDataType type, std::size_t length, std::size_t precision, - bool nullable): + bool nullable): _name(name), _length(length), _precision(precision), @@ -91,6 +91,7 @@ MetaColumn& MetaColumn::operator = (MetaColumn&& other) noexcept return *this; } + void MetaColumn::swap(MetaColumn& other) { std::swap(_name, other._name); diff --git a/Data/src/Session.cpp b/Data/src/Session.cpp index 0bd9f90d1..985acb255 100644 --- a/Data/src/Session.cpp +++ b/Data/src/Session.cpp @@ -48,16 +48,16 @@ Session::Session(const std::string& connection, } -Session::Session(const Session& other): +Session::Session(const Session& other): _pImpl(other._pImpl), - _statementCreator(other._pImpl) + _statementCreator(other._statementCreator) { } -Session::Session(Session&& other) noexcept: +Session::Session(Session&& other) noexcept: _pImpl(std::move(other._pImpl)), - _statementCreator(std::move(other._pImpl)) + _statementCreator(std::move(other._statementCreator)) { } diff --git a/Foundation/include/Poco/Message.h b/Foundation/include/Poco/Message.h index 7c42b748c..9779f0de7 100644 --- a/Foundation/include/Poco/Message.h +++ b/Foundation/include/Poco/Message.h @@ -54,109 +54,109 @@ public: PRIO_DEBUG, /// A debugging message. PRIO_TRACE /// A tracing message. This is the lowest priority. }; - + Message(); /// Creates an empty Message. /// The thread and process ids are set. - + Message(const std::string& source, const std::string& text, Priority prio); /// Creates a Message with the given source, text and priority. /// The thread and process ids are set. Message(const std::string& source, const std::string& text, Priority prio, const char* file, int line); /// Creates a Message with the given source, text, priority, - /// source file path and line. + /// source file path and line. /// - /// The source file path must be a + /// The source file path must be a /// static string with a lifetime that's at least the lifetime /// of the message object (the string is not copied internally). - /// Usually, this will be the path string obtained from the + /// Usually, this will be the path string obtained from the /// __FILE__ macro. /// /// The thread and process ids are set. - + Message(const Message& msg); /// Creates a Message by copying another one. - - Message(Message&& msg); + + Message(Message&& msg) noexcept; /// Creates a Message by copying another one. Message(const Message& msg, const std::string& text); /// Creates a Message by copying all but the text from another message. - + ~Message(); /// Destroys the Message. - + Message& operator = (const Message& msg); /// Assignment operator. - - Message& operator = (Message&& msg); + + Message& operator = (Message&& msg) noexcept; /// Assignment operator. void swap(Message& msg); - /// Swaps the message with another one. - + /// Swaps the message with another one. + void setSource(const std::string& src); /// Sets the source of the message. - + const std::string& getSource() const; /// Returns the source of the message. - + void setText(const std::string& text); /// Sets the text of the message. - + const std::string& getText() const; /// Returns the text of the message. - + void setPriority(Priority prio); /// Sets the priority of the message. - + Priority getPriority() const; /// Returns the priority of the message. - + void setTime(const Timestamp& time); /// Sets the time of the message. - + const Timestamp& getTime() const; /// Returns the time of the message. - + void setThread(const std::string& thread); /// Sets the thread identifier for the message. - + const std::string& getThread() const; /// Returns the thread identifier for the message. void setTid(long pid); /// Sets the numeric thread identifier for the message. - + long getTid() const; /// Returns the numeric thread identifier for the message. - + void setPid(long pid); /// Sets the process identifier for the message. - + long getPid() const; /// Returns the process identifier for the message. - + void setSourceFile(const char* file); /// Sets the source file path of the statement /// generating the log message. /// /// File must be a static string, such as the value of /// the __FILE__ macro. The string is not copied - /// internally for performance reasons. - + /// internally for performance reasons. + const char* getSourceFile() const; /// Returns the source file path of the code creating /// the message. May be 0 if not set. - + void setSourceLine(int line); /// Sets the source file line of the statement /// generating the log message. /// /// This is usually the result of the __LINE__ /// macro. - + int getSourceLine() const; /// Returns the source file line of the statement /// generating the log message. May be 0 @@ -183,7 +183,7 @@ public: /// Returns a const reference to the value of the parameter /// with the given name. Throws a NotFoundException if the /// parameter does not exist. - + std::string& operator [] (const std::string& param); /// Returns a reference to the value of the parameter with the /// given name. This can be used to set the parameter's value. @@ -194,7 +194,7 @@ protected: void init(); typedef std::map StringMap; -private: +private: std::string _source; std::string _text; Priority _prio; diff --git a/Foundation/src/Message.cpp b/Foundation/src/Message.cpp index 7a26c9253..94a3b53b3 100644 --- a/Foundation/src/Message.cpp +++ b/Foundation/src/Message.cpp @@ -24,41 +24,41 @@ namespace Poco { -Message::Message(): - _prio(PRIO_FATAL), - _tid(0), +Message::Message(): + _prio(PRIO_FATAL), + _tid(0), _pid(0), _file(0), _line(0), - _pMap(0) + _pMap(0) { init(); } -Message::Message(const std::string& source, const std::string& text, Priority prio): - _source(source), - _text(text), - _prio(prio), +Message::Message(const std::string& source, const std::string& text, Priority prio): + _source(source), + _text(text), + _prio(prio), _tid(0), _pid(0), _file(0), _line(0), - _pMap(0) + _pMap(0) { init(); } Message::Message(const std::string& source, const std::string& text, Priority prio, const char* file, int line): - _source(source), - _text(text), - _prio(prio), + _source(source), + _text(text), + _prio(prio), _tid(0), _pid(0), _file(file), _line(line), - _pMap(0) + _pMap(0) { init(); } @@ -82,7 +82,7 @@ Message::Message(const Message& msg): } -Message::Message(Message&& msg) : +Message::Message(Message&& msg) noexcept: _source(std::move(msg._source)), _text(std::move(msg._text)), _prio(std::move(msg._prio)), @@ -147,23 +147,20 @@ Message& Message::operator = (const Message& msg) } -Message& Message::operator = (Message&& msg) +Message& Message::operator = (Message&& msg) noexcept { - if (&msg != this) - { - _source = std::move(msg._source); - _text = std::move(msg._text); - _prio = std::move(msg._prio); - _time = std::move(msg._time); - _tid = std::move(msg._tid); - _thread = std::move(msg._thread); - _pid = std::move(msg._pid); - _file = std::move(msg._file); - _line = std::move(msg._line); - delete _pMap; - _pMap = msg._pMap; - msg._pMap = nullptr; - } + _source = std::move(msg._source); + _text = std::move(msg._text); + _prio = std::move(msg._prio); + _time = std::move(msg._time); + _tid = std::move(msg._tid); + _thread = std::move(msg._thread); + _pid = std::move(msg._pid); + _file = std::move(msg._file); + _line = std::move(msg._line); + delete _pMap; + _pMap = msg._pMap; + msg._pMap = nullptr; return *this; } diff --git a/JSON/include/Poco/JSON/Array.h b/JSON/include/Poco/JSON/Array.h index 507f2ead4..ac65b1313 100644 --- a/JSON/include/Poco/JSON/Array.h +++ b/JSON/include/Poco/JSON/Array.h @@ -73,16 +73,16 @@ public: Array(const Array& copy); /// Creates an Array by copying another one. - Array(Array&& other); + Array(Array&& other) noexcept; /// Move constructor - Array& operator=(Array&& other); - /// Move assignment operator. - - Array& operator=(const Array& other); + Array& operator = (const Array& other); /// Assignment operator. - virtual ~Array(); + Array& operator = (Array&& other) noexcept; + /// Move assignment operator. + + ~Array(); /// Destroys the Array. void setEscapeUnicode(bool escape = true); diff --git a/JSON/include/Poco/JSON/Object.h b/JSON/include/Poco/JSON/Object.h index 60837cf05..b733f828c 100644 --- a/JSON/include/Poco/JSON/Object.h +++ b/JSON/include/Poco/JSON/Object.h @@ -84,18 +84,18 @@ public: /// Struct is not copied to keep the operation as /// efficient as possible (when needed, it will be generated upon request). - Object(Object&& other); + Object(Object&& other) noexcept; /// Move constructor - Object &operator =(Object &&other); - // Move asignment operator - - virtual ~Object(); + ~Object(); /// Destroys the Object. - Object &operator =(const Object &other); + Object &operator = (const Object &other); // Assignment operator + Object &operator = (Object &&other) noexcept; + // Move asignment operator + void setEscapeUnicode(bool escape = true); /// Sets the flag for escaping unicode. diff --git a/JSON/src/Array.cpp b/JSON/src/Array.cpp index 9d07cb04a..67e43f218 100644 --- a/JSON/src/Array.cpp +++ b/JSON/src/Array.cpp @@ -25,46 +25,50 @@ namespace Poco { namespace JSON { -Array::Array(int options): _modified(false), +Array::Array(int options): + _modified(false), _escapeUnicode((options & Poco::JSON_ESCAPE_UNICODE) != 0) { } -Array::Array(const Array& other) : _values(other._values), +Array::Array(const Array& other) : + _values(other._values), _pArray(other._pArray), - _modified(other._modified) + _modified(other._modified), + _escapeUnicode(other._escapeUnicode) { } -Array &Array::operator=(const Array& other) +Array::Array(Array&& other) noexcept: + _values(std::move(other._values)), + _pArray(std::move(other._pArray)), + _modified(other._modified), + _escapeUnicode(other._escapeUnicode) +{ +} + + +Array& Array::operator = (const Array& other) { if (&other != this) { _values = other._values; _pArray = other._pArray; _modified = other._modified; + _escapeUnicode = other._escapeUnicode; } return *this; } -Array::Array(Array&& other): - _values(std::move(other._values)), - _pArray(!other._modified ? other._pArray : 0), - _modified(other._modified) -{ - _pArray = 0; -} - - -Array &Array::operator = (Array&& other) +Array& Array::operator = (Array&& other) noexcept { _values = std::move(other._values); - _pArray = other._pArray; - other._pArray = 0; + _pArray = std::move(other._pArray); _modified = other._modified; + _escapeUnicode = other._escapeUnicode; return *this; } diff --git a/JSON/src/Object.cpp b/JSON/src/Object.cpp index 48c391085..9ddbfc71d 100644 --- a/JSON/src/Object.cpp +++ b/JSON/src/Object.cpp @@ -42,29 +42,15 @@ Object::Object(const Object& other) : _values(other._values), } -Object::Object(Object&& other): +Object::Object(Object&& other) noexcept: _values(std::move(other._values)), _keys(std::move(other._keys)), _preserveInsOrder(other._preserveInsOrder), _escapeUnicode(other._escapeUnicode), - _pStruct(!other._modified ? other._pStruct : 0), + _pStruct(std::move(other._pStruct)), + _pOrdStruct(std::move(other._pOrdStruct)), _modified(other._modified) { - other.clear(); -} - - -Object &Object::operator = (Object&& other) -{ - _values = other._values; - _preserveInsOrder = other._preserveInsOrder; - syncKeys(other._keys); - _escapeUnicode = other._escapeUnicode; - _pStruct = !other._modified ? other._pStruct : 0; - _modified = other._modified; - other.clear(); - - return *this; } @@ -73,7 +59,7 @@ Object::~Object() } -Object &Object::operator= (const Object &other) +Object &Object::operator = (const Object &other) { if (&other != this) { @@ -88,6 +74,20 @@ Object &Object::operator= (const Object &other) } +Object& Object::operator = (Object&& other) noexcept +{ + _values = std::move(other._values); + _keys = std::move(other._keys); + _preserveInsOrder = other._preserveInsOrder; + _escapeUnicode = other._escapeUnicode; + _pStruct = std::move(other._pStruct); + _pOrdStruct = std::move(other._pOrdStruct); + _modified = other._modified; + + return *this; +} + + void Object::syncKeys(const KeyList& keys) { if(_preserveInsOrder) diff --git a/NetSSL_OpenSSL/src/X509Certificate.cpp b/NetSSL_OpenSSL/src/X509Certificate.cpp index f6d3ba4c1..0d9458a74 100644 --- a/NetSSL_OpenSSL/src/X509Certificate.cpp +++ b/NetSSL_OpenSSL/src/X509Certificate.cpp @@ -33,7 +33,7 @@ namespace Net { X509Certificate::X509Certificate(std::istream& istr): Poco::Crypto::X509Certificate(istr) -{ +{ } @@ -91,7 +91,7 @@ X509Certificate& X509Certificate::operator = (const X509Certificate& cert) X509Certificate& X509Certificate::operator = (X509Certificate&& cert) noexcept { - Poco::Crypto::X509Certificate::operator = (cert); + Poco::Crypto::X509Certificate::operator = (std::move(cert)); return *this; } @@ -108,7 +108,7 @@ bool X509Certificate::verify(const std::string& hostName) const bool X509Certificate::verify(const Poco::Crypto::X509Certificate& certificate, const std::string& hostName) -{ +{ #if OPENSSL_VERSION_NUMBER < 0x10002000L std::string commonName; std::set dnsNames;