diff --git a/CppUnit/src/TestCase.cpp b/CppUnit/src/TestCase.cpp index c1e044b7847..eda37e2422a 100644 --- a/CppUnit/src/TestCase.cpp +++ b/CppUnit/src/TestCase.cpp @@ -81,14 +81,14 @@ void TestCase::assertEquals(const char* expected, const std::string& actual, lon void TestCase::assertNotNull(const void* pointer, const std::string& pointerExpression, long lineNumber, const std::string& fileName) { - if (pointer == NULL) + if (pointer == nullptr) throw CppUnitException(pointerExpression + " must not be NULL", lineNumber, fileName); } void TestCase::assertNull(const void* pointer, const std::string& pointerExpression, long lineNumber, const std::string& fileName) { - if (pointer != NULL) + if (pointer != nullptr) throw CppUnitException(pointerExpression + " must be NULL", lineNumber, fileName); } diff --git a/CppUnit/src/TextTestResult.cpp b/CppUnit/src/TextTestResult.cpp index f70ed82bf08..ad6b5d922ab 100644 --- a/CppUnit/src/TextTestResult.cpp +++ b/CppUnit/src/TextTestResult.cpp @@ -162,19 +162,18 @@ void TextTestResult::printErrors(std::ostream& stream) stream << "There were " << testErrors() << " errors: " << std::endl; int i = 1; - for (std::vector::iterator it = errors().begin(); it != errors().end(); ++it) + for (const auto& failure : errors()) { - TestFailure* failure = *it; CppUnitException* e = failure->thrownException(); stream << std::setw(2) << i << ": " << failure->failedTest()->toString() << "\n" - << " \"" << (e ? e->what() : "") << "\"\n" + << " \"" << (e ? e->what() : "") << "\"\n" << " in \"" << (e ? e->fileName() : std::string()) << "\", line "; - if (e == 0) + if (e == nullptr) { stream << "0"; } @@ -210,10 +209,9 @@ void TextTestResult::printFailures(std::ostream& stream) int i = 1; - for (std::vector::iterator it = failures().begin(); it != failures().end(); ++it) + for (const auto& failure : failures()) { - TestFailure* failure = *it; - CppUnitException* e = failure->thrownException(); + CppUnitException* e = failure->thrownException(); stream << std::setw(2) << i << ": " @@ -222,7 +220,7 @@ void TextTestResult::printFailures(std::ostream& stream) << " in \"" << (e ? e->fileName() : std::string()) << "\", line "; - if (e == 0) + if (e == nullptr) { stream << "0"; } diff --git a/Foundation/include/Poco/ClassLibrary.h b/Foundation/include/Poco/ClassLibrary.h index e10dbcbfb1b..a980c104b30 100644 --- a/Foundation/include/Poco/ClassLibrary.h +++ b/Foundation/include/Poco/ClassLibrary.h @@ -67,10 +67,10 @@ extern "C" \ #define POCO_BEGIN_MANIFEST_IMPL(fnName, base) \ bool fnName(Poco::ManifestBase* pManifest_) \ { \ - typedef base _Base; \ - typedef Poco::Manifest<_Base> _Manifest; \ - std::string requiredType(typeid(_Manifest).name()); \ - std::string actualType(pManifest_->className()); \ + using _Base = base; \ + using _Manifest = Poco::Manifest<_Base>; \ + const std::string requiredType(typeid(_Manifest).name()); \ + const std::string actualType(pManifest_->className()); \ if (requiredType == actualType) \ { \ Poco::Manifest<_Base>* pManifest = static_cast<_Manifest*>(pManifest_); diff --git a/Foundation/include/Poco/ClassLoader.h b/Foundation/include/Poco/ClassLoader.h index a55c63fdcb4..4a49c251481 100644 --- a/Foundation/include/Poco/ClassLoader.h +++ b/Foundation/include/Poco/ClassLoader.h @@ -254,7 +254,7 @@ class ClassLoader if (itm != pManif->end()) return *itm; } - return 0; + return nullptr; } const Meta& classFor(const std::string& className) const diff --git a/Foundation/include/Poco/Dynamic/Var.h b/Foundation/include/Poco/Dynamic/Var.h index 7ec04f45c52..eb8364a6abd 100644 --- a/Foundation/include/Poco/Dynamic/Var.h +++ b/Foundation/include/Poco/Dynamic/Var.h @@ -210,7 +210,7 @@ class Foundation_API Var if (pHolder && pHolder->type() == typeid(T)) { - VarHolderImpl* pHolderImpl = static_cast*>(pHolder); + auto* pHolderImpl = static_cast*>(pHolder); return pHolderImpl->value(); } else if (!pHolder) @@ -733,7 +733,7 @@ inline bool Var::operator ! () const inline bool Var::isEmpty() const { - return 0 == content(); + return nullptr == content(); } diff --git a/Foundation/include/Poco/Dynamic/VarHolder.h b/Foundation/include/Poco/Dynamic/VarHolder.h index d883e9146a2..84294655f8c 100644 --- a/Foundation/include/Poco/Dynamic/VarHolder.h +++ b/Foundation/include/Poco/Dynamic/VarHolder.h @@ -131,12 +131,12 @@ class Foundation_API VarHolder /// throw BadCastException. { public: - typedef Var ArrayValueType; + using ArrayValueType = Var; virtual ~VarHolder(); /// Destroys the VarHolder. - virtual VarHolder* clone(Placeholder* pHolder = 0) const = 0; + virtual VarHolder* clone(Placeholder* pHolder = nullptr) const = 0; /// Implementation must implement this function to /// deep-copy the VarHolder. /// If small object optimization is enabled (i.e. if @@ -323,17 +323,17 @@ class Foundation_API VarHolder } template ::value && std::is_signed::value) || - std::is_floating_point::value, F>::type* = nullptr, - typename std::enable_if<(std::is_integral::value && std::is_signed::value) || - std::is_floating_point::value, T>::type* = nullptr> + std::enable_if_t<(std::is_integral_v && std::is_signed_v) || + std::is_floating_point_v, F>* = nullptr, + std::enable_if_t<(std::is_integral_v && std::is_signed_v) || + std::is_floating_point_v, T>* = nullptr> static void convertToSmaller(const F& from, T& to) /// Converts signed integral, as well as floating-point, values from /// larger to smaller type. It checks the upper and lower bound and /// if from value is within limits of type T (i.e. check calls do not throw), /// it is converted. { - if constexpr((std::is_integral::value) && (std::is_floating_point::value)) + if constexpr((std::is_integral_v) && (std::is_floating_point_v)) { if (isPrecisionLost(from)) POCO_VAR_RANGE_EXCEPTION ("Lost precision", from); @@ -344,8 +344,8 @@ class Foundation_API VarHolder } template ::value && std::is_signed::value, F>::type* = nullptr, - typename std::enable_if::value, T>::type* = nullptr> + std::enable_if_t && std::is_signed_v, F>* = nullptr, + std::enable_if_t, T>* = nullptr> static void convertToSmaller(const F& from, T& to) /// Converts signed integral values from integral to floating-point type. Checks for /// the loss of precision and if from value is within limits of type T (i.e. check calls do not throw), @@ -357,8 +357,8 @@ class Foundation_API VarHolder } template ::value>::type* = nullptr, - typename std::enable_if::value, T>::type* = nullptr> + std::enable_if_t>* = nullptr, + std::enable_if_t, T>* = nullptr> static void convertToSmaller(const F& from, T& to) /// Converts boolean values to floating-point type. { @@ -366,8 +366,8 @@ class Foundation_API VarHolder } template ::value && !std::is_signed::value, F>::type* = nullptr, - typename std::enable_if<(std::is_integral::value && !std::is_signed::value) || std::is_floating_point::value, T>::type* = nullptr> + std::enable_if_t && !std::is_signed_v, F>* = nullptr, + std::enable_if_t<(std::is_integral_v && !std::is_signed::value) || std::is_floating_point::value, T>* = nullptr> static void convertToSmallerUnsigned(const F& from, T& to) /// Converts unsigned integral data types from larger to smaller, as well as to floating-point, types. /// Since lower limit is always 0 for unsigned types, only the upper limit is checked, thus @@ -380,8 +380,8 @@ class Foundation_API VarHolder } template ::value && std::is_signed::value, F>::type* = nullptr, - typename std::enable_if::value && !std::is_signed::value, T>::type* = nullptr> + std::enable_if_t && std::is_signed_v, F>* = nullptr, + std::enable_if_t && !std::is_signed_v, T>* = nullptr> static void convertSignedToUnsigned(const F& from, T& to) /// Converts signed integral data types to unsigned data types. /// Negative values can not be converted and if one is encountered, RangeException is thrown. @@ -393,8 +393,8 @@ class Foundation_API VarHolder to = static_cast(from); } - template ::value, bool> = true, - typename std::enable_if::value && !std::is_signed::value, T>::type* = nullptr> + template , bool> = true, + std::enable_if_t && !std::is_signed_v, T>* = nullptr> static void convertSignedFloatToUnsigned(const F& from, T& to) /// Converts floating point data types to unsigned integral data types. Negative values /// can not be converted and if one is encountered, RangeException is thrown. @@ -407,8 +407,8 @@ class Foundation_API VarHolder } template ::value && !std::is_signed::value, F>::type* = nullptr, - typename std::enable_if::value && std::is_signed::value, T>::type* = nullptr> + std::enable_if_t && !std::is_signed_v, F>* = nullptr, + std::enable_if_t && std::is_signed_v, T>* = nullptr> static void convertUnsignedToSigned(const F& from, T& to) /// Converts unsigned integral data types to signed integral data types. /// If upper limit is within the target data type limits, the conversion is performed. @@ -418,8 +418,8 @@ class Foundation_API VarHolder } template ::value, bool> = true, - std::enable_if_t::value, bool> = true> + std::enable_if_t, bool> = true, + std::enable_if_t, bool> = true> static void convertToFP(F& from, T& to) /// Converts unsigned integral data types to floating-point data types. /// If the number of significant digits used for the integer vaue exceeds the number @@ -433,7 +433,7 @@ class Foundation_API VarHolder private: - template ::value, bool> = true> + template , bool> = true> static constexpr int numValDigits(const T& value) { using U = std::make_unsigned_t; @@ -444,58 +444,58 @@ class Foundation_API VarHolder return digitCount; } - template ::value, bool> = true> + template , bool> = true> static constexpr int numValDigits(T value) { return numValDigits(static_cast(value)); } - template ::value, bool> = true> + template , bool> = true> static constexpr int numTypeDigits() { return std::numeric_limits::digits; } - template ::value, bool> = true> + template , bool> = true> static constexpr int numTypeDigits() { return numValDigits(std::numeric_limits::max()); } template ::value, bool> = true, - std::enable_if_t::value, bool> = true> + std::enable_if_t, bool> = true, + std::enable_if_t, bool> = true> static bool isPrecisionLost(const F& from) // Checks for loss of precision in integral -> floating point conversion. { return numValDigits(from) > numTypeDigits(); } - template ::value, bool> = true> + template , bool> = true> static void checkUpperLimit(const F& from) { if (from > static_cast(std::numeric_limits::max())) POCO_VAR_RANGE_EXCEPTION ("Value too big", from); } - template ::value, bool> = true> + template , bool> = true> static void checkLowerLimit(const F& from) { if (from < static_cast(std::numeric_limits::min())) POCO_VAR_RANGE_EXCEPTION ("Value too small", from); } - template ::value, bool> = true> + template , bool> = true> static void checkUpperLimit(const F& from) { if ((from > static_cast(std::numeric_limits::max()))) POCO_VAR_RANGE_EXCEPTION ("Value too big", from); } - template ::value, bool> = true> + template , bool> = true> static void checkLowerLimit(const F& from) { - if constexpr(std::is_floating_point::value) + if constexpr(std::is_floating_point_v) { if (static_cast(-std::numeric_limits::max()) > from) POCO_VAR_RANGE_EXCEPTION ("Value too small", from); @@ -4378,10 +4378,10 @@ class VarHolderImpl: public VarHolder }; -typedef std::vector Vector; -typedef std::deque Deque; -typedef std::list List; -typedef Vector Array; +using Vector = std::vector; +using Deque = std::deque; +using List = std::list; +using Array = Vector; } } // namespace Poco::Dynamic diff --git a/Foundation/include/Poco/Thread_POSIX.h b/Foundation/include/Poco/Thread_POSIX.h index 2bccbfed763..5f64ac2ed1f 100644 --- a/Foundation/include/Poco/Thread_POSIX.h +++ b/Foundation/include/Poco/Thread_POSIX.h @@ -19,6 +19,7 @@ #include "Poco/Foundation.h" +#include "Poco/Mutex.h" #include "Poco/Runnable.h" #include "Poco/SignalHandler.h" #include "Poco/Event.h" @@ -31,7 +32,6 @@ #if !defined(POCO_NO_SYS_SELECT_H) #include #endif -#include #if defined(POCO_VXWORKS) #include #endif @@ -41,8 +41,8 @@ namespace Poco { class Foundation_API ThreadImpl { public: - typedef pthread_t TIDImpl; - typedef void (*Callable)(void*); + using TIDImpl = pthread_t; + using Callable = void (*)(void *); enum Priority { @@ -99,7 +99,7 @@ class Foundation_API ThreadImpl public: CurrentThreadHolder() { - if (pthread_key_create(&_key, NULL)) + if (pthread_key_create(&_key, nullptr)) throw SystemException("cannot allocate thread context key"); } ~CurrentThreadHolder() diff --git a/Foundation/src/ActiveThreadPool.cpp b/Foundation/src/ActiveThreadPool.cpp index 3d052476b15..91a6099d89c 100644 --- a/Foundation/src/ActiveThreadPool.cpp +++ b/Foundation/src/ActiveThreadPool.cpp @@ -20,7 +20,6 @@ #include "Poco/ErrorHandler.h" #include "Poco/NotificationQueue.h" #include -#include #include namespace Poco { diff --git a/Foundation/src/Event.cpp b/Foundation/src/Event.cpp index 58b0f5f4d6b..8a56727ffb7 100644 --- a/Foundation/src/Event.cpp +++ b/Foundation/src/Event.cpp @@ -37,9 +37,7 @@ Event::Event(bool autoReset): EventImpl(autoReset) } -Event::~Event() -{ -} +Event::~Event() = default; } // namespace Poco diff --git a/Foundation/src/Thread.cpp b/Foundation/src/Thread.cpp index c7e3ac5c2b7..893f6784619 100644 --- a/Foundation/src/Thread.cpp +++ b/Foundation/src/Thread.cpp @@ -66,11 +66,9 @@ class CallableHolder: public Runnable { } - ~CallableHolder() - { - } + ~CallableHolder() override = default; - void run() + void run() override { _callable(_pData); } @@ -190,7 +188,7 @@ void Thread::clearTLS() if (_pTLS) { delete _pTLS; - _pTLS = 0; + _pTLS = nullptr; } } diff --git a/Foundation/src/ThreadPool.cpp b/Foundation/src/ThreadPool.cpp index 1c17c334f58..757e71acce7 100644 --- a/Foundation/src/ThreadPool.cpp +++ b/Foundation/src/ThreadPool.cpp @@ -39,7 +39,7 @@ class PooledThread: public Runnable void join(); void activate(); void release(); - void run(); + void run() override; private: volatile bool _idle; @@ -57,14 +57,14 @@ class PooledThread: public Runnable PooledThread::PooledThread(const std::string& name, int stackSize): _idle(true), _idleTime(0), - _pTarget(0), + _pTarget(nullptr), _name(name), _thread(name), _targetCompleted(Event::EVENT_MANUALRESET) { poco_assert_dbg (stackSize >= 0); _thread.setStackSize(stackSize); - _idleTime = std::time(NULL); + _idleTime = std::time(nullptr); } @@ -84,7 +84,7 @@ void PooledThread::start(Thread::Priority priority, Runnable& target) { FastMutex::ScopedLock lock(_mutex); - poco_assert (_pTarget == 0); + poco_assert (_pTarget == nullptr); _pTarget = ⌖ _thread.setPriority(priority); @@ -110,7 +110,7 @@ void PooledThread::start(Thread::Priority priority, Runnable& target, const std: _thread.setName(fullName); _thread.setPriority(priority); - poco_assert (_pTarget == 0); + poco_assert (_pTarget == nullptr); _pTarget = ⌖ _targetReady.set(); @@ -128,7 +128,7 @@ int PooledThread::idleTime() { FastMutex::ScopedLock lock(_mutex); - return (int) (time(NULL) - _idleTime); + return (int) (time(nullptr) - _idleTime); } @@ -157,7 +157,7 @@ void PooledThread::release() const long JOIN_TIMEOUT = 10000; _mutex.lock(); - _pTarget = 0; + _pTarget = nullptr; _mutex.unlock(); // In case of a statically allocated thread pool (such // as the default thread pool), Windows may have already @@ -200,8 +200,8 @@ void PooledThread::run() ErrorHandler::handle(); } FastMutex::ScopedLock lock(_mutex); - _pTarget = 0; - _idleTime = time(NULL); + _pTarget = nullptr; + _idleTime = time(nullptr); _idle = true; _targetCompleted.set(); ThreadLocalStorage::clear(); @@ -430,8 +430,8 @@ PooledThread* ThreadPool::getThread() if (++_age == 32) housekeep(); - PooledThread* pThread = 0; - for (ThreadVec::iterator it = _threads.begin(); !pThread && it != _threads.end(); ++it) + PooledThread* pThread = nullptr; + for (auto it = _threads.begin(); !pThread && it != _threads.end(); ++it) { if ((*it)->idle()) pThread = *it; @@ -472,7 +472,7 @@ class ThreadPoolSingletonHolder public: ThreadPoolSingletonHolder() { - _pPool = 0; + _pPool = nullptr; } ~ThreadPoolSingletonHolder() { diff --git a/Foundation/src/Thread_POSIX.cpp b/Foundation/src/Thread_POSIX.cpp index 11fdc137678..0f8bcebdcc3 100644 --- a/Foundation/src/Thread_POSIX.cpp +++ b/Foundation/src/Thread_POSIX.cpp @@ -17,8 +17,6 @@ #include "Poco/Exception.h" #include "Poco/Error.h" #include "Poco/ErrorHandler.h" -#include "Poco/Timespan.h" -#include "Poco/Timestamp.h" #include "Poco/Format.h" #include "Poco/Error.h" #include diff --git a/Foundation/testsuite/src/ClassLoaderTest.cpp b/Foundation/testsuite/src/ClassLoaderTest.cpp index 45bafbecdd0..094cbeb48f9 100644 --- a/Foundation/testsuite/src/ClassLoaderTest.cpp +++ b/Foundation/testsuite/src/ClassLoaderTest.cpp @@ -39,6 +39,11 @@ ClassLoaderTest::~ClassLoaderTest() { } +namespace Poco { + +template class ClassLoader; + +} void ClassLoaderTest::testClassLoader1() { @@ -126,7 +131,7 @@ void ClassLoaderTest::testClassLoader2() TestPlugin& POCO_UNUSED plgB = cl.instance("PluginB"); fail("not a singleton - must throw"); } - catch (InvalidAccessException&) + catch (const Poco::InvalidAccessException&) { } @@ -135,7 +140,7 @@ void ClassLoaderTest::testClassLoader2() TestPlugin* POCO_UNUSED pPluginC = cl.create("PluginC"); fail("cannot create a singleton - must throw"); } - catch (InvalidAccessException&) + catch (const Poco::InvalidAccessException&) { } @@ -145,7 +150,7 @@ void ClassLoaderTest::testClassLoader2() meta.autoDelete(&(meta.instance())); fail("cannot take ownership of a singleton - must throw"); } - catch (InvalidAccessException&) + catch (const Poco::InvalidAccessException&) { }