Skip to content

Commit

Permalink
enh: Code improvements done while resolving deprecated functionality (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
matejk committed May 10, 2024
1 parent d744d07 commit bc4b50a
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 83 deletions.
4 changes: 2 additions & 2 deletions CppUnit/src/TestCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 6 additions & 8 deletions CppUnit/src/TextTestResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,18 @@ void TextTestResult::printErrors(std::ostream& stream)
stream << "There were " << testErrors() << " errors: " << std::endl;

int i = 1;
for (std::vector<TestFailure*>::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";
}
Expand Down Expand Up @@ -210,10 +209,9 @@ void TextTestResult::printFailures(std::ostream& stream)

int i = 1;

for (std::vector<TestFailure*>::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
<< ": "
Expand All @@ -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";
}
Expand Down
8 changes: 4 additions & 4 deletions Foundation/include/Poco/ClassLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand Down
2 changes: 1 addition & 1 deletion Foundation/include/Poco/ClassLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class ClassLoader
if (itm != pManif->end())
return *itm;
}
return 0;
return nullptr;
}

const Meta& classFor(const std::string& className) const
Expand Down
4 changes: 2 additions & 2 deletions Foundation/include/Poco/Dynamic/Var.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Foundation_API Var

if (pHolder && pHolder->type() == typeid(T))
{
VarHolderImpl<T>* pHolderImpl = static_cast<VarHolderImpl<T>*>(pHolder);
auto* pHolderImpl = static_cast<VarHolderImpl<T>*>(pHolder);
return pHolderImpl->value();
}
else if (!pHolder)
Expand Down Expand Up @@ -733,7 +733,7 @@ inline bool Var::operator ! () const

inline bool Var::isEmpty() const
{
return 0 == content();
return nullptr == content();
}


Expand Down
72 changes: 36 additions & 36 deletions Foundation/include/Poco/Dynamic/VarHolder.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<VarHolder>* pHolder = 0) const = 0;
virtual VarHolder* clone(Placeholder<VarHolder>* pHolder = nullptr) const = 0;
/// Implementation must implement this function to
/// deep-copy the VarHolder.
/// If small object optimization is enabled (i.e. if
Expand Down Expand Up @@ -323,17 +323,17 @@ class Foundation_API VarHolder
}

template <typename F, typename T,
typename std::enable_if<(std::is_integral<F>::value && std::is_signed<F>::value) ||
std::is_floating_point<F>::value, F>::type* = nullptr,
typename std::enable_if<(std::is_integral<T>::value && std::is_signed<T>::value) ||
std::is_floating_point<F>::value, T>::type* = nullptr>
std::enable_if_t<(std::is_integral_v<F> && std::is_signed_v<F>) ||
std::is_floating_point_v<F>, F>* = nullptr,
std::enable_if_t<(std::is_integral_v<T> && std::is_signed_v<T>) ||
std::is_floating_point_v<F>, 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<F>::value) && (std::is_floating_point<T>::value))
if constexpr((std::is_integral_v<F>) && (std::is_floating_point_v<T>))
{
if (isPrecisionLost<F, T>(from))
POCO_VAR_RANGE_EXCEPTION ("Lost precision", from);
Expand All @@ -344,8 +344,8 @@ class Foundation_API VarHolder
}

template <typename F, typename T,
typename std::enable_if<std::is_integral<F>::value && std::is_signed<T>::value, F>::type* = nullptr,
typename std::enable_if<std::is_floating_point<T>::value, T>::type* = nullptr>
std::enable_if_t<std::is_integral_v<F> && std::is_signed_v<T>, F>* = nullptr,
std::enable_if_t<std::is_floating_point_v<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),
Expand All @@ -357,17 +357,17 @@ class Foundation_API VarHolder
}

template <typename F, typename T,
typename std::enable_if<std::is_same<F, bool>::value>::type* = nullptr,
typename std::enable_if<std::is_floating_point<T>::value, T>::type* = nullptr>
std::enable_if_t<std::is_same_v<F, bool>>* = nullptr,
std::enable_if_t<std::is_floating_point_v<T>, T>* = nullptr>
static void convertToSmaller(const F& from, T& to)
/// Converts boolean values to floating-point type.
{
to = static_cast<T>(from);
}

