Fix warnings

This commit is contained in:
Martchus 2021-03-19 23:09:01 +01:00
parent d38a9bb776
commit 8c033ca243
16 changed files with 147 additions and 127 deletions

View File

@ -416,29 +416,29 @@ std::uint64_t DateTime::timeToTicks(int hour, int minute, int second, double mil
*/ */
int DateTime::getDatePart(DatePart part) const int DateTime::getDatePart(DatePart part) const
{ {
const int fullDays = m_ticks / TimeSpan::ticksPerDay; const auto fullDays = static_cast<int>(m_ticks / TimeSpan::ticksPerDay);
const int full400YearBlocks = fullDays / m_daysPer400Years; const auto full400YearBlocks = fullDays / m_daysPer400Years;
const int daysMinusFull400YearBlocks = fullDays - full400YearBlocks * m_daysPer400Years; const auto daysMinusFull400YearBlocks = fullDays - full400YearBlocks * m_daysPer400Years;
int full100YearBlocks = daysMinusFull400YearBlocks / m_daysPer100Years; auto full100YearBlocks = daysMinusFull400YearBlocks / m_daysPer100Years;
if (full100YearBlocks == 4) { if (full100YearBlocks == 4) {
full100YearBlocks = 3; full100YearBlocks = 3;
} }
const int daysMinusFull100YearBlocks = daysMinusFull400YearBlocks - full100YearBlocks * m_daysPer100Years; const auto daysMinusFull100YearBlocks = daysMinusFull400YearBlocks - full100YearBlocks * m_daysPer100Years;
const int full4YearBlocks = daysMinusFull100YearBlocks / m_daysPer4Years; const auto full4YearBlocks = daysMinusFull100YearBlocks / m_daysPer4Years;
const int daysMinusFull4YearBlocks = daysMinusFull100YearBlocks - full4YearBlocks * m_daysPer4Years; const auto daysMinusFull4YearBlocks = daysMinusFull100YearBlocks - full4YearBlocks * m_daysPer4Years;
int full1YearBlocks = daysMinusFull4YearBlocks / m_daysPerYear; auto full1YearBlocks = daysMinusFull4YearBlocks / m_daysPerYear;
if (full1YearBlocks == 4) { if (full1YearBlocks == 4) {
full1YearBlocks = 3; full1YearBlocks = 3;
} }
if (part == DatePart::Year) { if (part == DatePart::Year) {
return full400YearBlocks * 400 + full100YearBlocks * 100 + full4YearBlocks * 4 + full1YearBlocks + 1; return full400YearBlocks * 400 + full100YearBlocks * 100 + full4YearBlocks * 4 + full1YearBlocks + 1;
} }
const int restDays = daysMinusFull4YearBlocks - full1YearBlocks * m_daysPerYear; const auto restDays = daysMinusFull4YearBlocks - full1YearBlocks * m_daysPerYear;
if (part == DatePart::DayOfYear) { // day if (part == DatePart::DayOfYear) { // day
return restDays + 1; return restDays + 1;
} }
const int *const daysToMonth = (full1YearBlocks == 3 && (full4YearBlocks != 24 || full100YearBlocks == 3)) ? m_daysToMonth366 : m_daysToMonth365; const auto *const daysToMonth = (full1YearBlocks == 3 && (full4YearBlocks != 24 || full100YearBlocks == 3)) ? m_daysToMonth366 : m_daysToMonth365;
int month = 1; auto month = 1;
while (restDays >= daysToMonth[month]) { while (restDays >= daysToMonth[month]) {
++month; ++month;
} }

View File

@ -306,7 +306,7 @@ constexpr inline DayOfWeek DateTime::dayOfWeek() const
*/ */
constexpr inline int DateTime::hour() const constexpr inline int DateTime::hour() const
{ {
return m_ticks / TimeSpan::ticksPerHour % 24ul; return static_cast<int>(m_ticks / TimeSpan::ticksPerHour % 24ul);
} }
/*! /*!
@ -314,7 +314,7 @@ constexpr inline int DateTime::hour() const
*/ */
constexpr inline int DateTime::minute() const constexpr inline int DateTime::minute() const
{ {
return m_ticks / TimeSpan::ticksPerMinute % 60ul; return static_cast<int>(m_ticks / TimeSpan::ticksPerMinute % 60ul);
} }
/*! /*!
@ -322,7 +322,7 @@ constexpr inline int DateTime::minute() const
*/ */
constexpr inline int DateTime::second() const constexpr inline int DateTime::second() const
{ {
return m_ticks / TimeSpan::ticksPerSecond % 60ul; return static_cast<int>(m_ticks / TimeSpan::ticksPerSecond % 60ul);
} }
/*! /*!
@ -330,7 +330,7 @@ constexpr inline int DateTime::second() const
*/ */
constexpr inline int DateTime::millisecond() const constexpr inline int DateTime::millisecond() const
{ {
return m_ticks / TimeSpan::ticksPerMillisecond % 1000ul; return static_cast<int>(m_ticks / TimeSpan::ticksPerMillisecond % 1000ul);
} }
/*! /*!
@ -338,7 +338,7 @@ constexpr inline int DateTime::millisecond() const
*/ */
constexpr inline int DateTime::microsecond() const constexpr inline int DateTime::microsecond() const
{ {
return m_ticks / TimeSpan::ticksPerMicrosecond % 1000ul; return static_cast<int>(m_ticks / TimeSpan::ticksPerMicrosecond % 1000ul);
} }
/*! /*!
@ -348,7 +348,7 @@ constexpr inline int DateTime::microsecond() const
*/ */
constexpr inline int DateTime::nanosecond() const constexpr inline int DateTime::nanosecond() const
{ {
return m_ticks % 10ul * TimeSpan::nanosecondsPerTick; return static_cast<int>(m_ticks % 10ul * TimeSpan::nanosecondsPerTick);
} }
/*! /*!
@ -365,7 +365,7 @@ constexpr inline bool DateTime::isNull() const
*/ */
constexpr inline TimeSpan DateTime::timeOfDay() const constexpr inline TimeSpan DateTime::timeOfDay() const
{ {
return TimeSpan(m_ticks % TimeSpan::ticksPerDay); return TimeSpan(static_cast<std::int64_t>(m_ticks % TimeSpan::ticksPerDay));
} }
/*! /*!
@ -425,7 +425,7 @@ inline std::string DateTime::toString(DateTimeOutputFormat format, bool noMillis
*/ */
constexpr std::time_t DateTime::toTimeStamp() const constexpr std::time_t DateTime::toTimeStamp() const
{ {
return (totalTicks() - DateTime::unixEpochStart().totalTicks()) / TimeSpan::ticksPerSecond; return static_cast<std::time_t>((totalTicks() - DateTime::unixEpochStart().totalTicks()) / TimeSpan::ticksPerSecond);
} }
/*! /*!
@ -516,7 +516,7 @@ constexpr inline bool DateTime::operator>=(const DateTime &other) const
*/ */
constexpr inline DateTime DateTime::operator+(const TimeSpan &timeSpan) const constexpr inline DateTime DateTime::operator+(const TimeSpan &timeSpan) const
{ {
return DateTime(m_ticks + timeSpan.m_ticks); return DateTime(m_ticks + static_cast<std::uint64_t>(timeSpan.m_ticks));
} }
/*! /*!
@ -525,7 +525,7 @@ constexpr inline DateTime DateTime::operator+(const TimeSpan &timeSpan) const
*/ */
constexpr inline DateTime DateTime::operator-(const TimeSpan &timeSpan) const constexpr inline DateTime DateTime::operator-(const TimeSpan &timeSpan) const
{ {
return DateTime(m_ticks - timeSpan.m_ticks); return DateTime(m_ticks - static_cast<std::uint64_t>(timeSpan.m_ticks));
} }
/*! /*!
@ -534,7 +534,7 @@ constexpr inline DateTime DateTime::operator-(const TimeSpan &timeSpan) const
*/ */
constexpr inline TimeSpan DateTime::operator+(const DateTime &other) const constexpr inline TimeSpan DateTime::operator+(const DateTime &other) const
{ {
return TimeSpan(m_ticks + other.m_ticks); return TimeSpan(static_cast<std::int64_t>(m_ticks + other.m_ticks));
} }
/*! /*!
@ -545,7 +545,7 @@ constexpr inline TimeSpan DateTime::operator+(const DateTime &other) const
*/ */
constexpr inline TimeSpan DateTime::operator-(const DateTime &other) const constexpr inline TimeSpan DateTime::operator-(const DateTime &other) const
{ {
return TimeSpan(m_ticks - other.m_ticks); return TimeSpan(static_cast<std::int64_t>(m_ticks - other.m_ticks));
} }
/*! /*!
@ -553,7 +553,7 @@ constexpr inline TimeSpan DateTime::operator-(const DateTime &other) const
*/ */
inline DateTime &DateTime::operator+=(const TimeSpan &timeSpan) inline DateTime &DateTime::operator+=(const TimeSpan &timeSpan)
{ {
m_ticks += timeSpan.m_ticks; m_ticks += static_cast<std::uint64_t>(timeSpan.m_ticks);
return *this; return *this;
} }
@ -562,7 +562,7 @@ inline DateTime &DateTime::operator+=(const TimeSpan &timeSpan)
*/ */
inline DateTime &DateTime::operator-=(const TimeSpan &timeSpan) inline DateTime &DateTime::operator-=(const TimeSpan &timeSpan)
{ {
m_ticks -= timeSpan.m_ticks; m_ticks += static_cast<std::uint64_t>(timeSpan.m_ticks);
return *this; return *this;
} }
} // namespace CppUtilities } // namespace CppUtilities

View File

@ -247,7 +247,7 @@ constexpr inline double TimeSpan::totalDays() const
*/ */
constexpr int TimeSpan::nanoseconds() const constexpr int TimeSpan::nanoseconds() const
{ {
return m_ticks % 10l * TimeSpan::nanosecondsPerTick; return static_cast<int>(m_ticks % 10l * TimeSpan::nanosecondsPerTick);
} }
/*! /*!
@ -255,7 +255,7 @@ constexpr int TimeSpan::nanoseconds() const
*/ */
constexpr int TimeSpan::microseconds() const constexpr int TimeSpan::microseconds() const
{ {
return (m_ticks / ticksPerMicrosecond) % 1000l; return static_cast<int>((m_ticks / ticksPerMicrosecond) % 1000l);
} }
/*! /*!
@ -263,7 +263,7 @@ constexpr int TimeSpan::microseconds() const
*/ */
constexpr inline int TimeSpan::milliseconds() const constexpr inline int TimeSpan::milliseconds() const
{ {
return (m_ticks / ticksPerMillisecond) % 1000l; return static_cast<int>((m_ticks / ticksPerMillisecond) % 1000l);
} }
/*! /*!
@ -271,7 +271,7 @@ constexpr inline int TimeSpan::milliseconds() const
*/ */
constexpr inline int TimeSpan::seconds() const constexpr inline int TimeSpan::seconds() const
{ {
return (m_ticks / ticksPerSecond) % 60l; return static_cast<int>((m_ticks / ticksPerSecond) % 60l);
} }
/*! /*!
@ -279,7 +279,7 @@ constexpr inline int TimeSpan::seconds() const
*/ */
constexpr inline int TimeSpan::minutes() const constexpr inline int TimeSpan::minutes() const
{ {
return (m_ticks / ticksPerMinute) % 60l; return static_cast<int>((m_ticks / ticksPerMinute) % 60l);
} }
/*! /*!
@ -287,7 +287,7 @@ constexpr inline int TimeSpan::minutes() const
*/ */
constexpr inline int TimeSpan::hours() const constexpr inline int TimeSpan::hours() const
{ {
return (m_ticks / ticksPerHour) % 24l; return static_cast<int>((m_ticks / ticksPerHour) % 24l);
} }
/*! /*!
@ -295,7 +295,7 @@ constexpr inline int TimeSpan::hours() const
*/ */
constexpr inline int TimeSpan::days() const constexpr inline int TimeSpan::days() const
{ {
return (m_ticks / ticksPerDay); return static_cast<int>((m_ticks / ticksPerDay));
} }
/*! /*!
@ -367,7 +367,7 @@ constexpr inline TimeSpan TimeSpan::operator-(const TimeSpan &other) const
*/ */
constexpr inline TimeSpan TimeSpan::operator*(double factor) const constexpr inline TimeSpan TimeSpan::operator*(double factor) const
{ {
return TimeSpan(m_ticks * factor); return TimeSpan(static_cast<std::int64_t>(static_cast<double>(m_ticks) * factor));
} }
/*! /*!
@ -375,7 +375,7 @@ constexpr inline TimeSpan TimeSpan::operator*(double factor) const
*/ */
constexpr inline TimeSpan TimeSpan::operator/(double factor) const constexpr inline TimeSpan TimeSpan::operator/(double factor) const
{ {
return TimeSpan(m_ticks / factor); return TimeSpan(static_cast<std::int64_t>(static_cast<double>(m_ticks) / factor));
} }
/*! /*!
@ -409,7 +409,7 @@ inline TimeSpan &TimeSpan::operator-=(const TimeSpan &other)
*/ */
inline TimeSpan &TimeSpan::operator*=(double factor) inline TimeSpan &TimeSpan::operator*=(double factor)
{ {
m_ticks = m_ticks * factor; m_ticks = static_cast<std::int64_t>(static_cast<double>(m_ticks) * factor);
return *this; return *this;
} }
@ -418,7 +418,7 @@ inline TimeSpan &TimeSpan::operator*=(double factor)
*/ */
inline TimeSpan &TimeSpan::operator/=(double factor) inline TimeSpan &TimeSpan::operator/=(double factor)
{ {
m_ticks = m_ticks / factor; m_ticks = static_cast<std::int64_t>(static_cast<double>(m_ticks) / factor);
return *this; return *this;
} }

View File

@ -153,7 +153,7 @@ CPP_UTILITIES_EXPORT constexpr std::uint32_t toNormalInt(std::uint32_t synchsafe
*/ */
CPP_UTILITIES_EXPORT constexpr std::uint16_t swapOrder(std::uint16_t value) CPP_UTILITIES_EXPORT constexpr std::uint16_t swapOrder(std::uint16_t value)
{ {
return ((value >> 8) & 0x00FF) | ((value << 8) & 0xFF00); return static_cast<std::uint16_t>(((value >> 8) & 0x00FF) | ((value << 8) & 0xFF00));
} }
/*! /*!

View File

@ -6,15 +6,21 @@
#include <cstdint> #include <cstdint>
// disable warnings about sign conversions when using GCC or Clang
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
/*! /*!
* \brief Returns a 16-bit signed integer converted from two bytes at a specified position in a char array. * \brief Returns a 16-bit signed integer converted from two bytes at a specified position in a char array.
*/ */
CPP_UTILITIES_EXPORT constexpr std::int16_t toInt16(const char *value) CPP_UTILITIES_EXPORT constexpr std::int16_t toInt16(const char *value)
{ {
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0 #if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
return (static_cast<std::int16_t>(value[0]) << 8 & 0xFF00) | (static_cast<std::int16_t>(value[1]) & 0x00FF); return static_cast<std::int16_t>((static_cast<std::int16_t>(value[0]) << 8 & 0xFF00) | (static_cast<std::int16_t>(value[1]) & 0x00FF));
#else #else
return (static_cast<std::int16_t>(value[1]) << 8 & 0xFF00) | (static_cast<std::int16_t>(value[0]) & 0x00FF); return static_cast<std::int16_t>((static_cast<std::int16_t>(value[1]) << 8 & 0xFF00) | (static_cast<std::int16_t>(value[0]) & 0x00FF));
#endif #endif
} }
@ -24,9 +30,9 @@ CPP_UTILITIES_EXPORT constexpr std::int16_t toInt16(const char *value)
CPP_UTILITIES_EXPORT constexpr std::uint16_t toUInt16(const char *value) CPP_UTILITIES_EXPORT constexpr std::uint16_t toUInt16(const char *value)
{ {
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0 #if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
return (static_cast<std::uint16_t>(value[0]) << 8 & 0xFF00) | (static_cast<std::uint16_t>(value[1]) & 0x00FF); return static_cast<std::uint16_t>((static_cast<std::uint16_t>(value[0]) << 8 & 0xFF00) | (static_cast<std::uint16_t>(value[1]) & 0x00FF));
#else #else
return (static_cast<std::uint16_t>(value[1]) << 8 & 0xFF00) | (static_cast<std::uint16_t>(value[0]) & 0x00FF); return static_cast<std::uint16_t>((static_cast<std::uint16_t>(value[1]) << 8 & 0xFF00) | (static_cast<std::uint16_t>(value[0]) & 0x00FF));
#endif #endif
} }
@ -36,11 +42,13 @@ CPP_UTILITIES_EXPORT constexpr std::uint16_t toUInt16(const char *value)
CPP_UTILITIES_EXPORT constexpr std::int32_t toInt32(const char *value) CPP_UTILITIES_EXPORT constexpr std::int32_t toInt32(const char *value)
{ {
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0 #if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
return (static_cast<std::int32_t>(value[0]) << 24 & 0xFF000000) | (static_cast<std::int32_t>(value[1]) << 16 & 0x00FF0000) return static_cast<std::int32_t>((static_cast<std::int32_t>(value[0]) << 24 & 0xFF000000)
| (static_cast<std::int32_t>(value[2]) << 8 & 0x0000FF00) | (static_cast<std::int32_t>(value[3]) & 0x000000FF); | (static_cast<std::int32_t>(value[1]) << 16 & 0x00FF0000) | (static_cast<std::int32_t>(value[2]) << 8 & 0x0000FF00)
| (static_cast<std::int32_t>(value[3]) & 0x000000FF));
#else #else
return (static_cast<std::int32_t>(value[3]) << 24 & 0xFF000000) | (static_cast<std::int32_t>(value[2]) << 16 & 0x00FF0000) return static_cast<std::int32_t>((static_cast<std::int32_t>(value[3]) << 24 & 0xFF000000)
| (static_cast<std::int32_t>(value[1]) << 8 & 0x0000FF00) | (static_cast<std::int32_t>(value[0]) & 0x000000FF); | (static_cast<std::int32_t>(value[2]) << 16 & 0x00FF0000) | (static_cast<std::int32_t>(value[1]) << 8 & 0x0000FF00)
| (static_cast<std::int32_t>(value[0]) & 0x000000FF));
#endif #endif
} }
@ -125,7 +133,7 @@ CPP_UTILITIES_EXPORT inline double toFloat64(const char *value)
{ {
const auto val = toInt64(value); const auto val = toInt64(value);
const auto *const c = reinterpret_cast<const char *>(&val); const auto *const c = reinterpret_cast<const char *>(&val);
return *reinterpret_cast<const double *const>(c); return *reinterpret_cast<const double *>(c);
} }
/*! /*!
@ -281,4 +289,8 @@ CPP_UTILITIES_EXPORT inline void getBytes(double value, char *outputbuffer)
getBytes(i, outputbuffer); getBytes(i, outputbuffer);
} }
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#endif // CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL #endif // CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL

View File

@ -101,9 +101,9 @@ constexpr std::size_t computeTupleElementSize(CharType)
template <class StringType, typename IntegralType, template <class StringType, typename IntegralType,
Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>,
std::is_unsigned<IntegralType>> * = nullptr> std::is_unsigned<IntegralType>> * = nullptr>
constexpr std::size_t computeTupleElementSize(IntegralType number, typename StringType::value_type base = 10) constexpr std::size_t computeTupleElementSize(IntegralType number, IntegralType base = 10)
{ {
std::size_t size = 0; auto size = std::size_t(0u);
for (auto n = number; n; n /= base, ++size) for (auto n = number; n; n /= base, ++size)
; ;
return size; return size;
@ -112,9 +112,9 @@ constexpr std::size_t computeTupleElementSize(IntegralType number, typename Stri
template <class StringType, typename IntegralType, template <class StringType, typename IntegralType,
Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>,
std::is_signed<IntegralType>> * = nullptr> std::is_signed<IntegralType>> * = nullptr>
constexpr std::size_t computeTupleElementSize(IntegralType number, typename StringType::value_type base = 10) constexpr std::size_t computeTupleElementSize(IntegralType number, IntegralType base = 10)
{ {
std::size_t size = number < 0 ? 1 : 0; auto size = std::size_t(number < 0 ? 1u : 0u);
for (auto n = number; n; n /= base, ++size) for (auto n = number; n; n /= base, ++size)
; ;
return size; return size;
@ -176,11 +176,11 @@ inline void append(StringType &target, CharType c)
template <class StringType, typename IntegralType, template <class StringType, typename IntegralType,
Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>,
std::is_unsigned<IntegralType>> * = nullptr> std::is_unsigned<IntegralType>> * = nullptr>
inline void append(StringType &target, IntegralType number, typename StringType::value_type base = 10) inline void append(StringType &target, IntegralType number, IntegralType base = 10)
{ {
const auto start = target.begin() + target.size(); const auto start = target.begin() + static_cast<typename StringType::difference_type>(target.size());
do { do {
target.insert(start, digitToChar<typename StringType::value_type>(number % base)); target.insert(start, static_cast<typename StringType::value_type>(digitToChar<IntegralType>(number % base)));
number /= base; number /= base;
} while (number); } while (number);
} }
@ -188,15 +188,15 @@ inline void append(StringType &target, IntegralType number, typename StringType:
template <class StringType, typename IntegralType, template <class StringType, typename IntegralType,
Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>, Traits::EnableIf<Traits::Not<std::is_same<typename StringType::value_type, IntegralType>>, std::is_integral<IntegralType>,
std::is_signed<IntegralType>> * = nullptr> std::is_signed<IntegralType>> * = nullptr>
inline void append(StringType &target, IntegralType number, typename StringType::value_type base = 10) inline void append(StringType &target, IntegralType number, IntegralType base = 10)
{ {
if (number < 0) { if (number < 0) {
target += '-'; target += '-';
number = -number; number = -number;
} }
const auto start = target.begin() + target.size(); const auto start = target.begin() + static_cast<typename StringType::difference_type>(target.size());
do { do {
target.insert(start, digitToChar<typename StringType::value_type>(number % base)); target.insert(start, static_cast<typename StringType::value_type>(digitToChar<IntegralType>(number % base)));
number /= base; number /= base;
} while (number); } while (number);
} }
@ -232,12 +232,14 @@ template <class StringType, class Tuple> struct TupleToString<StringType, Tuple,
template <class StringType, typename TupleType, Traits::EnableIf<Traits::IsSpecializationOf<std::decay_t<TupleType>, std::tuple>> *> template <class StringType, typename TupleType, Traits::EnableIf<Traits::IsSpecializationOf<std::decay_t<TupleType>, std::tuple>> *>
constexpr std::size_t computeTupleElementSize(TupleType &&tuple, typename StringType::value_type base) constexpr std::size_t computeTupleElementSize(TupleType &&tuple, typename StringType::value_type base)
{ {
CPP_UTILITIES_UNUSED(base)
return TupleToString<StringType, TupleType, std::tuple_size_v<std::decay_t<TupleType>>>::precomputeSize(std::forward<TupleType>(tuple)); return TupleToString<StringType, TupleType, std::tuple_size_v<std::decay_t<TupleType>>>::precomputeSize(std::forward<TupleType>(tuple));
} }
template <class StringType, typename TupleType, Traits::EnableIf<Traits::IsSpecializationOf<std::decay_t<TupleType>, std::tuple>> *> template <class StringType, typename TupleType, Traits::EnableIf<Traits::IsSpecializationOf<std::decay_t<TupleType>, std::tuple>> *>
constexpr void append(StringType &target, TupleType &&tuple, typename StringType::value_type base) constexpr void append(StringType &target, TupleType &&tuple, typename StringType::value_type base)
{ {
CPP_UTILITIES_UNUSED(base)
return TupleToString<StringType, TupleType, std::tuple_size_v<std::decay_t<TupleType>>>::append(std::forward<TupleType>(tuple), target); return TupleToString<StringType, TupleType, std::tuple_size_v<std::decay_t<TupleType>>>::append(std::forward<TupleType>(tuple), target);
} }

View File

@ -49,7 +49,7 @@ struct Factor {
: factor(factor){}; : factor(factor){};
size_t operator()(size_t value) size_t operator()(size_t value)
{ {
return static_cast<size_t>(value * factor); return static_cast<size_t>(static_cast<float>(value) * factor);
} }
float factor; float factor;
}; };
@ -340,13 +340,13 @@ const char base64Pad = '=';
*/ */
string encodeBase64(const std::uint8_t *data, std::uint32_t dataSize) string encodeBase64(const std::uint8_t *data, std::uint32_t dataSize)
{ {
string encoded; auto encoded = std::string();
std::uint8_t mod = dataSize % 3; auto mod = static_cast<std::uint8_t>(dataSize % 3);
auto temp = std::uint32_t();
encoded.reserve(((dataSize / 3) + (mod > 0)) * 4); encoded.reserve(((dataSize / 3) + (mod > 0)) * 4);
std::uint32_t temp;
for (const std::uint8_t *end = --data + dataSize - mod; data != end;) { for (const std::uint8_t *end = --data + dataSize - mod; data != end;) {
temp = *++data << 16; temp = static_cast<std::uint32_t>(*++data << 16);
temp |= *++data << 8; temp |= static_cast<std::uint32_t>(*++data << 8);
temp |= *++data; temp |= *++data;
encoded.push_back(base64Chars[(temp & 0x00FC0000) >> 18]); encoded.push_back(base64Chars[(temp & 0x00FC0000) >> 18]);
encoded.push_back(base64Chars[(temp & 0x0003F000) >> 12]); encoded.push_back(base64Chars[(temp & 0x0003F000) >> 12]);
@ -355,15 +355,15 @@ string encodeBase64(const std::uint8_t *data, std::uint32_t dataSize)
} }
switch (mod) { switch (mod) {
case 1: case 1:
temp = *++data << 16; temp = static_cast<std::uint32_t>(*++data << 16);
encoded.push_back(base64Chars[(temp & 0x00FC0000) >> 18]); encoded.push_back(base64Chars[(temp & 0x00FC0000) >> 18]);
encoded.push_back(base64Chars[(temp & 0x0003F000) >> 12]); encoded.push_back(base64Chars[(temp & 0x0003F000) >> 12]);
encoded.push_back(base64Pad); encoded.push_back(base64Pad);
encoded.push_back(base64Pad); encoded.push_back(base64Pad);
break; break;
case 2: case 2:
temp = *++data << 16; temp = static_cast<std::uint32_t>(*++data << 16);
temp |= *++data << 8; temp |= static_cast<std::uint32_t>(*++data << 8);
encoded.push_back(base64Chars[(temp & 0x00FC0000) >> 18]); encoded.push_back(base64Chars[(temp & 0x00FC0000) >> 18]);
encoded.push_back(base64Chars[(temp & 0x0003F000) >> 12]); encoded.push_back(base64Chars[(temp & 0x0003F000) >> 12]);
encoded.push_back(base64Chars[(temp & 0x00000FC0) >> 6]); encoded.push_back(base64Chars[(temp & 0x00000FC0) >> 6]);
@ -412,11 +412,11 @@ pair<unique_ptr<std::uint8_t[]>, std::uint32_t> decodeBase64(const char *encoded
} else if (*encodedStr == base64Pad) { } else if (*encodedStr == base64Pad) {
switch (end - encodedStr) { switch (end - encodedStr) {
case 1: case 1:
*++iter = (temp >> 16) & 0xFF; *++iter = static_cast<std::uint8_t>((temp >> 16) & 0xFF);
*++iter = (temp >> 8) & 0xFF; *++iter = static_cast<std::uint8_t>((temp >> 8) & 0xFF);
return make_pair(move(buffer), decodedSize); return make_pair(move(buffer), decodedSize);
case 2: case 2:
*++iter = (temp >> 10) & 0xFF; *++iter = static_cast<std::uint8_t>((temp >> 10) & 0xFF);
return make_pair(move(buffer), decodedSize); return make_pair(move(buffer), decodedSize);
default: default:
throw ConversionException("invalid padding in base64"); throw ConversionException("invalid padding in base64");
@ -425,9 +425,9 @@ pair<unique_ptr<std::uint8_t[]>, std::uint32_t> decodeBase64(const char *encoded
throw ConversionException("invalid character in base64"); throw ConversionException("invalid character in base64");
} }
} }
*++iter = (temp >> 16) & 0xFF; *++iter = static_cast<std::uint8_t>((temp >> 16) & 0xFF);
*++iter = (temp >> 8) & 0xFF; *++iter = static_cast<std::uint8_t>((temp >> 8) & 0xFF);
*++iter = (temp)&0xFF; *++iter = static_cast<std::uint8_t>(temp & 0xFF);
} }
return make_pair(move(buffer), decodedSize); return make_pair(move(buffer), decodedSize);
} }

View File

@ -281,7 +281,8 @@ template <typename StringType> bool endsWith(const StringType &str, const String
if (str.size() < phrase.size()) { if (str.size() < phrase.size()) {
return false; return false;
} }
for (auto stri = str.cend() - phrase.size(), strend = str.cend(), phrasei = phrase.cbegin(); stri != strend; ++stri, ++phrasei) { for (auto stri = str.cend() - static_cast<typename StringType::difference_type>(phrase.size()), strend = str.cend(), phrasei = phrase.cbegin();
stri != strend; ++stri, ++phrasei) {
if (*stri != *phrasei) { if (*stri != *phrasei) {
return false; return false;
} }
@ -298,7 +299,8 @@ template <typename StringType> bool endsWith(const StringType &str, const typena
if (str.size() < phraseSize) { if (str.size() < phraseSize) {
return false; return false;
} }
for (auto stri = str.cend() - phraseSize, strend = str.cend(); stri != strend; ++stri, ++phrase) { for (auto stri = str.cend() - static_cast<typename StringType::difference_type>(phraseSize), strend = str.cend(); stri != strend;
++stri, ++phrase) {
if (*stri != *phrase) { if (*stri != *phrase) {
return false; return false;
} }
@ -397,7 +399,7 @@ template <typename CharType> constexpr CharType digitToChar(CharType digit)
*/ */
template <typename IntegralType, class StringType = std::string, template <typename IntegralType, class StringType = std::string,
CppUtilities::Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr> CppUtilities::Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr>
StringType numberToString(IntegralType number, typename StringType::value_type base = 10) StringType numberToString(IntegralType number, IntegralType base = 10)
{ {
std::size_t resSize = 0; std::size_t resSize = 0;
for (auto n = number; n; n /= base, ++resSize) for (auto n = number; n; n /= base, ++resSize)
@ -405,7 +407,7 @@ StringType numberToString(IntegralType number, typename StringType::value_type b
StringType res; StringType res;
res.reserve(resSize); res.reserve(resSize);
do { do {
res.insert(res.begin(), digitToChar<typename StringType::value_type>(number % base)); res.insert(res.begin(), digitToChar<typename StringType::value_type>(static_cast<typename StringType::value_type>(number % base)));
number /= base; number /= base;
} while (number); } while (number);
return res; return res;
@ -419,7 +421,7 @@ StringType numberToString(IntegralType number, typename StringType::value_type b
*/ */
template <typename IntegralType, class StringType = std::string, template <typename IntegralType, class StringType = std::string,
Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr> Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr>
StringType numberToString(IntegralType number, typename StringType::value_type base = 10) StringType numberToString(IntegralType number, IntegralType base = 10)
{ {
const bool negative = number < 0; const bool negative = number < 0;
std::size_t resSize; std::size_t resSize;
@ -433,7 +435,7 @@ StringType numberToString(IntegralType number, typename StringType::value_type b
StringType res; StringType res;
res.reserve(resSize); res.reserve(resSize);
do { do {
res.insert(res.begin(), digitToChar<typename StringType::value_type>(number % base)); res.insert(res.begin(), digitToChar<typename StringType::value_type>(static_cast<typename StringType::value_type>(number % base)));
number /= base; number /= base;
} while (number); } while (number);
if (negative) { if (negative) {
@ -451,7 +453,7 @@ StringType numberToString(IntegralType number, typename StringType::value_type b
* \sa stringToNumber(), bufferToNumber() * \sa stringToNumber(), bufferToNumber()
*/ */
template <typename FloatingType, class StringType = std::string, Traits::EnableIf<std::is_floating_point<FloatingType>> * = nullptr> template <typename FloatingType, class StringType = std::string, Traits::EnableIf<std::is_floating_point<FloatingType>> * = nullptr>
StringType numberToString(FloatingType number, typename StringType::value_type base = 10) StringType numberToString(FloatingType number, int base = 10)
{ {
std::basic_stringstream<typename StringType::value_type> ss; std::basic_stringstream<typename StringType::value_type> ss;
ss << std::setbase(base) << number; ss << std::setbase(base) << number;
@ -479,7 +481,7 @@ template <typename CharType> CharType charToDigit(CharType character, CharType b
std::string errorMsg; std::string errorMsg;
errorMsg.reserve(36); errorMsg.reserve(36);
errorMsg += "The character \""; errorMsg += "The character \"";
errorMsg += character; errorMsg += character >= ' ' && character <= '~' ? static_cast<std::string::value_type>(character) : '?';
errorMsg += "\" is no valid digit."; errorMsg += "\" is no valid digit.";
throw ConversionException(std::move(errorMsg)); throw ConversionException(std::move(errorMsg));
} }
@ -493,7 +495,7 @@ template <typename CharType> CharType charToDigit(CharType character, CharType b
* \todo Provide an alternative using std::expected (when switching to C++17). * \todo Provide an alternative using std::expected (when switching to C++17).
*/ */
template <typename IntegralType, typename StringType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr> template <typename IntegralType, typename StringType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr>
IntegralType stringToNumber(const StringType &string, typename StringType::value_type base = 10) IntegralType stringToNumber(const StringType &string, IntegralType base = 10)
{ {
IntegralType result = 0; IntegralType result = 0;
for (const auto &c : string) { for (const auto &c : string) {
@ -501,7 +503,7 @@ IntegralType stringToNumber(const StringType &string, typename StringType::value
continue; continue;
} }
result *= base; result *= base;
result += charToDigit<typename StringType::value_type>(c, base); result += static_cast<IntegralType>(charToDigit<typename StringType::value_type>(c, static_cast<typename StringType::value_type>(base)));
} }
return result; return result;
} }
@ -515,7 +517,7 @@ IntegralType stringToNumber(const StringType &string, typename StringType::value
* \todo Provide an alternative using std::expected (when switching to C++17). * \todo Provide an alternative using std::expected (when switching to C++17).
*/ */
template <typename IntegralType, class StringType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr> template <typename IntegralType, class StringType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr>
IntegralType stringToNumber(const StringType &string, typename StringType::value_type base = 10) IntegralType stringToNumber(const StringType &string, IntegralType base = 10)
{ {
auto i = string.begin(); auto i = string.begin();
auto end = string.end(); auto end = string.end();
@ -534,7 +536,7 @@ IntegralType stringToNumber(const StringType &string, typename StringType::value
continue; continue;
} }
result *= base; result *= base;
result += charToDigit<typename StringType::value_type>(*i, base); result += static_cast<IntegralType>(charToDigit<typename StringType::value_type>(*i, static_cast<typename StringType::value_type>(base)));
} }
return negative ? -result : result; return negative ? -result : result;
} }
@ -550,7 +552,7 @@ IntegralType stringToNumber(const StringType &string, typename StringType::value
* \todo Provide an alternative using std::expected (when switching to C++17). * \todo Provide an alternative using std::expected (when switching to C++17).
*/ */
template <typename FloatingType, class StringType, Traits::EnableIf<std::is_floating_point<FloatingType>> * = nullptr> template <typename FloatingType, class StringType, Traits::EnableIf<std::is_floating_point<FloatingType>> * = nullptr>
FloatingType stringToNumber(const StringType &string, typename StringType::value_type base = 10) FloatingType stringToNumber(const StringType &string, int base = 10)
{ {
std::basic_stringstream<typename StringType::value_type> ss; std::basic_stringstream<typename StringType::value_type> ss;
ss << std::setbase(base) << string; ss << std::setbase(base) << string;
@ -575,7 +577,7 @@ FloatingType stringToNumber(const StringType &string, typename StringType::value
* \todo Provide an alternative using std::expected (when switching to C++17). * \todo Provide an alternative using std::expected (when switching to C++17).
*/ */
template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr> template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr>
IntegralType stringToNumber(const CharType *string, unsigned char base = 10) IntegralType stringToNumber(const CharType *string, IntegralType base = 10)
{ {
IntegralType result = 0; IntegralType result = 0;
for (; *string; ++string) { for (; *string; ++string) {
@ -583,7 +585,7 @@ IntegralType stringToNumber(const CharType *string, unsigned char base = 10)
continue; continue;
} }
result *= base; result *= base;
result += charToDigit<CharType>(*string, base); result += static_cast<IntegralType>(charToDigit<CharType>(*string, static_cast<CharType>(base)));
} }
return result; return result;
} }
@ -599,7 +601,7 @@ IntegralType stringToNumber(const CharType *string, unsigned char base = 10)
* \todo Provide an alternative using std::expected (when switching to C++17). * \todo Provide an alternative using std::expected (when switching to C++17).
*/ */
template <typename FloatingType, class CharType, Traits::EnableIf<std::is_floating_point<FloatingType>> * = nullptr> template <typename FloatingType, class CharType, Traits::EnableIf<std::is_floating_point<FloatingType>> * = nullptr>
FloatingType stringToNumber(const CharType *string, unsigned char base = 10) FloatingType stringToNumber(const CharType *string, int base = 10)
{ {
std::basic_stringstream<CharType> ss; std::basic_stringstream<CharType> ss;
ss << std::setbase(base) << string; ss << std::setbase(base) << string;
@ -623,7 +625,7 @@ FloatingType stringToNumber(const CharType *string, unsigned char base = 10)
* \sa numberToString(), stringToNumber() * \sa numberToString(), stringToNumber()
*/ */
template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr> template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr>
IntegralType bufferToNumber(const CharType *string, std::size_t size, unsigned char base = 10) IntegralType bufferToNumber(const CharType *string, std::size_t size, IntegralType base = 10)
{ {
IntegralType result = 0; IntegralType result = 0;
for (const CharType *end = string + size; string != end; ++string) { for (const CharType *end = string + size; string != end; ++string) {
@ -631,7 +633,7 @@ IntegralType bufferToNumber(const CharType *string, std::size_t size, unsigned c
continue; continue;
} }
result *= base; result *= base;
result += charToDigit<CharType>(*string, base); result += static_cast<IntegralType>(charToDigit<CharType>(*string, static_cast<CharType>(base)));
} }
return result; return result;
} }
@ -644,7 +646,7 @@ IntegralType bufferToNumber(const CharType *string, std::size_t size, unsigned c
* \sa numberToString(), bufferToNumber() * \sa numberToString(), bufferToNumber()
*/ */
template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr> template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr>
IntegralType stringToNumber(const CharType *string, unsigned char base = 10) IntegralType stringToNumber(const CharType *string, IntegralType base = 10)
{ {
if (!*string) { if (!*string) {
return 0; return 0;
@ -664,7 +666,7 @@ IntegralType stringToNumber(const CharType *string, unsigned char base = 10)
continue; continue;
} }
result *= base; result *= base;
result += charToDigit<CharType>(*string, base); result += static_cast<IntegralType>(charToDigit<CharType>(*string, static_cast<CharType>(base)));
} }
return negative ? -result : result; return negative ? -result : result;
} }
@ -677,7 +679,7 @@ IntegralType stringToNumber(const CharType *string, unsigned char base = 10)
* \sa numberToString(), stringToNumber() * \sa numberToString(), stringToNumber()
*/ */
template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr> template <typename IntegralType, class CharType, Traits::EnableIf<std::is_integral<IntegralType>, std::is_signed<IntegralType>> * = nullptr>
IntegralType bufferToNumber(const CharType *string, std::size_t size, unsigned char base = 10) IntegralType bufferToNumber(const CharType *string, std::size_t size, IntegralType base = 10)
{ {
if (!size) { if (!size) {
return 0; return 0;
@ -698,7 +700,7 @@ IntegralType bufferToNumber(const CharType *string, std::size_t size, unsigned c
continue; continue;
} }
result *= base; result *= base;
result += charToDigit<CharType>(*string, base); result += static_cast<IntegralType>(charToDigit<CharType>(*string, static_cast<CharType>(base)));
} }
return negative ? -result : result; return negative ? -result : result;
} }
@ -716,7 +718,7 @@ template <typename T> std::string interpretIntegerAsString(T integer, int startO
{ {
char buffer[sizeof(T)]; char buffer[sizeof(T)];
BE::getBytes(integer, buffer); BE::getBytes(integer, buffer);
return std::string(buffer + startOffset, sizeof(T) - startOffset); return std::string(buffer + startOffset, sizeof(T) - static_cast<std::size_t>(startOffset));
} }
CPP_UTILITIES_EXPORT std::string dataSizeToString(std::uint64_t sizeInByte, bool includeByte = false); CPP_UTILITIES_EXPORT std::string dataSizeToString(std::uint64_t sizeInByte, bool includeByte = false);

View File

@ -87,7 +87,7 @@ void BinaryReader::bufferVariableLengthInteger()
} }
memset(m_buffer, 0, maxPrefixLength); memset(m_buffer, 0, maxPrefixLength);
m_stream->read(m_buffer + (maxPrefixLength - prefixLength), prefixLength); m_stream->read(m_buffer + (maxPrefixLength - prefixLength), prefixLength);
*(m_buffer + (maxPrefixLength - prefixLength)) ^= mask; *(m_buffer + (maxPrefixLength - prefixLength)) ^= static_cast<char>(mask);
} }
/*! /*!

View File

@ -534,7 +534,7 @@ inline void BinaryWriter::writeFloat64LE(double value)
*/ */
inline void BinaryWriter::writeString(const std::string &value) inline void BinaryWriter::writeString(const std::string &value)
{ {
m_stream->write(value.c_str(), value.length()); m_stream->write(value.data(), static_cast<std::streamsize>(value.size()));
} }
/*! /*!
@ -542,7 +542,7 @@ inline void BinaryWriter::writeString(const std::string &value)
*/ */
inline void BinaryWriter::writeTerminatedString(const std::string &value) inline void BinaryWriter::writeTerminatedString(const std::string &value)
{ {
m_stream->write(value.c_str(), value.length() + 1); m_stream->write(value.data(), static_cast<std::streamsize>(value.size() + 1));
} }
/*! /*!

View File

@ -18,7 +18,7 @@ namespace CppUtilities {
void BitReader::skipBits(std::size_t bitCount) void BitReader::skipBits(std::size_t bitCount)
{ {
if (bitCount <= m_bitsAvail) { if (bitCount <= m_bitsAvail) {
m_bitsAvail -= bitCount; m_bitsAvail -= static_cast<std::uint8_t>(bitCount);
} else { } else {
if ((m_buffer += 1 + (bitCount -= m_bitsAvail) / 8) >= m_end) { if ((m_buffer += 1 + (bitCount -= m_bitsAvail) / 8) >= m_end) {
throw ios_base::failure("end of buffer exceeded"); throw ios_base::failure("end of buffer exceeded");

View File

@ -75,7 +75,8 @@ template <typename intType> intType BitReader::readBits(std::uint8_t bitCount)
m_bitsAvail = 8; m_bitsAvail = 8;
} }
readAtOnce = std::min(bitCount, m_bitsAvail); readAtOnce = std::min(bitCount, m_bitsAvail);
val = static_cast<intType>((val << readAtOnce) | (((*m_buffer) >> (m_bitsAvail -= readAtOnce)) & (0xFF >> (0x08 - readAtOnce)))); val = static_cast<intType>(
(val << readAtOnce) | static_cast<intType>(((*m_buffer) >> (m_bitsAvail -= readAtOnce)) & (0xFF >> (0x08 - readAtOnce))));
} }
return val; return val;
} }
@ -104,7 +105,7 @@ template <typename intType> intType BitReader::readUnsignedExpGolombCodedBits()
while (!readBit()) { while (!readBit()) {
++count; ++count;
} }
return count ? (((1 << count) | readBits<intType>(count)) - 1) : 0; return count ? static_cast<intType>(((1 << count) | readBits<intType>(count)) - 1) : 0;
} }
/*! /*!

View File

@ -47,8 +47,8 @@ template <std::size_t bufferSize> void CopyHelper<bufferSize>::copy(std::istream
output.write(m_buffer, bufferSize); output.write(m_buffer, bufferSize);
count -= bufferSize; count -= bufferSize;
} }
input.read(m_buffer, count); input.read(m_buffer, static_cast<std::streamsize>(count));
output.write(m_buffer, count); output.write(m_buffer, static_cast<std::streamsize>(count));
} }
/*! /*!
@ -65,7 +65,7 @@ template <std::size_t bufferSize>
void CopyHelper<bufferSize>::callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function<bool(void)> &isAborted, void CopyHelper<bufferSize>::callbackCopy(std::istream &input, std::ostream &output, std::size_t count, const std::function<bool(void)> &isAborted,
const std::function<void(double)> &callback) const std::function<void(double)> &callback)
{ {
const std::size_t totalBytes = count; const auto totalBytes = count;
while (count > bufferSize) { while (count > bufferSize) {
input.read(m_buffer, bufferSize); input.read(m_buffer, bufferSize);
output.write(m_buffer, bufferSize); output.write(m_buffer, bufferSize);
@ -73,10 +73,10 @@ void CopyHelper<bufferSize>::callbackCopy(std::istream &input, std::ostream &out
if (isAborted()) { if (isAborted()) {
return; return;
} }
callback(static_cast<double>(totalBytes - count) / totalBytes); callback(static_cast<double>(totalBytes - count) / static_cast<double>(totalBytes));
} }
input.read(m_buffer, count); input.read(m_buffer, static_cast<std::streamsize>(count));
output.write(m_buffer, count); output.write(m_buffer, static_cast<std::streamsize>(count));
callback(1.0); callback(1.0);
} }

View File

@ -12,22 +12,22 @@ namespace Detail {
template <class Tuple, std::size_t N> struct DimensionsHelper { template <class Tuple, std::size_t N> struct DimensionsHelper {
static std::size_t requiredSize(const Tuple &dimensionSizes) static std::size_t requiredSize(const Tuple &dimensionSizes)
{ {
return DimensionsHelper<Tuple, N - 1>::requiredSize(dimensionSizes) * std::get<N - 1>(dimensionSizes); return DimensionsHelper<Tuple, N - 1>::requiredSize(dimensionSizes) * static_cast<std::size_t>(std::get<N - 1>(dimensionSizes));
} }
static std::size_t offset(const Tuple &dimensions, const Tuple &indices, std::size_t factor) static std::size_t offset(const Tuple &dimensions, const Tuple &indices, std::size_t factor)
{ {
return DimensionsHelper<Tuple, N - 1>::offset(dimensions, indices, factor * std::get<N - 1>(dimensions)) return DimensionsHelper<Tuple, N - 1>::offset(dimensions, indices, factor * static_cast<std::size_t>(std::get<N - 1>(dimensions)))
+ (factor * std::get<N - 1>(indices)); + (factor * static_cast<std::size_t>(std::get<N - 1>(indices)));
} }
}; };
template <class Tuple> struct DimensionsHelper<Tuple, 1> { template <class Tuple> struct DimensionsHelper<Tuple, 1> {
static std::size_t requiredSize(const Tuple &dimensionSizes) static std::size_t requiredSize(const Tuple &dimensionSizes)
{ {
return std::get<0>(dimensionSizes); return static_cast<std::size_t>(std::get<0>(dimensionSizes));
} }
static std::size_t offset(const Tuple &, const Tuple &indices, std::size_t factor) static std::size_t offset(const Tuple &, const Tuple &indices, std::size_t factor)
{ {
return factor * std::get<0>(indices); return factor * static_cast<std::size_t>(std::get<0>(indices));
} }
}; };
} // namespace Detail } // namespace Detail
@ -70,6 +70,9 @@ struct NoneOwningMultiArray {
}; };
/// \brief The MultiArray class provides an *N*-dimensional array. /// \brief The MultiArray class provides an *N*-dimensional array.
/// \tparam T Specifies the type of the data the MultiArray is supposed to contain.
/// \tparam UnderlyingContainer Specifies the type of the underlying container to use.
/// \tparam Dimentions Specifies the types used to store the limit/size of the dimentions. Must be safely castable to std::size_t.
template <typename T, typename UnderlyingContainer, typename... Dimensions> class MultiArray { template <typename T, typename UnderlyingContainer, typename... Dimensions> class MultiArray {
public: public:
MultiArray(Dimensions... dimensionSizes); MultiArray(Dimensions... dimensionSizes);
@ -89,7 +92,7 @@ private:
typename UnderlyingContainer::template Type<T> m_buff; typename UnderlyingContainer::template Type<T> m_buff;
}; };
/// \brief Constructs a new *N*-dimensional array. The sizes for the dimensions are passed as arguments. /// \brief Constructs a new *N*-dimensional array. The sizes for the dimensions are passed as arguments and must be greather than zero.
/// \remarks The number of dimensions *N* is deduced from the number of \a dimensionSizes. /// \remarks The number of dimensions *N* is deduced from the number of \a dimensionSizes.
/// \sa makeMultiArray(), makeFixedSizeMultiArray() and makeNoneOwningMultiArray() for more convenient construction /// \sa makeMultiArray(), makeFixedSizeMultiArray() and makeNoneOwningMultiArray() for more convenient construction
template <typename T, typename UnderlyingContainer, typename... Dimensions> template <typename T, typename UnderlyingContainer, typename... Dimensions>
@ -119,7 +122,7 @@ template <typename T, typename UnderlyingContainer, typename... Dimensions>
template <std::size_t index> template <std::size_t index>
std::size_t MultiArray<T, UnderlyingContainer, Dimensions...>::dimensionSize() const std::size_t MultiArray<T, UnderlyingContainer, Dimensions...>::dimensionSize() const
{ {
return std::get<index>(m_dims); return static_cast<std::size_t>(std::get<index>(m_dims));
} }
/// \brief Returns the element at the position specified via \a indices. /// \brief Returns the element at the position specified via \a indices.

View File

@ -25,8 +25,8 @@ using namespace CPPUNIT_NS;
static_assert(toSynchsafeInt(255) == 383, "toSynchsafeInt()"); static_assert(toSynchsafeInt(255) == 383, "toSynchsafeInt()");
static_assert(toNormalInt(383) == 255, "toNormalInt()"); static_assert(toNormalInt(383) == 255, "toNormalInt()");
static_assert(swapOrder(static_cast<std::uint16_t>(0xABCD)) == 0xCDAB, "swapOrder(uint16)"); static_assert(swapOrder(static_cast<std::uint16_t>(0xABCD)) == 0xCDAB, "swapOrder(uint16)");
static_assert(swapOrder(static_cast<std::uint32_t>(0xABCDEF12)) == 0x12EFCDAB, "swapOrder(uint32)"); static_assert(swapOrder(0xABCDEF12u) == 0x12EFCDABu, "swapOrder(uint32)");
static_assert(swapOrder(static_cast<std::uint64_t>(0xABCDEF1234567890)) == 0x9078563412EFCDAB, "swapOrder(uint64)"); static_assert(swapOrder(0xABCDEF1234567890ul) == 0x9078563412EFCDABul, "swapOrder(uint64)");
/*! /*!
* \brief The ConversionTests class tests classes and functions provided by the files inside the conversion directory. * \brief The ConversionTests class tests classes and functions provided by the files inside the conversion directory.
@ -256,16 +256,16 @@ void ConversionTests::testStringConversions()
auto signedRandom = randomDistSigned(m_randomEngine); auto signedRandom = randomDistSigned(m_randomEngine);
auto unsignedRandom = randomDistUnsigned(m_randomEngine); auto unsignedRandom = randomDistUnsigned(m_randomEngine);
for (const auto base : initializer_list<std::uint8_t>{ 2, 8, 10, 16 }) { for (const auto base : initializer_list<std::uint8_t>{ 2, 8, 10, 16 }) {
const auto asString = numberToString<std::uint64_t, string>(unsignedRandom, static_cast<string::value_type>(base)); const auto asString = numberToString<std::uint64_t, string>(unsignedRandom, base);
const auto asWideString = numberToString<std::uint64_t, wstring>(unsignedRandom, base); const auto asWideString = numberToString<std::uint64_t, wstring>(unsignedRandom, base);
CPPUNIT_ASSERT_EQUAL_MESSAGE(stringMsg, unsignedRandom, stringToNumber<std::uint64_t>(asString, static_cast<string::value_type>(base))); CPPUNIT_ASSERT_EQUAL_MESSAGE(stringMsg, unsignedRandom, stringToNumber<std::uint64_t>(asString, base));
CPPUNIT_ASSERT_EQUAL_MESSAGE(wideStringMsg, unsignedRandom, stringToNumber<std::uint64_t>(asWideString, base)); CPPUNIT_ASSERT_EQUAL_MESSAGE(wideStringMsg, unsignedRandom, stringToNumber<std::uint64_t>(asWideString, base));
CPPUNIT_ASSERT_EQUAL_MESSAGE(bufferMsg, unsignedRandom, bufferToNumber<std::uint64_t>(asString.data(), asString.size(), base)); CPPUNIT_ASSERT_EQUAL_MESSAGE(bufferMsg, unsignedRandom, bufferToNumber<std::uint64_t>(asString.data(), asString.size(), base));
} }
for (const auto base : initializer_list<std::uint8_t>{ 10 }) { for (const auto base : initializer_list<std::uint8_t>{ 10 }) {
const auto asString = numberToString<std::int64_t, string>(signedRandom, static_cast<string::value_type>(base)); const auto asString = numberToString<std::int64_t, string>(signedRandom, static_cast<string::value_type>(base));
const auto asWideString = numberToString<std::int64_t, wstring>(signedRandom, base); const auto asWideString = numberToString<std::int64_t, wstring>(signedRandom, base);
CPPUNIT_ASSERT_EQUAL_MESSAGE(stringMsg, signedRandom, stringToNumber<std::int64_t>(asString, static_cast<string::value_type>(base))); CPPUNIT_ASSERT_EQUAL_MESSAGE(stringMsg, signedRandom, stringToNumber<std::int64_t>(asString, base));
CPPUNIT_ASSERT_EQUAL_MESSAGE(wideStringMsg, signedRandom, stringToNumber<std::int64_t>(asWideString, base)); CPPUNIT_ASSERT_EQUAL_MESSAGE(wideStringMsg, signedRandom, stringToNumber<std::int64_t>(asWideString, base));
CPPUNIT_ASSERT_EQUAL_MESSAGE(bufferMsg, signedRandom, bufferToNumber<std::int64_t>(asString.data(), asString.size(), base)); CPPUNIT_ASSERT_EQUAL_MESSAGE(bufferMsg, signedRandom, bufferToNumber<std::int64_t>(asString.data(), asString.size(), base));
} }

View File

@ -506,13 +506,13 @@ int TestApplication::execApp(const char *const *args, string &output, string &er
// determine the path of the application to be tested // determine the path of the application to be tested
const char *appPath = m_applicationPathArg.firstValue(); const char *appPath = m_applicationPathArg.firstValue();
string fallbackAppPath; auto fallbackAppPath = string();
if (!appPath || !*appPath) { if (!appPath || !*appPath) {
// try to find the path by removing "_tests"-suffix from own executable path // try to find the path by removing "_tests"-suffix from own executable path
// (the own executable path is the path of the test application and its name is usually the name of the application // (the own executable path is the path of the test application and its name is usually the name of the application
// to be tested with "_tests"-suffix) // to be tested with "_tests"-suffix)
const char *const testAppPath = m_parser.executable(); const char *const testAppPath = m_parser.executable();
const size_t testAppPathLength = strlen(testAppPath); const auto testAppPathLength = strlen(testAppPath);
if (testAppPathLength > 6 && !strcmp(testAppPath + testAppPathLength - 6, "_tests")) { if (testAppPathLength > 6 && !strcmp(testAppPath + testAppPathLength - 6, "_tests")) {
fallbackAppPath.assign(testAppPath, testAppPathLength - 6); fallbackAppPath.assign(testAppPath, testAppPathLength - 6);
appPath = fallbackAppPath.data(); appPath = fallbackAppPath.data();
@ -524,27 +524,27 @@ int TestApplication::execApp(const char *const *args, string &output, string &er
// determine new path for profiling output (to not override profiling output of parent and previous invocations) // determine new path for profiling output (to not override profiling output of parent and previous invocations)
const auto newProfilingPath = [appPath] { const auto newProfilingPath = [appPath] {
string newProfilingPath; auto path = string();
const char *const llvmProfileFile = getenv("LLVM_PROFILE_FILE"); const char *const llvmProfileFile = getenv("LLVM_PROFILE_FILE");
if (!llvmProfileFile) { if (!llvmProfileFile) {
return newProfilingPath; return path;
} }
// replace eg. "/some/path/tageditor_tests.profraw" with "/some/path/tageditor0.profraw" // replace eg. "/some/path/tageditor_tests.profraw" with "/some/path/tageditor0.profraw"
const char *const llvmProfileFileEnd = strstr(llvmProfileFile, ".profraw"); const char *const llvmProfileFileEnd = strstr(llvmProfileFile, ".profraw");
if (!llvmProfileFileEnd) { if (!llvmProfileFileEnd) {
return newProfilingPath; return path;
} }
const string llvmProfileFileWithoutExtension(llvmProfileFile, llvmProfileFileEnd); const auto llvmProfileFileWithoutExtension = string(llvmProfileFile, llvmProfileFileEnd);
// extract application name from path // extract application name from path
const char *appName = strrchr(appPath, '/'); const char *appName = strrchr(appPath, '/');
appName = appName ? appName + 1 : appPath; appName = appName ? appName + 1 : appPath;
// concat new path // concat new path
newProfilingPath = argsToString(llvmProfileFileWithoutExtension, '_', appName, invocationCount, ".profraw"); path = argsToString(llvmProfileFileWithoutExtension, '_', appName, invocationCount, ".profraw");
// append path to profiling list file // append path to profiling list file
if (const char *const profrawListFile = getenv("LLVM_PROFILE_LIST_FILE")) { if (const char *const profrawListFile = getenv("LLVM_PROFILE_LIST_FILE")) {
ofstream(profrawListFile, ios_base::app) << newProfilingPath << endl; ofstream(profrawListFile, ios_base::app) << path << endl;
} }
return newProfilingPath; return path;
}(); }();
return execAppInternal(appPath, args, output, errors, suppressLogging, timeout, newProfilingPath); return execAppInternal(appPath, args, output, errors, suppressLogging, timeout, newProfilingPath);