diff --git a/JSON/include/Poco/JSON/Array.h b/JSON/include/Poco/JSON/Array.h index 1e0c9e6432..dca8692208 100644 --- a/JSON/include/Poco/JSON/Array.h +++ b/JSON/include/Poco/JSON/Array.h @@ -217,7 +217,7 @@ class JSON_API Array private: void resetDynArray() const; - typedef SharedPtr ArrayPtr; + using ArrayPtr = SharedPtr; ValueVec _values; mutable ArrayPtr _pArray; @@ -340,98 +340,96 @@ class VarHolderImpl: public VarHolder { } - ~VarHolderImpl() - { - } + ~VarHolderImpl() override = default; - const std::type_info& type() const + const std::type_info& type() const override { return typeid(JSON::Array::Ptr); } - void convert(Int8&) const + void convert(Int8&) const override { throw BadCastException(); } - void convert(Int16&) const + void convert(Int16&) const override { throw BadCastException(); } - void convert(Int32&) const + void convert(Int32&) const override { throw BadCastException(); } - void convert(Int64&) const + void convert(Int64&) const override { throw BadCastException(); } - void convert(UInt8&) const + void convert(UInt8&) const override { throw BadCastException(); } - void convert(UInt16&) const + void convert(UInt16&) const override { throw BadCastException(); } - void convert(UInt32&) const + void convert(UInt32&) const override { throw BadCastException(); } - void convert(UInt64&) const + void convert(UInt64&) const override { throw BadCastException(); } - void convert(bool& value) const + void convert(bool& value) const override { value = !_val.isNull() && _val->size() > 0; } - void convert(float&) const + void convert(float&) const override { throw BadCastException(); } - void convert(double&) const + void convert(double&) const override { throw BadCastException(); } - void convert(char&) const + void convert(char&) const override { throw BadCastException(); } - void convert(std::string& s) const + void convert(std::string& s) const override { std::ostringstream oss; _val->stringify(oss); s = oss.str(); } - void convert(DateTime& /*val*/) const + void convert(DateTime& /*val*/) const override { throw BadCastException("Cannot convert Array to DateTime"); } - void convert(LocalDateTime& /*ldt*/) const + void convert(LocalDateTime& /*ldt*/) const override { throw BadCastException("Cannot convert Array to LocalDateTime"); } - void convert(Timestamp& /*ts*/) const + void convert(Timestamp& /*ts*/) const override { throw BadCastException("Cannot convert Array to Timestamp"); } - VarHolder* clone(Placeholder* pVarHolder = 0) const + VarHolder* clone(Placeholder* pVarHolder = nullptr) const override { return cloneHolder(pVarHolder, _val); } @@ -441,22 +439,22 @@ class VarHolderImpl: public VarHolder return _val; } - bool isInteger() const + bool isInteger() const override { return false; } - bool isSigned() const + bool isSigned() const override { return false; } - bool isNumeric() const + bool isNumeric() const override { return false; } - bool isString() const + bool isString() const override { return false; } @@ -474,98 +472,96 @@ class VarHolderImpl: public VarHolder { } - ~VarHolderImpl() - { - } + ~VarHolderImpl() override = default; - const std::type_info& type() const + const std::type_info& type() const override { return typeid(JSON::Array); } - void convert(Int8&) const + void convert(Int8&) const override { throw BadCastException(); } - void convert(Int16&) const + void convert(Int16&) const override { throw BadCastException(); } - void convert(Int32&) const + void convert(Int32&) const override { throw BadCastException(); } - void convert(Int64&) const + void convert(Int64&) const override { throw BadCastException(); } - void convert(UInt8&) const + void convert(UInt8&) const override { throw BadCastException(); } - void convert(UInt16&) const + void convert(UInt16&) const override { throw BadCastException(); } - void convert(UInt32&) const + void convert(UInt32&) const override { throw BadCastException(); } - void convert(UInt64&) const + void convert(UInt64&) const override { throw BadCastException(); } - void convert(bool& value) const + void convert(bool& value) const override { value = _val.size() > 0; } - void convert(float&) const + void convert(float&) const override { throw BadCastException(); } - void convert(double&) const + void convert(double&) const override { throw BadCastException(); } - void convert(char&) const + void convert(char&) const override { throw BadCastException(); } - void convert(std::string& s) const + void convert(std::string& s) const override { std::ostringstream oss; _val.stringify(oss); s = oss.str(); } - void convert(DateTime& /*val*/) const + void convert(DateTime& /*val*/) const override { throw BadCastException("Cannot convert Array to DateTime"); } - void convert(LocalDateTime& /*ldt*/) const + void convert(LocalDateTime& /*ldt*/) const override { throw BadCastException("Cannot convert Array to LocalDateTime"); } - void convert(Timestamp& /*ts*/) const + void convert(Timestamp& /*ts*/) const override { throw BadCastException("Cannot convert Array to Timestamp"); } - VarHolder* clone(Placeholder* pVarHolder = 0) const + VarHolder* clone(Placeholder* pVarHolder = nullptr) const override { return cloneHolder(pVarHolder, _val); } @@ -575,22 +571,22 @@ class VarHolderImpl: public VarHolder return _val; } - bool isInteger() const + bool isInteger() const override { return false; } - bool isSigned() const + bool isSigned() const override { return false; } - bool isNumeric() const + bool isNumeric() const override { return false; } - bool isString() const + bool isString() const override { return false; } diff --git a/JSON/include/Poco/JSON/Object.h b/JSON/include/Poco/JSON/Object.h index 5a9585b3b1..2efd4465dc 100644 --- a/JSON/include/Poco/JSON/Object.h +++ b/JSON/include/Poco/JSON/Object.h @@ -188,7 +188,7 @@ class JSON_API Object bool isArray(const std::string& key) const; /// Returns true when the given property contains an array. - bool isArray(ConstIterator& it) const; + bool isArray(const ConstIterator& it) const; /// Returns true when the given property contains an array. bool isNull(const std::string& key) const; @@ -197,7 +197,7 @@ class JSON_API Object bool isObject(const std::string& key) const; /// Returns true when the given property contains an object. - bool isObject(ConstIterator& it) const; + bool isObject(const ConstIterator& it) const; /// Returns true when the given property contains an object. template @@ -207,7 +207,7 @@ class JSON_API Object /// def will be returned. { T value = def; - ValueMap::const_iterator it = _values.find(key); + auto it = _values.find(key); if (it != _values.end() && ! it->second.isEmpty()) { try @@ -255,9 +255,9 @@ class JSON_API Object /// Insertion order preservation property is left intact. private: - typedef std::deque KeyList; - typedef Poco::DynamicStruct::Ptr StructPtr; - typedef Poco::OrderedDynamicStruct::Ptr OrdStructPtr; + using KeyList = std::deque; + using StructPtr = Poco::DynamicStruct::Ptr; + using OrdStructPtr = Poco::OrderedDynamicStruct::Ptr; void syncKeys(const KeyList& keys); @@ -311,30 +311,28 @@ class JSON_API Object if (obj->_preserveInsOrder) { - KeyList::const_iterator it = obj->_keys.begin(); - KeyList::const_iterator end = obj->_keys.end(); - for (; it != end; ++it) + for (const auto& it: obj->_keys) { - if (obj->isObject((*it)->first)) + if (obj->isObject(it->first)) { - Object::Ptr pObj = obj->getObject((*it)->first); + Object::Ptr pObj = obj->getObject(it->first); S str = makeStructImpl(pObj); - ds.insert((*it)->first, str); + ds.insert(it->first, str); } - else if (obj->isArray((*it)->first)) + else if (obj->isArray(it->first)) { - Array::Ptr pArr = obj->getArray((*it)->first); + Array::Ptr pArr = obj->getArray(it->first); std::vector v = Poco::JSON::Array::makeArray(pArr); - ds.insert((*it)->first, v); + ds.insert(it->first, v); } else - ds.insert((*it)->first, (*it)->second); + ds.insert(it->first, it->second); } } else { - ConstIterator it = obj->begin(); - ConstIterator end = obj->end(); + auto it = obj->begin(); + const auto end = obj->end(); for (; it != end; ++it) { if (obj->isObject(it)) @@ -430,19 +428,19 @@ inline Object::ConstIterator Object::end() const inline bool Object::has(const std::string& key) const { - ValueMap::const_iterator it = _values.find(key); + const auto it = _values.find(key); return it != _values.end(); } inline bool Object::isArray(const std::string& key) const { - ValueMap::const_iterator it = _values.find(key); + const auto it = _values.find(key); return isArray(it); } -inline bool Object::isArray(ConstIterator& it) const +inline bool Object::isArray(const ConstIterator& it) const { return it != _values.end() && (it->second.type() == typeid(Array::Ptr) || it->second.type() == typeid(Array)); } @@ -450,19 +448,19 @@ inline bool Object::isArray(ConstIterator& it) const inline bool Object::isNull(const std::string& key) const { - ValueMap::const_iterator it = _values.find(key); + const auto it = _values.find(key); return it == _values.end() || it->second.isEmpty(); } inline bool Object::isObject(const std::string& key) const { - ValueMap::const_iterator it = _values.find(key); + const auto it = _values.find(key); return isObject(it); } -inline bool Object::isObject(ConstIterator& it) const +inline bool Object::isObject(const ConstIterator& it) const { return it != _values.end() && (it->second.type() == typeid(Object::Ptr) || it->second.type() == typeid(Object)); } @@ -478,8 +476,8 @@ inline void Object::remove(const std::string& key) { if (_preserveInsOrder) { - KeyList::iterator it = _keys.begin(); - KeyList::iterator end = _keys.end(); + auto it = _keys.begin(); + const auto end = _keys.end(); for (; it != end; ++it) { if (key == (*it)->first) @@ -508,7 +506,7 @@ inline const Dynamic::Var& Object::getValue(ValueMap::const_iterator& it) const inline const Dynamic::Var& Object::getValue(KeyList::const_iterator& it) const { - ValueMap::const_iterator itv = _values.find((*it)->first); + const auto itv = _values.find((*it)->first); if (itv != _values.end()) return itv->second; else @@ -531,101 +529,99 @@ class VarHolderImpl: public VarHolder { } - ~VarHolderImpl() - { - } + ~VarHolderImpl() override = default; - const std::type_info& type() const + const std::type_info& type() const override { return typeid(JSON::Object::Ptr); } - void convert(Int8&) const + void convert(Int8&) const override { throw BadCastException(); } - void convert(Int16&) const + void convert(Int16&) const override { throw BadCastException(); } - void convert(Int32&) const + void convert(Int32&) const override { throw BadCastException(); } - void convert(Int64&) const + void convert(Int64&) const override { throw BadCastException(); } - void convert(UInt8&) const + void convert(UInt8&) const override { throw BadCastException(); } - void convert(UInt16&) const + void convert(UInt16&) const override { throw BadCastException(); } - void convert(UInt32&) const + void convert(UInt32&) const override { throw BadCastException(); } - void convert(UInt64&) const + void convert(UInt64&) const override { throw BadCastException(); } - void convert(bool& value) const + void convert(bool& value) const override { value = !_val.isNull() && _val->size() > 0; } - void convert(float&) const + void convert(float&) const override { throw BadCastException(); } - void convert(double&) const + void convert(double&) const override { throw BadCastException(); } - void convert(char&) const + void convert(char&) const override { throw BadCastException(); } - void convert(std::string& s) const + void convert(std::string& s) const override { std::ostringstream oss; _val->stringify(oss); s = oss.str(); } - void convert(DateTime& /*val*/) const + void convert(DateTime& /*val*/) const override { //TODO: val = _val; throw NotImplementedException("Conversion not implemented: JSON:Object => DateTime"); } - void convert(LocalDateTime& /*ldt*/) const + void convert(LocalDateTime& /*ldt*/) const override { //TODO: ldt = _val.timestamp(); throw NotImplementedException("Conversion not implemented: JSON:Object => LocalDateTime"); } - void convert(Timestamp& /*ts*/) const + void convert(Timestamp& /*ts*/) const override { //TODO: ts = _val.timestamp(); throw NotImplementedException("Conversion not implemented: JSON:Object => Timestamp"); } - VarHolder* clone(Placeholder* pVarHolder = 0) const + VarHolder* clone(Placeholder* pVarHolder = nullptr) const override { return cloneHolder(pVarHolder, _val); } @@ -635,27 +631,27 @@ class VarHolderImpl: public VarHolder return _val; } - bool isArray() const + bool isArray() const override { return false; } - bool isInteger() const + bool isInteger() const override { return false; } - bool isSigned() const + bool isSigned() const override { return false; } - bool isNumeric() const + bool isNumeric() const override { return false; } - bool isString() const + bool isString() const override { return false; } @@ -673,101 +669,99 @@ class VarHolderImpl: public VarHolder { } - ~VarHolderImpl() - { - } + ~VarHolderImpl() override = default; - const std::type_info& type() const + const std::type_info& type() const override { return typeid(JSON::Object); } - void convert(Int8&) const + void convert(Int8&) const override { throw BadCastException(); } - void convert(Int16&) const + void convert(Int16&) const override { throw BadCastException(); } - void convert(Int32&) const + void convert(Int32&) const override { throw BadCastException(); } - void convert(Int64&) const + void convert(Int64&) const override { throw BadCastException(); } - void convert(UInt8&) const + void convert(UInt8&) const override { throw BadCastException(); } - void convert(UInt16&) const + void convert(UInt16&) const override { throw BadCastException(); } - void convert(UInt32&) const + void convert(UInt32&) const override { throw BadCastException(); } - void convert(UInt64&) const + void convert(UInt64&) const override { throw BadCastException(); } - void convert(bool& value) const + void convert(bool& value) const override { value = _val.size() > 0; } - void convert(float&) const + void convert(float&) const override { throw BadCastException(); } - void convert(double&) const + void convert(double&) const override { throw BadCastException(); } - void convert(char&) const + void convert(char&) const override { throw BadCastException(); } - void convert(std::string& s) const + void convert(std::string& s) const override { std::ostringstream oss; _val.stringify(oss); s = oss.str(); } - void convert(DateTime& /*val*/) const + void convert(DateTime& /*val*/) const override { //TODO: val = _val; throw NotImplementedException("Conversion not implemented: JSON:Object => DateTime"); } - void convert(LocalDateTime& /*ldt*/) const + void convert(LocalDateTime& /*ldt*/) const override { //TODO: ldt = _val.timestamp(); throw NotImplementedException("Conversion not implemented: JSON:Object => LocalDateTime"); } - void convert(Timestamp& /*ts*/) const + void convert(Timestamp& /*ts*/) const override { //TODO: ts = _val.timestamp(); throw NotImplementedException("Conversion not implemented: JSON:Object => Timestamp"); } - VarHolder* clone(Placeholder* pVarHolder = 0) const + VarHolder* clone(Placeholder* pVarHolder = nullptr) const override { return cloneHolder(pVarHolder, _val); } @@ -777,27 +771,27 @@ class VarHolderImpl: public VarHolder return _val; } - bool isArray() const + bool isArray() const override { return false; } - bool isInteger() const + bool isInteger() const override { return false; } - bool isSigned() const + bool isSigned() const override { return false; } - bool isNumeric() const + bool isNumeric() const override { return false; } - bool isString() const + bool isString() const override { return false; } diff --git a/JSON/include/Poco/JSON/ParseHandler.h b/JSON/include/Poco/JSON/ParseHandler.h index 80dda16b41..74c9ba9cea 100644 --- a/JSON/include/Poco/JSON/ParseHandler.h +++ b/JSON/include/Poco/JSON/ParseHandler.h @@ -40,61 +40,61 @@ class JSON_API ParseHandler: public Handler /// inside objects is preserved. Otherwise, items /// will be sorted by keys. - virtual ~ParseHandler(); + ~ParseHandler() override; /// Destroys the ParseHandler. - virtual void reset(); + void reset() override; /// Resets the handler state. - void startObject(); + void startObject() override; /// Handles a '{'; a new object is started. - void endObject(); + void endObject() override; /// Handles a '}'; the object is closed. - void startArray(); + void startArray() override; /// Handles a '['; a new array is started. - void endArray(); + void endArray() override; /// Handles a ']'; the array is closed. - void key(const std::string& k); + void key(const std::string& k) override; /// A key is read - Dynamic::Var asVar() const; + Dynamic::Var asVar() const override; /// Returns the result of the parser (an object or an array). - virtual void value(int v); + void value(int v) override; /// An integer value is read - virtual void value(unsigned v); + void value(unsigned v) override; /// An unsigned value is read. This will only be triggered if the /// value cannot fit into a signed int. #if defined(POCO_HAVE_INT64) - virtual void value(Int64 v); + void value(Int64 v) override; /// A 64-bit integer value is read - virtual void value(UInt64 v); + void value(UInt64 v) override; /// An unsigned 64-bit integer value is read. This will only be /// triggered if the value cannot fit into a signed 64-bit integer. #endif - virtual void value(const std::string& s); + void value(const std::string& s) override; /// A string value is read. - virtual void value(double d); + void value(double d) override; /// A double value is read. - virtual void value(bool b); + void value(bool b) override; /// A boolean value is read. - virtual void null(); + void null() override; /// A null value is read. private: void setValue(const Poco::Dynamic::Var& value); - typedef std::stack Stack; + using Stack = std::stack; Stack _stack; std::string _key; diff --git a/JSON/include/Poco/JSON/Parser.h b/JSON/include/Poco/JSON/Parser.h index 3e9707f3c3..6a175990e8 100644 --- a/JSON/include/Poco/JSON/Parser.h +++ b/JSON/include/Poco/JSON/Parser.h @@ -20,11 +20,7 @@ #include "Poco/JSON/JSON.h" #include "Poco/JSON/ParserImpl.h" -#include "Poco/JSON/Object.h" -#include "Poco/JSON/Array.h" #include "Poco/JSON/ParseHandler.h" -#include "Poco/JSON/JSONException.h" -#include "Poco/UTF8Encoding.h" #include "Poco/Dynamic/Var.h" #include @@ -68,7 +64,7 @@ class JSON_API Parser: private ParserImpl Parser(const Handler::Ptr& pHandler = new ParseHandler); /// Creates JSON Parser, using the given Handler and buffer size. - virtual ~Parser(); + ~Parser() override; /// Destroys JSON Parser. void reset(); diff --git a/JSON/include/Poco/JSON/ParserImpl.h b/JSON/include/Poco/JSON/ParserImpl.h index 5984b2cf6c..d9349126bb 100644 --- a/JSON/include/Poco/JSON/ParserImpl.h +++ b/JSON/include/Poco/JSON/ParserImpl.h @@ -19,11 +19,7 @@ #include "Poco/JSON/JSON.h" -#include "Poco/JSON/Object.h" -#include "Poco/JSON/Array.h" #include "Poco/JSON/ParseHandler.h" -#include "Poco/JSON/JSONException.h" -#include "Poco/UTF8Encoding.h" #include "Poco/Dynamic/Var.h" #include @@ -183,7 +179,7 @@ inline Dynamic::Var ParserImpl::asVarImpl() const { if (_pHandler) return _pHandler->asVar(); - return Dynamic::Var(); + return {}; } diff --git a/JSON/include/Poco/JSON/PrintHandler.h b/JSON/include/Poco/JSON/PrintHandler.h index 18d131c0f6..2bee734bd6 100644 --- a/JSON/include/Poco/JSON/PrintHandler.h +++ b/JSON/include/Poco/JSON/PrintHandler.h @@ -44,56 +44,56 @@ class JSON_API PrintHandler: public Handler PrintHandler(std::ostream& out, unsigned indent = 0, int options = Poco::JSON_WRAP_STRINGS); /// Creates the PrintHandler. - ~PrintHandler(); + ~PrintHandler() override; /// Destroys the PrintHandler. - void reset(); + void reset() override; /// Resets the handler state. - void startObject(); + void startObject() override; /// The parser has read a '{'; a new object is started. /// If indent is greater than zero, a newline will be appended. - void endObject(); + void endObject() override; /// The parser has read a '}'; the object is closed. - void startArray(); + void startArray() override; /// The parser has read a [; a new array will be started. /// If indent is greater than zero, a newline will be appended. - void endArray(); + void endArray() override; /// The parser has read a ]; the array is closed. - void key(const std::string& k); + void key(const std::string& k) override; /// A key of an object is read; it will be written to the output, /// followed by a ':'. If indent is greater than zero, the colon /// is padded by a space before and after. - void null(); + void null() override; /// A null value is read; "null" will be written to the output. - void value(int v); + void value(int v) override; /// An integer value is read. - void value(unsigned v); + void value(unsigned v) override; /// An unsigned value is read. This will only be triggered if the /// value cannot fit into a signed int. #if defined(POCO_HAVE_INT64) - void value(Int64 v); + void value(Int64 v) override; /// A 64-bit integer value is read; it will be written to the output. - void value(UInt64 v); + void value(UInt64 v) override; /// An unsigned 64-bit integer value is read; it will be written to the output. #endif - void value(const std::string& value); + void value(const std::string& value) override; /// A string value is read; it will be formatted and written to the output. - void value(double d); + void value(double d) override; /// A double value is read; it will be written to the output. - void value(bool b); + void value(bool b) override; /// A boolean value is read; it will be written to the output. void comma(); diff --git a/JSON/include/Poco/JSON/TemplateCache.h b/JSON/include/Poco/JSON/TemplateCache.h index 80a09b52a1..4fe29195f7 100644 --- a/JSON/include/Poco/JSON/TemplateCache.h +++ b/JSON/include/Poco/JSON/TemplateCache.h @@ -21,7 +21,6 @@ #include "Poco/JSON/JSON.h" #include "Poco/JSON/Template.h" #include "Poco/Path.h" -#include "Poco/SharedPtr.h" #include "Poco/Logger.h" #include #include diff --git a/JSON/samples/Benchmark/src/Benchmark.cpp b/JSON/samples/Benchmark/src/Benchmark.cpp index 0725ebb779..edb7ba6741 100644 --- a/JSON/samples/Benchmark/src/Benchmark.cpp +++ b/JSON/samples/Benchmark/src/Benchmark.cpp @@ -11,7 +11,7 @@ #include "Poco/JSON/Parser.h" -#include "Poco/JSON/ParseHandler.h" +#include "Poco/JSON/Object.h" #include "Poco/JSON/JSONException.h" #include "Poco/Environment.h" #include "Poco/Path.h" @@ -20,7 +20,7 @@ #include "Poco/StreamCopier.h" #include "Poco/Stopwatch.h" #include -#include +#include int main(int argc, char** argv) diff --git a/JSON/src/Array.cpp b/JSON/src/Array.cpp index 9b36e4830c..230153d275 100644 --- a/JSON/src/Array.cpp +++ b/JSON/src/Array.cpp @@ -42,14 +42,7 @@ Array::Array(int options): } -Array::Array(const Array& other) : - _values(other._values), - _pArray(other._pArray), - _modified(other._modified), - _escapeUnicode(other._escapeUnicode), - _lowercaseHex(other._lowercaseHex) -{ -} +Array::Array(const Array& other) = default; Array::Array(Array&& other) noexcept: @@ -88,9 +81,7 @@ Array& Array::operator = (Array&& other) noexcept } -Array::~Array() -{ -} +Array::~Array() = default; Var Array::get(unsigned int index) const @@ -176,7 +167,7 @@ void Array::stringify(std::ostream& out, unsigned int indent, int step) const if (indent > 0) out << std::endl; - for (ValueVec::const_iterator it = _values.begin(); it != _values.end();) + for (auto it = _values.begin(); it != _values.end();) { for (int i = 0; i < indent; i++) out << ' '; @@ -210,14 +201,14 @@ void Array::resetDynArray() const Array::operator const Poco::Dynamic::Array& () const { - if (!_values.size()) + if (_values.empty()) { resetDynArray(); } else if (_modified) { - ValueVec::const_iterator it = _values.begin(); - ValueVec::const_iterator end = _values.end(); + auto it = _values.begin(); + const auto end = _values.end(); resetDynArray(); int index = 0; for (; it != end; ++it, ++index) @@ -246,8 +237,8 @@ Poco::Dynamic::Array Array::makeArray(const JSON::Array::Ptr& arr) { Poco::Dynamic::Array vec; - JSON::Array::ConstIterator it = arr->begin(); - JSON::Array::ConstIterator end = arr->end(); + auto it = arr->begin(); + const auto end = arr->end(); int index = 0; for (; it != end; ++it, ++index) { @@ -274,7 +265,7 @@ Poco::Dynamic::Array Array::makeArray(const JSON::Array::Ptr& arr) void Array::clear() { _values.clear(); - _pArray = 0; + _pArray = nullptr; } diff --git a/JSON/src/Handler.cpp b/JSON/src/Handler.cpp index e207329ad3..0406ccf947 100644 --- a/JSON/src/Handler.cpp +++ b/JSON/src/Handler.cpp @@ -13,32 +13,27 @@ #include "Poco/JSON/Handler.h" -#include "Poco/JSON/Object.h" namespace Poco { namespace JSON { -Handler::Handler() -{ -} +Handler::Handler() = default; -Handler::~Handler() -{ -} +Handler::~Handler() = default; Dynamic::Var Handler::asVar() const { - return Dynamic::Var(); + return {}; } Poco::DynamicStruct Handler::asStruct() const { - return Poco::DynamicStruct(); + return {}; } diff --git a/JSON/src/Object.cpp b/JSON/src/Object.cpp index 57d70f9edd..d575d7dd8f 100644 --- a/JSON/src/Object.cpp +++ b/JSON/src/Object.cpp @@ -14,7 +14,6 @@ #include "Poco/JSON/Object.h" #include -#include using Poco::Dynamic::Var; @@ -43,11 +42,12 @@ Object::Object(int options): } -Object::Object(const Object& other) : _values(other._values), +Object::Object(const Object& other) : + _values(other._values), _preserveInsOrder(other._preserveInsOrder), _escapeUnicode(other._escapeUnicode), _lowercaseHex(other._lowercaseHex), - _pStruct(!other._modified ? other._pStruct : 0), + _pStruct(!other._modified ? other._pStruct : nullptr), _modified(other._modified) { syncKeys(other._keys); @@ -67,9 +67,7 @@ Object::Object(Object&& other) noexcept: } -Object::~Object() -{ -} +Object::~Object() = default; Object &Object::operator = (const Object &other) @@ -81,7 +79,7 @@ Object &Object::operator = (const Object &other) _preserveInsOrder = other._preserveInsOrder; _escapeUnicode = other._escapeUnicode; _lowercaseHex = other._lowercaseHex; - _pStruct = !other._modified ? other._pStruct : 0; + _pStruct = !other._modified ? other._pStruct : nullptr; _modified = other._modified; } return *this; @@ -108,11 +106,10 @@ void Object::syncKeys(const KeyList& keys) if(_preserveInsOrder) { // update iterators in _keys to point to copied _values - for(KeyList::const_iterator it = keys.begin(); it != keys.end(); ++it) - { - ValueMap::const_iterator itv = _values.find((*it)->first); - poco_assert (itv != _values.end()); - _keys.push_back(itv); + for (const auto& key : keys) { + auto itv = _values.find(key->first); + poco_assert(itv != _values.end()); + _keys.emplace_back(itv); } } } @@ -120,37 +117,37 @@ void Object::syncKeys(const KeyList& keys) Var Object::get(const std::string& key) const { - ValueMap::const_iterator it = _values.find(key); + auto it = _values.find(key); if (it != _values.end()) { return it->second; } - return Var(); + return {}; } Array::Ptr Object::getArray(const std::string& key) const { - ValueMap::const_iterator it = _values.find(key); + auto it = _values.find(key); if ((it != _values.end()) && (it->second.type() == typeid(Array::Ptr))) { return it->second.extract(); } - return 0; + return nullptr; } Object::Ptr Object::getObject(const std::string& key) const { - ValueMap::const_iterator it = _values.find(key); + auto it = _values.find(key); if ((it != _values.end()) && (it->second.type() == typeid(Object::Ptr))) { return it->second.extract(); } - return 0; + return nullptr; } @@ -159,16 +156,14 @@ void Object::getNames(NameList& names) const names.clear(); if (_preserveInsOrder) { - for(KeyList::const_iterator it = _keys.begin(); it != _keys.end(); ++it) - { - names.push_back((*it)->first); + for (const auto& _key : _keys) { + names.push_back(_key->first); } } else { - for(ValueMap::const_iterator it = _values.begin(); it != _values.end(); ++it) - { - names.push_back(it->first); + for (const auto& _value : _values) { + names.push_back(_value.first); } } } @@ -195,8 +190,8 @@ void Object::stringify(std::ostream& out, unsigned int indent, int step) const const std::string& Object::getKey(KeyList::const_iterator& iter) const { - ValueMap::const_iterator it = _values.begin(); - ValueMap::const_iterator end = _values.end(); + auto it = _values.begin(); + auto end = _values.end(); for (; it != end; ++it) { if (it == *iter) return it->first; @@ -212,13 +207,13 @@ Object& Object::set(const std::string& key, const Dynamic::Var& value) if (!ret.second) ret.first->second = value; if (_preserveInsOrder) { - KeyList::iterator it = _keys.begin(); - KeyList::iterator end = _keys.end(); + auto it = _keys.begin(); + const auto end = _keys.end(); for (; it != end; ++it) { if (key == (*it)->first) return *this; } - _keys.push_back(ret.first); + _keys.emplace_back(ret.first); } _modified = true; return *this; @@ -259,14 +254,14 @@ void Object::resetDynStruct() const Object::operator const Poco::DynamicStruct& () const { - if (!_values.size()) + if (_values.empty()) { resetDynStruct(_pStruct); } else if (_modified) { - ValueMap::const_iterator it = _values.begin(); - ValueMap::const_iterator end = _values.end(); + auto it = _values.begin(); + const auto end = _values.end(); resetDynStruct(_pStruct); for (; it != end; ++it) { @@ -291,7 +286,7 @@ Object::operator const Poco::DynamicStruct& () const Object::operator const Poco::OrderedDynamicStruct& () const { - if (!_values.size()) + if (_values.empty()) { resetDynStruct(_pOrdStruct); } @@ -299,8 +294,8 @@ Object::operator const Poco::OrderedDynamicStruct& () const { if (_preserveInsOrder) { - KeyList::const_iterator it = _keys.begin(); - KeyList::const_iterator end = _keys.end(); + auto it = _keys.begin(); + const auto end = _keys.end(); resetDynStruct(_pOrdStruct); for (; it != end; ++it) { @@ -320,8 +315,8 @@ Object::operator const Poco::OrderedDynamicStruct& () const } else { - ValueMap::const_iterator it = _values.begin(); - ValueMap::const_iterator end = _values.end(); + auto it = _values.begin(); + const auto end = _values.end(); resetDynStruct(_pOrdStruct); for (; it != end; ++it) { @@ -349,7 +344,7 @@ void Object::clear() { _values.clear(); _keys.clear(); - _pStruct = 0; + _pStruct = nullptr; _modified = true; } diff --git a/JSON/src/ParseHandler.cpp b/JSON/src/ParseHandler.cpp index 99de30c160..fdb2d995ec 100644 --- a/JSON/src/ParseHandler.cpp +++ b/JSON/src/ParseHandler.cpp @@ -30,9 +30,7 @@ ParseHandler::ParseHandler(bool preserveObjectOrder) : Handler(), } -ParseHandler::~ParseHandler() -{ -} +ParseHandler::~ParseHandler() = default; void ParseHandler::reset() @@ -67,7 +65,7 @@ void ParseHandler::startObject() } } - _stack.push(newObj); + _stack.emplace(newObj); } @@ -102,7 +100,7 @@ void ParseHandler::startArray() } } - _stack.push(newArr); + _stack.emplace(newArr); } @@ -120,7 +118,7 @@ void ParseHandler::key(const std::string& k) void ParseHandler::setValue(const Var& value) { - if (_stack.size()) + if (!_stack.empty()) { Var parent = _stack.top(); diff --git a/JSON/src/Parser.cpp b/JSON/src/Parser.cpp index 5da4985891..1dec9e823c 100644 --- a/JSON/src/Parser.cpp +++ b/JSON/src/Parser.cpp @@ -13,16 +13,9 @@ #include "Poco/JSON/Parser.h" -#include "Poco/JSON/JSONException.h" -#include "Poco/Ascii.h" -#include "Poco/Token.h" -#include "Poco/UTF8Encoding.h" -#include "Poco/String.h" #undef min #undef max -#include #include -#include namespace Poco { @@ -35,9 +28,7 @@ Parser::Parser(const Handler::Ptr& pHandler): } -Parser::~Parser() -{ -} +Parser::~Parser() = default; void Parser::setHandler(const Handler::Ptr& pHandler) diff --git a/JSON/src/ParserImpl.cpp b/JSON/src/ParserImpl.cpp index 4ec5b701e9..eae24f1e0d 100644 --- a/JSON/src/ParserImpl.cpp +++ b/JSON/src/ParserImpl.cpp @@ -11,23 +11,20 @@ // SPDX-License-Identifier: BSL-1.0 // +#include +#include +#include -#include "Poco/JSON/Parser.h" -#include "Poco/JSON/JSONException.h" -#include "Poco/Ascii.h" -#include "Poco/Token.h" -#include "Poco/UTF8Encoding.h" -#include "Poco/String.h" -#include "Poco/StreamCopier.h" #undef min #undef max -#include -#include + #include +#include +#include #include "pdjson.h" -typedef struct json_stream json_stream; +using json_stream = struct json_stream; namespace Poco { @@ -38,13 +35,13 @@ extern "C" { static int istream_get(void* ptr) { - std::streambuf* pBuf = reinterpret_cast(ptr); + auto pBuf = reinterpret_cast(ptr); return pBuf->sbumpc(); } static int istream_peek(void* ptr) { - std::streambuf* pBuf = reinterpret_cast(ptr); + auto pBuf = reinterpret_cast(ptr); return pBuf->sgetc(); } } @@ -167,8 +164,7 @@ void ParserImpl::stripComments(std::string& json) std::string::iterator it = json.begin(); for (; it != json.end();) { - if (*it == '"' && !inString) inString = true; - else inString = false; + inString = *it == '"' && !inString; if (!inString) { if (*it == '/' && it + 1 != json.end() && *(it + 1) == '*') @@ -220,7 +216,7 @@ void ParserImpl::handleObject() while (tok != JSON_OBJECT_END && checkError()) { json_next(_pJSON); - if (_pHandler) _pHandler->key(std::string(json_get_string(_pJSON, NULL))); + if (_pHandler) _pHandler->key(std::string(json_get_string(_pJSON, nullptr))); handle(); tok = json_peek(_pJSON); } @@ -252,7 +248,7 @@ void ParserImpl::handle() case JSON_NUMBER: if (_pHandler) { - std::string str(json_get_string(_pJSON, NULL)); + std::string str(json_get_string(_pJSON, nullptr)); if (str.find(_decimalPoint) != str.npos || str.find('e') != str.npos || str.find('E') != str.npos) { _pHandler->value(NumberParser::parseFloat(str)); diff --git a/JSON/src/PrintHandler.cpp b/JSON/src/PrintHandler.cpp index 2bce27008f..b17727677a 100644 --- a/JSON/src/PrintHandler.cpp +++ b/JSON/src/PrintHandler.cpp @@ -41,9 +41,7 @@ PrintHandler::PrintHandler(std::ostream& out, unsigned indent, int options): } -PrintHandler::~PrintHandler() -{ -} +PrintHandler::~PrintHandler() = default; void PrintHandler::reset() diff --git a/JSON/src/Query.cpp b/JSON/src/Query.cpp index 27e5ad8756..731681aaf1 100644 --- a/JSON/src/Query.cpp +++ b/JSON/src/Query.cpp @@ -37,9 +37,7 @@ Query::Query(const Var& source): _source(source) } -Query::~Query() -{ -} +Query::~Query() = default; Object::Ptr Query::findObject(const std::string& path) const @@ -51,7 +49,7 @@ Object::Ptr Query::findObject(const std::string& path) const else if (result.type() == typeid(Object)) return new Object(result.extract()); - return 0; + return nullptr; } @@ -79,7 +77,7 @@ Array::Ptr Query::findArray(const std::string& path) const else if (result.type() == typeid(Array)) return new Array(result.extract()); - return 0; + return nullptr; } @@ -150,7 +148,7 @@ Var Query::find(const std::string& path) const if (!result.isEmpty() && !indexes.empty()) { - for (auto i: indexes) + for (const auto& i: indexes) { if (result.type() == typeid(Array::Ptr)) { diff --git a/JSON/src/Stringifier.cpp b/JSON/src/Stringifier.cpp index 78ced39215..e1f37de2f5 100644 --- a/JSON/src/Stringifier.cpp +++ b/JSON/src/Stringifier.cpp @@ -15,7 +15,6 @@ #include "Poco/JSON/Stringifier.h" #include "Poco/JSON/Array.h" #include "Poco/JSON/Object.h" -#include using Poco::Dynamic::Var; @@ -34,28 +33,28 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde if (any.type() == typeid(Object)) { - Object& o = const_cast(any.extract()); + auto& o = const_cast(any.extract()); o.setEscapeUnicode(escapeUnicode); o.setLowercaseHex(lowercaseHex); o.stringify(out, indent == 0 ? 0 : indent, step); } else if (any.type() == typeid(Array)) { - Array& a = const_cast(any.extract()); + auto& a = const_cast(any.extract()); a.setEscapeUnicode(escapeUnicode); a.setLowercaseHex(lowercaseHex); a.stringify(out, indent == 0 ? 0 : indent, step); } else if (any.type() == typeid(Object::Ptr)) { - Object::Ptr& o = const_cast(any.extract()); + auto& o = const_cast(any.extract()); o->setEscapeUnicode(escapeUnicode); o->setLowercaseHex(lowercaseHex); o->stringify(out, indent == 0 ? 0 : indent, step); } else if (any.type() == typeid(Array::Ptr)) { - Array::Ptr& a = const_cast(any.extract()); + auto& a = const_cast(any.extract()); a->setEscapeUnicode(escapeUnicode); a->setLowercaseHex(lowercaseHex); a->stringify(out, indent == 0 ? 0 : indent, step); @@ -66,7 +65,7 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde } else if (any.isNumeric() || any.isBoolean()) { - std::string value = any.convert(); + auto value = any.convert(); if ((Poco::icompare(value, "nan") == 0) || (Poco::icompare(value, "inf") == 0)) value = "null"; if (any.type() == typeid(char)) formatString(value, out, options); @@ -74,7 +73,7 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde } else if (any.isString() || any.isDateTime() || any.isDate() || any.isTime()) { - std::string value = any.convert(); + auto value = any.convert(); formatString(value, out, options); } else diff --git a/JSON/src/Template.cpp b/JSON/src/Template.cpp index c452d6ee03..c9878a537d 100644 --- a/JSON/src/Template.cpp +++ b/JSON/src/Template.cpp @@ -32,17 +32,13 @@ POCO_IMPLEMENT_EXCEPTION(JSONTemplateException, Exception, "Template Exception") class Part { public: - Part() - { - } + Part() = default; - virtual ~Part() - { - } + virtual ~Part() = default; virtual void render(const Var& data, std::ostream& out) const = 0; - typedef std::vector> VectorParts; + using VectorParts = std::vector>; }; @@ -57,11 +53,9 @@ class StringPart: public Part { } - virtual ~StringPart() - { - } + ~StringPart() override = default; - void render(const Var& data, std::ostream& out) const + void render(const Var& data, std::ostream& out) const override { out << _content; } @@ -84,20 +78,16 @@ class StringPart: public Part class MultiPart: public Part { public: - MultiPart() - { - } + MultiPart() = default; - virtual ~MultiPart() - { - } + ~MultiPart() override = default; virtual void addPart(Part* part) { - _parts.push_back(part); + _parts.emplace_back(part); } - void render(const Var& data, std::ostream& out) const + void render(const Var& data, std::ostream& out) const override { for (const auto& p: _parts) { @@ -117,11 +107,9 @@ class EchoPart: public Part { } - virtual ~EchoPart() - { - } + ~EchoPart() override = default; - void render(const Var& data, std::ostream& out) const + void render(const Var& data, std::ostream& out) const override { Query query(data); Var value = query.find(_query); @@ -144,9 +132,7 @@ class LogicQuery { } - virtual ~LogicQuery() - { - } + virtual ~LogicQuery() = default; virtual bool apply(const Var& data) const { @@ -161,7 +147,7 @@ class LogicQuery // An empty string must result in false, otherwise true // Which is not the case when we convert to bool with Var { - std::string s = value.convert(); + auto s = value.convert(); logic = !s.empty(); } else @@ -188,11 +174,9 @@ class LogicExistQuery: public LogicQuery { } - virtual ~LogicExistQuery() - { - } + ~LogicExistQuery() override = default; - virtual bool apply(const Var& data) const + bool apply(const Var& data) const override { Query query(data); Var value = query.find(_queryString); @@ -209,11 +193,9 @@ class LogicElseQuery: public LogicQuery { } - virtual ~LogicElseQuery() - { - } + ~LogicElseQuery() override = default; - virtual bool apply(const Var& data) const + bool apply(const Var& data) const override { return true; } @@ -227,23 +209,21 @@ class LogicPart: public MultiPart { } - virtual ~LogicPart() - { - } + ~LogicPart() override = default; void addPart(LogicQuery* query, Part* part) { MultiPart::addPart(part); - _queries.push_back(query); + _queries.emplace_back(query); } - void addPart(Part* part) + void addPart(Part* part) override { MultiPart::addPart(part); _queries.push_back(new LogicElseQuery()); } - void render(const Var& data, std::ostream& out) const + void render(const Var& data, std::ostream& out) const override { int count = 0; for (auto it = _queries.begin(); it != _queries.end(); ++it, ++count) @@ -268,11 +248,9 @@ class LoopPart: public MultiPart { } - virtual ~LoopPart() - { - } + ~LoopPart() override = default; - void render(const Var& data, std::ostream& out) const + void render(const Var& data, std::ostream& out) const override { Query query(data); @@ -322,14 +300,12 @@ class IncludePart: public Part } } - virtual ~IncludePart() - { - } + ~IncludePart() override = default; - void render(const Var& data, std::ostream& out) const + void render(const Var& data, std::ostream& out) const override { TemplateCache* cache = TemplateCache::instance(); - if (cache == 0) + if (cache == nullptr) { Template tpl(_path); tpl.parse(); @@ -348,16 +324,16 @@ class IncludePart: public Part Template::Template(const Path& templatePath): - _parts(0), - _currentPart(0), + _parts(nullptr), + _currentPart(nullptr), _templatePath(templatePath) { } Template::Template(): - _parts(0), - _currentPart(0) + _parts(nullptr), + _currentPart(nullptr) { } @@ -430,24 +406,24 @@ void Template::parse(std::istream& in) } _partStack.push(_currentPart); - LoopPart* part = new LoopPart(loopVariable, query); + auto part = new LoopPart(loopVariable, query); _partStack.push(part); _currentPart->addPart(part); _currentPart = part; } else if (command.compare("else") == 0) { - if (_partStack.size() == 0) + if (_partStack.empty()) { throw JSONTemplateException("Unexpected found"); } _currentPart = _partStack.top(); - LogicPart* lp = dynamic_cast(_currentPart); - if (lp == 0) + auto lp = dynamic_cast(_currentPart); + if (lp == nullptr) { throw JSONTemplateException("Missing or for "); } - MultiPart* part = new MultiPart(); + auto part = new MultiPart(); lp->addPart(part); _currentPart = part; } @@ -459,18 +435,18 @@ void Template::parse(std::istream& in) throw JSONTemplateException("Missing query in "); } - if (_partStack.size() == 0) + if (_partStack.empty()) { throw JSONTemplateException("Unexpected found"); } _currentPart = _partStack.top(); - LogicPart* lp = dynamic_cast(_currentPart); - if (lp == 0) + auto lp = dynamic_cast(_currentPart); + if (lp == nullptr) { throw JSONTemplateException("Missing or for "); } - MultiPart* part = new MultiPart(); + auto part = new MultiPart(); lp->addPart(new LogicQuery(query), part); _currentPart = part; } @@ -481,8 +457,8 @@ void Template::parse(std::istream& in) throw JSONTemplateException("Unexpected found"); } MultiPart* loopPart = _partStack.top(); - LoopPart* lp = dynamic_cast(loopPart); - if (lp == 0) + auto lp = dynamic_cast(loopPart); + if (lp == nullptr) { throw JSONTemplateException("Missing command"); } @@ -498,8 +474,8 @@ void Template::parse(std::istream& in) } _currentPart = _partStack.top(); - LogicPart* lp = dynamic_cast(_currentPart); - if (lp == 0) + auto lp = dynamic_cast(_currentPart); + if (lp == nullptr) { throw JSONTemplateException("Missing or for "); } @@ -516,7 +492,7 @@ void Template::parse(std::istream& in) throw JSONTemplateException("Missing query in "); } _partStack.push(_currentPart); - LogicPart* lp = new LogicPart(); + auto lp = new LogicPart(); _partStack.push(lp); _currentPart->addPart(lp); _currentPart = new MultiPart(); @@ -590,7 +566,7 @@ std::string Template::readText(std::istream& in) break; } } - text += c; + text += static_cast(c); c = in.get(); } @@ -612,7 +588,7 @@ std::string Template::readTemplateCommand(std::istream& in) if (c == '?' && in.peek() == '>') { - in.putback(c); + in.putback(static_cast(c)); break; } @@ -622,7 +598,7 @@ std::string Template::readTemplateCommand(std::istream& in) break; } - command += c; + command += static_cast(c); c = in.get(); } @@ -638,7 +614,7 @@ std::string Template::readWord(std::istream& in) while ((c = in.peek()) != -1 && !Ascii::isSpace(c)) { in.get(); - word += c; + word += static_cast(c); } return word; } @@ -652,7 +628,7 @@ std::string Template::readQuery(std::istream& in) { if (c == '?' && in.peek() == '>') { - in.putback(c); + in.putback(static_cast(c)); break; } @@ -660,7 +636,7 @@ std::string Template::readQuery(std::istream& in) { break; } - word += c; + word += static_cast(c); } return word; } @@ -685,7 +661,7 @@ std::string Template::readString(std::istream& in) { while ((c = in.get()) != -1 && c != '"') { - str += c; + str += static_cast(c); } } return str; diff --git a/JSON/src/TemplateCache.cpp b/JSON/src/TemplateCache.cpp index bb5c7e2702..5e0ad03abc 100644 --- a/JSON/src/TemplateCache.cpp +++ b/JSON/src/TemplateCache.cpp @@ -20,10 +20,10 @@ namespace Poco { namespace JSON { -TemplateCache* TemplateCache::_pInstance = 0; +TemplateCache* TemplateCache::_pInstance = nullptr; -TemplateCache::TemplateCache(): _pLogger(0) +TemplateCache::TemplateCache(): _pLogger(nullptr) { setup(); } @@ -31,13 +31,13 @@ TemplateCache::TemplateCache(): _pLogger(0) TemplateCache::~TemplateCache() { - _pInstance = 0; + _pInstance = nullptr; } void TemplateCache::setup() { - poco_assert (_pInstance == 0); + poco_assert (_pInstance == nullptr); _pInstance = this; } @@ -61,7 +61,7 @@ Template::Ptr TemplateCache::getTemplate(const Path& path) Template::Ptr tpl; - std::map::iterator it = _cache.find(templatePathname); + auto it = _cache.find(templatePathname); if (it == _cache.end()) { if (templateFile.exists())