diff --git a/MongoDB/include/Poco/MongoDB/Array.h b/MongoDB/include/Poco/MongoDB/Array.h index a3bf7f27f8..5f6fcbadeb 100644 --- a/MongoDB/include/Poco/MongoDB/Array.h +++ b/MongoDB/include/Poco/MongoDB/Array.h @@ -36,7 +36,7 @@ class MongoDB_API Array: public Document Array(); /// Creates an empty Array. - virtual ~Array(); + ~Array() override; /// Destroys the Array. // Document template functions available for backward compatibility @@ -93,7 +93,7 @@ class MongoDB_API Array: public Document return Document::isType(Poco::NumberFormatter::format(pos)); } - std::string toString(int indent = 0) const; + std::string toString(int indent = 0) const override; /// Returns a string representation of the Array. private: diff --git a/MongoDB/include/Poco/MongoDB/Binary.h b/MongoDB/include/Poco/MongoDB/Binary.h index 5e9eb58f20..9563b1b26f 100644 --- a/MongoDB/include/Poco/MongoDB/Binary.h +++ b/MongoDB/include/Poco/MongoDB/Binary.h @@ -20,12 +20,8 @@ #include "Poco/MongoDB/MongoDB.h" #include "Poco/MongoDB/Element.h" -#include "Poco/Base64Encoder.h" #include "Poco/Buffer.h" -#include "Poco/StreamCopier.h" -#include "Poco/MemoryStream.h" #include "Poco/UUID.h" -#include namespace Poco { @@ -106,7 +102,7 @@ inline Buffer& Binary::buffer() inline std::string Binary::toRawString() const { - return std::string(reinterpret_cast(_buffer.begin()), _buffer.size()); + return {reinterpret_cast(_buffer.begin()), _buffer.size()}; } @@ -145,7 +141,7 @@ inline void BSONWriter::write(Binary::Ptr& from) { _writer << (Poco::Int32) from->buffer().size(); _writer << from->subtype(); - _writer.writeRaw((char*) from->buffer().begin(), from->buffer().size()); + _writer.writeRaw(reinterpret_cast(from->buffer().begin()), from->buffer().size()); } diff --git a/MongoDB/include/Poco/MongoDB/Connection.h b/MongoDB/include/Poco/MongoDB/Connection.h index 5b718fa5a0..85d0616c52 100644 --- a/MongoDB/include/Poco/MongoDB/Connection.h +++ b/MongoDB/include/Poco/MongoDB/Connection.h @@ -20,7 +20,6 @@ #include "Poco/Net/SocketAddress.h" #include "Poco/Net/StreamSocket.h" -#include "Poco/Mutex.h" #include "Poco/MongoDB/RequestMessage.h" #include "Poco/MongoDB/ResponseMessage.h" #include "Poco/MongoDB/OpMsgMessage.h" diff --git a/MongoDB/include/Poco/MongoDB/Document.h b/MongoDB/include/Poco/MongoDB/Document.h index f84fc122d0..ad33af5a30 100644 --- a/MongoDB/include/Poco/MongoDB/Document.h +++ b/MongoDB/include/Poco/MongoDB/Document.h @@ -108,7 +108,7 @@ class MongoDB_API Document /// Returns true if the document has an element with the given name. template - T get(const std::string& name) const + const T& get(const std::string& name) const /// Returns the element with the given name and tries to convert /// it to the template type. When the element is not found, a /// NotFoundException will be thrown. When the element can't be @@ -123,7 +123,7 @@ class MongoDB_API Document { if (ElementTraits::TypeId == element->type()) { - ConcreteElement* concrete = dynamic_cast* >(element.get()); + auto* concrete = dynamic_cast* >(element.get()); if (concrete != 0) { return concrete->value(); @@ -134,7 +134,7 @@ class MongoDB_API Document } template - T get(const std::string& name, const T& def) const + const T& get(const std::string& name, const T& def) const /// Returns the element with the given name and tries to convert /// it to the template type. When the element is not found, or /// has the wrong type, the def argument will be returned. @@ -147,7 +147,7 @@ class MongoDB_API Document if (ElementTraits::TypeId == element->type()) { - ConcreteElement* concrete = dynamic_cast* >(element.get()); + auto* concrete = dynamic_cast* >(element.get()); if (concrete != 0) { return concrete->value(); @@ -232,9 +232,9 @@ inline bool Document::empty() const inline void Document::elementNames(std::vector& keys) const { - for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it) + for (const auto & _element : _elements) { - keys.push_back((*it)->name()); + keys.push_back(_element->name()); } } diff --git a/MongoDB/include/Poco/MongoDB/Element.h b/MongoDB/include/Poco/MongoDB/Element.h index 47a9fae7e1..78e845be8f 100644 --- a/MongoDB/include/Poco/MongoDB/Element.h +++ b/MongoDB/include/Poco/MongoDB/Element.h @@ -25,7 +25,6 @@ #include "Poco/Nullable.h" #include "Poco/NumberFormatter.h" #include "Poco/DateTimeFormatter.h" -#include "Poco/UTF8String.h" #include "Poco/MongoDB/MongoDB.h" #include "Poco/MongoDB/BSONReader.h" #include "Poco/MongoDB/BSONWriter.h" @@ -115,9 +114,9 @@ struct ElementTraits oss << '"'; - for (std::string::const_iterator it = value.begin(); it != value.end(); ++it) + for (char it : value) { - switch (*it) + switch (it) { case '"': oss << "\\\""; @@ -142,13 +141,13 @@ struct ElementTraits break; default: { - if ( *it > 0 && *it <= 0x1F ) + if ( it > 0 && it <= 0x1F ) { - oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast(*it); + oss << "\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast(it); } else { - oss << *it; + oss << it; } break; } @@ -360,34 +359,32 @@ class ConcreteElement: public Element { } - virtual ~ConcreteElement() - { - } + ~ConcreteElement() override = default; - T value() const + const T& value() const { return _value; } - std::string toString(int indent = 0) const + std::string toString(int indent = 0) const override { return ElementTraits::toString(_value, indent); } - int type() const + int type() const override { return ElementTraits::TypeId; } - void read(BinaryReader& reader) + void read(BinaryReader& reader) override { BSONReader(reader).read(_value); } - void write(BinaryWriter& writer) + void write(BinaryWriter& writer) override { BSONWriter(writer).write(_value); } diff --git a/MongoDB/src/Array.cpp b/MongoDB/src/Array.cpp index 6fff0994d8..c4e4b6b6de 100644 --- a/MongoDB/src/Array.cpp +++ b/MongoDB/src/Array.cpp @@ -46,7 +46,7 @@ std::string Array::toString(int indent) const if (indent > 0) oss << std::endl; - for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it) + for (auto it = _elements.begin(), total = _elements.end(); it != total; ++it) { if (it != _elements.begin()) { diff --git a/MongoDB/src/Binary.cpp b/MongoDB/src/Binary.cpp index ea814d6969..604ac52c05 100644 --- a/MongoDB/src/Binary.cpp +++ b/MongoDB/src/Binary.cpp @@ -13,6 +13,10 @@ #include "Poco/MongoDB/Binary.h" +#include "Poco/Base64Encoder.h" +#include "Poco/StreamCopier.h" +#include "Poco/MemoryStream.h" +#include namespace Poco { diff --git a/MongoDB/src/Database.cpp b/MongoDB/src/Database.cpp index f00fc96813..ecd2ffd190 100644 --- a/MongoDB/src/Database.cpp +++ b/MongoDB/src/Database.cpp @@ -13,6 +13,7 @@ #include "Poco/MongoDB/Database.h" +#include "Poco/Base64Encoder.h" #include "Poco/MongoDB/Binary.h" #include "Poco/MD5Engine.h" #include "Poco/SHA1Engine.h" diff --git a/MongoDB/src/Document.cpp b/MongoDB/src/Document.cpp index f7c5c9c5dc..cfdf221ba3 100644 --- a/MongoDB/src/Document.cpp +++ b/MongoDB/src/Document.cpp @@ -47,7 +47,7 @@ Element::Ptr Document::get(const std::string& name) const { Element::Ptr element; - ElementSet::const_iterator it = std::find_if(_elements.begin(), _elements.end(), ElementFindByName(name)); + auto it = std::find_if(_elements.begin(), _elements.end(), ElementFindByName(name)); if (it != _elements.end()) { return *it; @@ -167,7 +167,7 @@ std::string Document::toString(int indent) const if (indent > 0) oss << std::endl; - for (ElementSet::const_iterator it = _elements.begin(); it != _elements.end(); ++it) + for (auto it = _elements.begin(), total = _elements.end(); it != total; ++it) { if (it != _elements.begin()) { diff --git a/MongoDB/testsuite/src/MongoDBTestOpMsg.cpp b/MongoDB/testsuite/src/MongoDBTestOpMsg.cpp index 7d843e1214..113f66d548 100644 --- a/MongoDB/testsuite/src/MongoDBTestOpMsg.cpp +++ b/MongoDB/testsuite/src/MongoDBTestOpMsg.cpp @@ -60,7 +60,7 @@ void MongoDBTest::testOpCmdUUID() Document::Ptr doc = response.documents()[0]; try { - std::string name = doc->get("name"); + const auto& name = doc->get("name"); assertEquals ("Barcelona", name ); Binary::Ptr uuidBinary = doc->get("uuid"); @@ -194,14 +194,14 @@ void MongoDBTest::testOpCmdFind() try { - std::string lastname = doc->get("lastname"); + const auto& lastname = doc->get("lastname"); assertEquals ("Braem", lastname); - std::string firstname = doc->get("firstname"); + const auto& firstname = doc->get("firstname"); assertEquals ("Franky", firstname); - Poco::Timestamp birthDateTimestamp = doc->get("birthdate"); + const auto& birthDateTimestamp = doc->get("birthdate"); Poco::DateTime birthDate(birthDateTimestamp); assertTrue (birthDate.year() == 1969 && birthDate.month() == 3 && birthDate.day() == 9); - Poco::Timestamp lastupdatedTimestamp = doc->get("lastupdated"); + const auto& lastupdatedTimestamp = doc->get("lastupdated"); assertTrue (doc->isType("unknown")); bool active = doc->get("active"); assertEquals (false, active);