template <typename F, typename T,
typename std::enable_if<std::is_integral<F>::value && !std::is_signed<F>::value, F>::type* = nullptr,
typename std::enable_if<(std::is_integral<T>::value && !std::is_signed<T>::value) || std::is_floating_point<T>::value, T>::type* = nullptr>
std::enable_if_t<std::is_integral_v<F> && !std::is_signed_v<F>, F>* = nullptr,
std::enable_if_t<(std::is_integral_v<T> && !std::is_signed<T>::value) || std::is_floating_point<T>::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
Expand All @@ -380,8 +380,8 @@ class Foundation_API VarHolder
}

template <typename F, typename T,
typename std::enable_if<std::is_integral<F>::value && std::is_signed<F>::value, F>::type* = nullptr,
typename std::enable_if<std::is_integral<T>::value && !std::is_signed<T>::value, T>::type* = nullptr>
std::enable_if_t<std::is_integral_v<F> && std::is_signed_v<F>, F>* = nullptr,
std::enable_if_t<std::is_integral_v<T> && !std::is_signed_v<T>, 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.
Expand All @@ -393,8 +393,8 @@ class Foundation_API VarHolder
to = static_cast<T>(from);
}

template <typename F, typename T, std::enable_if_t<std::is_floating_point<F>::value, bool> = true,
typename std::enable_if<std::is_integral<T>::value && !std::is_signed<T>::value, T>::type* = nullptr>
template <typename F, typename T, std::enable_if_t<std::is_floating_point_v<F>, bool> = true,
std::enable_if_t<std::is_integral_v<T> && !std::is_signed_v<T>, 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.
Expand All @@ -407,8 +407,8 @@ class Foundation_API VarHolder
}

template <typename F, typename T,
typename std::enable_if<std::is_integral<F>::value && !std::is_signed<F>::value, F>::type* = nullptr,
typename std::enable_if<std::is_integral<T>::value && std::is_signed<T>::value, T>::type* = nullptr>
std::enable_if_t<std::is_integral_v<F> && !std::is_signed_v<F>, F>* = nullptr,
std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>, 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.
Expand All @@ -418,8 +418,8 @@ class Foundation_API VarHolder
}

template <typename F, typename T,
std::enable_if_t<std::is_integral<F>::value, bool> = true,
std::enable_if_t<std::is_floating_point<T>::value, bool> = true>
std::enable_if_t<std::is_integral_v<F>, bool> = true,
std::enable_if_t<std::is_floating_point_v<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
Expand All @@ -433,7 +433,7 @@ class Foundation_API VarHolder

private:

template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
static constexpr int numValDigits(const T& value)
{
using U = std::make_unsigned_t<T>;
Expand All @@ -444,58 +444,58 @@ class Foundation_API VarHolder
return digitCount;
}

template <typename T, std::enable_if_t<std::is_floating_point<T>::value, bool> = true>
template <typename T, std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
static constexpr int numValDigits(T value)
{
return numValDigits<int64_t>(static_cast<int64_t>(value));
}

template <typename T, std::enable_if_t<std::is_floating_point<T>::value, bool> = true>
template <typename T, std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
static constexpr int numTypeDigits()
{
return std::numeric_limits<T>::digits;
}

template <typename T, std::enable_if_t<std::is_integral<T>::value, bool> = true>
template <typename T, std::enable_if_t<std::is_integral_v<T>, bool> = true>
static constexpr int numTypeDigits()
{
return numValDigits(std::numeric_limits<T>::max());
}

template <typename F, typename T,
std::enable_if_t<std::is_integral<F>::value, bool> = true,
std::enable_if_t<std::is_floating_point<T>::value, bool> = true>
std::enable_if_t<std::is_integral_v<F>, bool> = true,
std::enable_if_t<std::is_floating_point_v<T>, bool> = true>
static bool isPrecisionLost(const F& from)
// Checks for loss of precision in integral -> floating point conversion.
{
return numValDigits(from) > numTypeDigits<T>();
}

template <typename F, typename T, std::enable_if_t<std::is_integral<F>::value, bool> = true>
template <typename F, typename T, std::enable_if_t<std::is_integral_v<F>, bool> = true>
static void checkUpperLimit(const F& from)
{
if (from > static_cast<F>(std::numeric_limits<T>::max()))
POCO_VAR_RANGE_EXCEPTION ("Value too big", from);
}

template <typename F, typename T, std::enable_if_t<std::is_integral<F>::value, bool> = true>
template <typename F, typename T, std::enable_if_t<std::is_integral_v<F>, bool> = true>
static void checkLowerLimit(const F& from)
{
if (from < static_cast<F>(std::numeric_limits<T>::min()))
POCO_VAR_RANGE_EXCEPTION ("Value too small", from);
}

template <typename F, typename T, std::enable_if_t<std::is_floating_point<F>::value, bool> = true>
template <typename F, typename T, std::enable_if_t<std::is_floating_point_v<F>, bool> = true>
static void checkUpperLimit(const F& from)
{
if ((from > static_cast<F>(std::numeric_limits<T>::max())))
POCO_VAR_RANGE_EXCEPTION ("Value too big", from);
}

template <typename F, typename T, std::enable_if_t<std::is_floating_point<F>::value, bool> = true>
template <typename F, typename T, std::enable_if_t<std::is_floating_point_v<F>, bool> = true>
static void checkLowerLimit(const F& from)
{
if constexpr(std::is_floating_point<T>::value)
if constexpr(std::is_floating_point_v<T>)
{
if (static_cast<F>(-std::numeric_limits<T>::max()) > from)
POCO_VAR_RANGE_EXCEPTION ("Value too small", from);
Expand Down Expand Up @@ -4378,10 +4378,10 @@ class VarHolderImpl<UUID>: public VarHolder
};


typedef std::vector<Var> Vector;
typedef std::deque<Var> Deque;
typedef std::list<Var> List;
typedef Vector Array;
using Vector = std::vector<Var>;
using Deque = std::deque<Var>;
using List = std::list<Var>;
using Array = Vector;


} } // namespace Poco::Dynamic
Expand Down
8 changes: 4 additions & 4 deletions Foundation/include/Poco/Thread_POSIX.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


#include "Poco/Foundation.h"
#include "Poco/Mutex.h"
#include "Poco/Runnable.h"
#include "Poco/SignalHandler.h"
#include "Poco/Event.h"
Expand All @@ -31,7 +32,6 @@
#if !defined(POCO_NO_SYS_SELECT_H)
#include <sys/select.h>
#endif
#include <errno.h>
#if defined(POCO_VXWORKS)
#include <cstring>
#endif
Expand All @@ -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
{
Expand Down Expand Up @@ -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()
Expand Down
1 change: 0 additions & 1 deletion Foundation/src/ActiveThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include "Poco/ErrorHandler.h"
#include "Poco/NotificationQueue.h"
#include <sstream>
#include <ctime>
#include <utility>

namespace Poco {
Expand Down
4 changes: 1 addition & 3 deletions Foundation/src/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ Event::Event(bool autoReset): EventImpl(autoReset)
}


Event::~Event()
{
}
Event::~Event() = default;


} // namespace Poco
8 changes: 3 additions & 5 deletions Foundation/src/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ class CallableHolder: public Runnable
{
}

~CallableHolder()
{
}
~CallableHolder() override = default;

void run()
void run() override
{
_callable(_pData);
}
Expand Down Expand Up @@ -190,7 +188,7 @@ void Thread::clearTLS()
if (_pTLS)
{
delete _pTLS;
_pTLS = 0;
_pTLS = nullptr;
}
}

Expand Down
Loading

0 comments on commit bc4b50a

Please sign in to comment.