Remove types

This commit is contained in:
Martchus 2019-03-13 19:00:37 +01:00
parent 132f936c57
commit 9a50d2b8df
20 changed files with 484 additions and 563 deletions

View File

@ -16,7 +16,6 @@ set(HEADER_FILES
conversion/conversionexception.h
conversion/stringconversion.h
conversion/stringbuilder.h
conversion/types.h
io/ansiescapecodes.h
io/binaryreader.h
io/binarywriter.h

View File

@ -72,7 +72,7 @@ DateTime DateTime::fromTimeStamp(time_t timeStamp)
*/
DateTime DateTime::fromTimeStampGmt(time_t timeStamp)
{
return DateTime(DateTime::unixEpochStart().totalTicks() + static_cast<uint64>(timeStamp) * TimeSpan::ticksPerSecond);
return DateTime(DateTime::unixEpochStart().totalTicks() + static_cast<std::uint64_t>(timeStamp) * TimeSpan::ticksPerSecond);
}
/*!
@ -319,15 +319,15 @@ DateTime DateTime::exactGmtNow()
{
struct timespec t;
clock_gettime(CLOCK_REALTIME, &t);
return DateTime(
DateTime::unixEpochStart().totalTicks() + static_cast<uint64>(t.tv_sec) * TimeSpan::ticksPerSecond + static_cast<uint64>(t.tv_nsec) / 100);
return DateTime(DateTime::unixEpochStart().totalTicks() + static_cast<std::uint64_t>(t.tv_sec) * TimeSpan::ticksPerSecond
+ static_cast<std::uint64_t>(t.tv_nsec) / 100);
}
#endif
/*!
* \brief Converts the given date expressed in \a year, \a month and \a day to ticks.
*/
uint64 DateTime::dateToTicks(int year, int month, int day)
std::uint64_t DateTime::dateToTicks(int year, int month, int day)
{
if (!inRangeInclMax(year, 1, 9999)) {
throw ConversionException("year is out of range");
@ -350,7 +350,7 @@ uint64 DateTime::dateToTicks(int year, int month, int day)
/*!
* \brief Converts the given time expressed in \a hour, \a minute, \a second and \a millisecond to ticks.
*/
uint64 DateTime::timeToTicks(int hour, int minute, int second, double millisecond)
std::uint64_t DateTime::timeToTicks(int hour, int minute, int second, double millisecond)
{
if (!inRangeExclMax(hour, 0, 24)) {
throw ConversionException("hour is out of range");
@ -364,8 +364,8 @@ uint64 DateTime::timeToTicks(int hour, int minute, int second, double millisecon
if (!inRangeExclMax(millisecond, 0.0, 1000.0)) {
throw ConversionException("millisecond is out of range");
}
return static_cast<uint64>(hour * TimeSpan::ticksPerHour) + static_cast<uint64>(minute * TimeSpan::ticksPerMinute)
+ static_cast<uint64>(second * TimeSpan::ticksPerSecond) + static_cast<uint64>(millisecond * TimeSpan::ticksPerMillisecond);
return static_cast<std::uint64_t>(hour * TimeSpan::ticksPerHour) + static_cast<std::uint64_t>(minute * TimeSpan::ticksPerMinute)
+ static_cast<std::uint64_t>(second * TimeSpan::ticksPerSecond) + static_cast<std::uint64_t>(millisecond * TimeSpan::ticksPerMillisecond);
}
/*!

View File

@ -3,8 +3,7 @@
#include "./timespan.h"
#include "../conversion/types.h"
#include <cstdint>
#include <ctime>
#include <limits>
#include <string>
@ -52,7 +51,7 @@ enum class DatePart {
class CPP_UTILITIES_EXPORT DateTime {
public:
explicit constexpr DateTime();
explicit constexpr DateTime(uint64 ticks);
explicit constexpr DateTime(std::uint64_t ticks);
static DateTime fromDate(int year = 1, int month = 1, int day = 1);
static DateTime fromTime(int hour = 0, int minute = 0, int second = 0, double millisecond = 0.0);
static DateTime fromDateAndTime(int year = 1, int month = 1, int day = 1, int hour = 0, int minute = 0, int second = 0, double millisecond = 0.0);
@ -64,8 +63,8 @@ public:
static DateTime fromTimeStamp(time_t timeStamp);
static DateTime fromTimeStampGmt(time_t timeStamp);
uint64 &ticks();
constexpr uint64 totalTicks() const;
std::uint64_t &ticks();
constexpr std::uint64_t totalTicks() const;
int year() const;
int month() const;
int day() const;
@ -111,11 +110,11 @@ public:
DateTime &operator-=(const TimeSpan &timeSpan);
private:
static uint64 dateToTicks(int year, int month, int day);
static uint64 timeToTicks(int hour, int minute, int second, double millisecond);
static std::uint64_t dateToTicks(int year, int month, int day);
static std::uint64_t timeToTicks(int hour, int minute, int second, double millisecond);
int getDatePart(DatePart part) const;
uint64 m_ticks;
std::uint64_t m_ticks;
static const int m_daysPerYear;
static const int m_daysPer4Years;
static const int m_daysPer100Years;
@ -140,7 +139,7 @@ constexpr inline DateTime::DateTime()
/*!
* \brief Constructs a DateTime with the specified number of \a ticks.
*/
constexpr inline DateTime::DateTime(uint64 ticks)
constexpr inline DateTime::DateTime(std::uint64_t ticks)
: m_ticks(ticks)
{
}
@ -170,7 +169,7 @@ inline DateTime DateTime::fromTime(int hour, int minute, int second, double mill
*/
inline DateTime DateTime::fromDateAndTime(int year, int month, int day, int hour, int minute, int second, double millisecond)
{
if (uint64 ticks = dateToTicks(year, month, day)) {
if (std::uint64_t ticks = dateToTicks(year, month, day)) {
return DateTime(ticks + timeToTicks(hour, minute, second, millisecond));
}
return DateTime();
@ -216,7 +215,7 @@ inline DateTime DateTime::fromIsoStringLocal(const char *str)
/*!
* \brief Returns a mutable reference to the total ticks.
*/
inline uint64 &DateTime::ticks()
inline std::uint64_t &DateTime::ticks()
{
return m_ticks;
}
@ -224,7 +223,7 @@ inline uint64 &DateTime::ticks()
/*!
* \brief Returns the number of ticks which represent the value of the current instance.
*/
constexpr inline uint64 DateTime::totalTicks() const
constexpr inline std::uint64_t DateTime::totalTicks() const
{
return m_ticks;
}

View File

@ -1,9 +1,9 @@
#ifndef CHRONO_UTILITIES_TIMESPAN_H
#define CHRONO_UTILITIES_TIMESPAN_H
#include "../conversion/types.h"
#include "../global.h"
#include <cstdint>
#include <functional>
#include <limits>
#include <string>
@ -30,7 +30,7 @@ class CPP_UTILITIES_EXPORT TimeSpan {
public:
explicit constexpr TimeSpan();
explicit constexpr TimeSpan(int64 ticks);
explicit constexpr TimeSpan(std::int64_t ticks);
static constexpr TimeSpan fromMilliseconds(double milliseconds);
static constexpr TimeSpan fromSeconds(double seconds);
@ -42,8 +42,8 @@ public:
static constexpr TimeSpan negativeInfinity();
static constexpr TimeSpan infinity();
int64 &ticks();
constexpr int64 totalTicks() const;
std::int64_t &ticks();
constexpr std::int64_t totalTicks() const;
constexpr double totalMicroseconds() const;
constexpr double totalMilliseconds() const;
constexpr double totalSeconds() const;
@ -77,16 +77,16 @@ public:
constexpr bool isNegativeInfinity() const;
constexpr bool isInfinity() const;
static constexpr int64 nanosecondsPerTick = 100uL;
static constexpr int64 ticksPerMicrosecond = 10uL;
static constexpr int64 ticksPerMillisecond = 10000uL;
static constexpr int64 ticksPerSecond = 10000000uL;
static constexpr int64 ticksPerMinute = 600000000uL;
static constexpr int64 ticksPerHour = 36000000000uL;
static constexpr int64 ticksPerDay = 864000000000uL;
static constexpr std::int64_t nanosecondsPerTick = 100uL;
static constexpr std::int64_t ticksPerMicrosecond = 10uL;
static constexpr std::int64_t ticksPerMillisecond = 10000uL;
static constexpr std::int64_t ticksPerSecond = 10000000uL;
static constexpr std::int64_t ticksPerMinute = 600000000uL;
static constexpr std::int64_t ticksPerHour = 36000000000uL;
static constexpr std::int64_t ticksPerDay = 864000000000uL;
private:
int64 m_ticks;
std::int64_t m_ticks;
};
/*!
@ -100,7 +100,7 @@ constexpr inline TimeSpan::TimeSpan()
/*!
* \brief Constructs a new instance of the TimeSpan class with the specified number of ticks.
*/
constexpr inline TimeSpan::TimeSpan(int64 ticks)
constexpr inline TimeSpan::TimeSpan(std::int64_t ticks)
: m_ticks(ticks)
{
}
@ -110,7 +110,7 @@ constexpr inline TimeSpan::TimeSpan(int64 ticks)
*/
constexpr inline TimeSpan TimeSpan::fromMilliseconds(double milliseconds)
{
return TimeSpan(static_cast<int64>(milliseconds * static_cast<double>(ticksPerMillisecond)));
return TimeSpan(static_cast<std::int64_t>(milliseconds * static_cast<double>(ticksPerMillisecond)));
}
/*!
@ -118,7 +118,7 @@ constexpr inline TimeSpan TimeSpan::fromMilliseconds(double milliseconds)
*/
constexpr inline TimeSpan TimeSpan::fromSeconds(double seconds)
{
return TimeSpan(static_cast<int64>(seconds * static_cast<double>(ticksPerSecond)));
return TimeSpan(static_cast<std::int64_t>(seconds * static_cast<double>(ticksPerSecond)));
}
/*!
@ -126,7 +126,7 @@ constexpr inline TimeSpan TimeSpan::fromSeconds(double seconds)
*/
constexpr inline TimeSpan TimeSpan::fromMinutes(double minutes)
{
return TimeSpan(static_cast<int64>(minutes * static_cast<double>(ticksPerMinute)));
return TimeSpan(static_cast<std::int64_t>(minutes * static_cast<double>(ticksPerMinute)));
}
/*!
@ -134,7 +134,7 @@ constexpr inline TimeSpan TimeSpan::fromMinutes(double minutes)
*/
constexpr inline TimeSpan TimeSpan::fromHours(double hours)
{
return TimeSpan(static_cast<int64>(hours * static_cast<double>(ticksPerHour)));
return TimeSpan(static_cast<std::int64_t>(hours * static_cast<double>(ticksPerHour)));
}
/*!
@ -142,7 +142,7 @@ constexpr inline TimeSpan TimeSpan::fromHours(double hours)
*/
constexpr inline TimeSpan TimeSpan::fromDays(double days)
{
return TimeSpan(static_cast<int64>(days * static_cast<double>(ticksPerDay)));
return TimeSpan(static_cast<std::int64_t>(days * static_cast<double>(ticksPerDay)));
}
/*!
@ -177,7 +177,7 @@ constexpr inline TimeSpan TimeSpan::infinity()
/*!
* \brief Returns a mutable reference to the total ticks.
*/
inline int64 &TimeSpan::ticks()
inline std::int64_t &TimeSpan::ticks()
{
return m_ticks;
}
@ -185,7 +185,7 @@ inline int64 &TimeSpan::ticks()
/*!
* \brief Returns the number of ticks that represent the value of the current TimeSpan class.
*/
constexpr inline int64 TimeSpan::totalTicks() const
constexpr inline std::int64_t TimeSpan::totalTicks() const
{
return m_ticks;
}

View File

@ -1,10 +1,10 @@
#ifndef CONVERSION_UTILITIES_BINARY_CONVERSION_H
#define CONVERSION_UTILITIES_BINARY_CONVERSION_H
#include "./types.h"
#include "../global.h"
#include <cstdint>
// detect byte order according to __BYTE_ORDER__
#if defined(__BYTE_ORDER__)
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
@ -98,33 +98,33 @@ namespace LE {
/*!
* \brief Returns the 8.8 fixed point representation converted from the specified 32-bit floating point number.
*/
CPP_UTILITIES_EXPORT constexpr uint16 toFixed8(float32 float32value)
CPP_UTILITIES_EXPORT constexpr std::uint16_t toFixed8(float float32value)
{
return static_cast<uint16>(float32value * 256.0f);
return static_cast<std::uint16_t>(float32value * 256.0f);
}
/*!
* \brief Returns a 32-bit floating point number converted from the specified 8.8 fixed point representation.
*/
CPP_UTILITIES_EXPORT constexpr float32 toFloat32(uint16 fixed8value)
CPP_UTILITIES_EXPORT constexpr float toFloat32(std::uint16_t fixed8value)
{
return static_cast<float32>(fixed8value) / 256.0f;
return static_cast<float>(fixed8value) / 256.0f;
}
/*!
* \brief Returns the 16.16 fixed point representation converted from the specified 32-bit floating point number.
*/
CPP_UTILITIES_EXPORT constexpr uint32 toFixed16(float32 float32value)
CPP_UTILITIES_EXPORT constexpr std::uint32_t toFixed16(float float32value)
{
return static_cast<uint32>(float32value * 65536.0f);
return static_cast<std::uint32_t>(float32value * 65536.0f);
}
/*!
* \brief Returns a 32-bit floating point number converted from the specified 16.16 fixed point representation.
*/
CPP_UTILITIES_EXPORT constexpr float32 toFloat32(uint32 fixed16value)
CPP_UTILITIES_EXPORT constexpr float toFloat32(std::uint32_t fixed16value)
{
return static_cast<float32>(fixed16value) / 65536.0f;
return static_cast<float>(fixed16value) / 65536.0f;
}
/*!
@ -132,7 +132,7 @@ CPP_UTILITIES_EXPORT constexpr float32 toFloat32(uint32 fixed16value)
* \remarks Synchsafe integers appear in ID3 tags that are attached to an MP3 file.
* \sa <a href="http://id3.org/id3v2.4.0-structure">ID3 tag version 2.4.0 - Main Structure</a>
*/
CPP_UTILITIES_EXPORT constexpr uint32 toSynchsafeInt(uint32 normalInt)
CPP_UTILITIES_EXPORT constexpr std::uint32_t toSynchsafeInt(std::uint32_t normalInt)
{
return ((normalInt & 0x0000007fu)) | ((normalInt & 0x00003f80u) << 1) | ((normalInt & 0x001fc000u) << 2) | ((normalInt & 0x0fe00000u) << 3);
}
@ -142,7 +142,7 @@ CPP_UTILITIES_EXPORT constexpr uint32 toSynchsafeInt(uint32 normalInt)
* \remarks Synchsafe integers appear in ID3 tags that are attached to an MP3 file.
* \sa <a href="http://id3.org/id3v2.4.0-structure">ID3 tag version 2.4.0 - Main Structure</a>
*/
CPP_UTILITIES_EXPORT constexpr uint32 toNormalInt(uint32 synchsafeInt)
CPP_UTILITIES_EXPORT constexpr std::uint32_t toNormalInt(std::uint32_t synchsafeInt)
{
return ((synchsafeInt & 0x0000007fu)) | ((synchsafeInt & 0x00007f00u) >> 1) | ((synchsafeInt & 0x007f0000u) >> 2)
| ((synchsafeInt & 0x7f000000u) >> 3);
@ -151,7 +151,7 @@ CPP_UTILITIES_EXPORT constexpr uint32 toNormalInt(uint32 synchsafeInt)
/*!
* \brief Swaps the byte order of the specified 16-bit unsigned integer.
*/
CPP_UTILITIES_EXPORT constexpr uint16 swapOrder(uint16 value)
CPP_UTILITIES_EXPORT constexpr std::uint16_t swapOrder(std::uint16_t value)
{
return ((value >> 8) & 0x00FF) | ((value << 8) & 0xFF00);
}
@ -159,7 +159,7 @@ CPP_UTILITIES_EXPORT constexpr uint16 swapOrder(uint16 value)
/*!
* \brief Swaps the byte order of the specified 32-bit unsigned integer.
*/
CPP_UTILITIES_EXPORT constexpr uint32 swapOrder(uint32 value)
CPP_UTILITIES_EXPORT constexpr std::uint32_t swapOrder(std::uint32_t value)
{
return (value >> 24) | ((value & 0x00FF0000) >> 8) | ((value & 0x0000FF00) << 8) | (value << 24);
}
@ -167,7 +167,7 @@ CPP_UTILITIES_EXPORT constexpr uint32 swapOrder(uint32 value)
/*!
* \brief Swaps the byte order of the specified 64-bit unsigned integer.
*/
CPP_UTILITIES_EXPORT constexpr uint64 swapOrder(uint64 value)
CPP_UTILITIES_EXPORT constexpr std::uint64_t swapOrder(std::uint64_t value)
{
return (value >> (7 * 8)) | ((value & 0x00FF000000000000) >> (5 * 8)) | ((value & 0x0000FF0000000000) >> (3 * 8))
| ((value & 0x000000FF00000000) >> (1 * 8)) | ((value & 0x00000000FF000000) << (1 * 8)) | ((value & 0x0000000000FF0000) << (3 * 8))

View File

@ -2,136 +2,136 @@
#error "Do not include binaryconversionprivate.h directly."
#else
#include "./types.h"
#include "../global.h"
#include <cstdint>
/*!
* \brief Returns a 16-bit signed integer converted from two bytes at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT constexpr int16 toInt16(const char *value)
CPP_UTILITIES_EXPORT constexpr std::int16_t toInt16(const char *value)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
return (static_cast<int16>(value[0]) << 8 & 0xFF00) | (static_cast<int16>(value[1]) & 0x00FF);
return (static_cast<std::int16_t>(value[0]) << 8 & 0xFF00) | (static_cast<std::int16_t>(value[1]) & 0x00FF);
#else
return (static_cast<int16>(value[1]) << 8 & 0xFF00) | (static_cast<int16>(value[0]) & 0x00FF);
return (static_cast<std::int16_t>(value[1]) << 8 & 0xFF00) | (static_cast<std::int16_t>(value[0]) & 0x00FF);
#endif
}
/*!
* \brief Returns a 16-bit unsigned integer converted from two bytes at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT constexpr uint16 toUInt16(const char *value)
CPP_UTILITIES_EXPORT constexpr std::uint16_t toUInt16(const char *value)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
return (static_cast<uint16>(value[0]) << 8 & 0xFF00) | (static_cast<uint16>(value[1]) & 0x00FF);
return (static_cast<std::uint16_t>(value[0]) << 8 & 0xFF00) | (static_cast<std::uint16_t>(value[1]) & 0x00FF);
#else
return (static_cast<uint16>(value[1]) << 8 & 0xFF00) | (static_cast<uint16>(value[0]) & 0x00FF);
return (static_cast<std::uint16_t>(value[1]) << 8 & 0xFF00) | (static_cast<std::uint16_t>(value[0]) & 0x00FF);
#endif
}
/*!
* \brief Returns a 32-bit signed integer converted from four bytes at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT constexpr int32 toInt32(const char *value)
CPP_UTILITIES_EXPORT constexpr std::int32_t toInt32(const char *value)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
return (static_cast<int32>(value[0]) << 24 & 0xFF000000) | (static_cast<int32>(value[1]) << 16 & 0x00FF0000)
| (static_cast<int32>(value[2]) << 8 & 0x0000FF00) | (static_cast<int32>(value[3]) & 0x000000FF);
return (static_cast<std::int32_t>(value[0]) << 24 & 0xFF000000) | (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
return (static_cast<int32>(value[3]) << 24 & 0xFF000000) | (static_cast<int32>(value[2]) << 16 & 0x00FF0000)
| (static_cast<int32>(value[1]) << 8 & 0x0000FF00) | (static_cast<int32>(value[0]) & 0x000000FF);
return (static_cast<std::int32_t>(value[3]) << 24 & 0xFF000000) | (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
}
/*!
* \brief Returns a 32-bit unsigned integer converted from three bytes at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT constexpr uint32 toUInt24(const char *value)
CPP_UTILITIES_EXPORT constexpr std::uint32_t toUInt24(const char *value)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
return (static_cast<uint32>(value[0]) << 16 & 0x00FF0000) | (static_cast<uint32>(value[1]) << 8 & 0x0000FF00)
| (static_cast<uint32>(value[2]) & 0x000000FF);
return (static_cast<std::uint32_t>(value[0]) << 16 & 0x00FF0000) | (static_cast<std::uint32_t>(value[1]) << 8 & 0x0000FF00)
| (static_cast<std::uint32_t>(value[2]) & 0x000000FF);
#else
return (static_cast<uint32>(value[2]) << 16 & 0x00FF0000) | (static_cast<uint32>(value[1]) << 8 & 0x0000FF00)
| (static_cast<uint32>(value[0]) & 0x000000FF);
return (static_cast<std::uint32_t>(value[2]) << 16 & 0x00FF0000) | (static_cast<std::uint32_t>(value[1]) << 8 & 0x0000FF00)
| (static_cast<std::uint32_t>(value[0]) & 0x000000FF);
#endif
}
/*!
* \brief Returns a 32-bit unsigned integer converted from four bytes at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT constexpr uint32 toUInt32(const char *value)
CPP_UTILITIES_EXPORT constexpr std::uint32_t toUInt32(const char *value)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
return (static_cast<uint32>(value[0]) << 24 & 0xFF000000) | (static_cast<uint32>(value[1]) << 16 & 0x00FF0000)
| (static_cast<uint32>(value[2]) << 8 & 0x0000FF00) | (static_cast<uint32>(value[3]) & 0x000000FF);
return (static_cast<std::uint32_t>(value[0]) << 24 & 0xFF000000) | (static_cast<std::uint32_t>(value[1]) << 16 & 0x00FF0000)
| (static_cast<std::uint32_t>(value[2]) << 8 & 0x0000FF00) | (static_cast<std::uint32_t>(value[3]) & 0x000000FF);
#else
return (static_cast<uint32>(value[3]) << 24 & 0xFF000000) | (static_cast<uint32>(value[2]) << 16 & 0x00FF0000)
| (static_cast<uint32>(value[1]) << 8 & 0x0000FF00) | (static_cast<uint32>(value[0]) & 0x000000FF);
return (static_cast<std::uint32_t>(value[3]) << 24 & 0xFF000000) | (static_cast<std::uint32_t>(value[2]) << 16 & 0x00FF0000)
| (static_cast<std::uint32_t>(value[1]) << 8 & 0x0000FF00) | (static_cast<std::uint32_t>(value[0]) & 0x000000FF);
#endif
}
/*!
* \brief Returns a 64-bit signed integer converted from eight bytes at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT constexpr int64 toInt64(const char *value)
CPP_UTILITIES_EXPORT constexpr std::int64_t toInt64(const char *value)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
return (static_cast<int64>(value[0]) << 56 & 0xFF00000000000000) | (static_cast<int64>(value[1]) << 48 & 0x00FF000000000000)
| (static_cast<int64>(value[2]) << 40 & 0x0000FF0000000000) | (static_cast<int64>(value[3]) << 32 & 0x000000FF00000000)
| (static_cast<int64>(value[4]) << 24 & 0x00000000FF000000) | (static_cast<int64>(value[5]) << 16 & 0x0000000000FF0000)
| (static_cast<int64>(value[6]) << 8 & 0x000000000000FF00) | (static_cast<int64>(value[7]) & 0x00000000000000FF);
return (static_cast<std::int64_t>(value[0]) << 56 & 0xFF00000000000000) | (static_cast<std::int64_t>(value[1]) << 48 & 0x00FF000000000000)
| (static_cast<std::int64_t>(value[2]) << 40 & 0x0000FF0000000000) | (static_cast<std::int64_t>(value[3]) << 32 & 0x000000FF00000000)
| (static_cast<std::int64_t>(value[4]) << 24 & 0x00000000FF000000) | (static_cast<std::int64_t>(value[5]) << 16 & 0x0000000000FF0000)
| (static_cast<std::int64_t>(value[6]) << 8 & 0x000000000000FF00) | (static_cast<std::int64_t>(value[7]) & 0x00000000000000FF);
#else
return (static_cast<int64>(value[7]) << 56 & 0xFF00000000000000) | (static_cast<int64>(value[6]) << 48 & 0x00FF000000000000)
| (static_cast<int64>(value[5]) << 40 & 0x0000FF0000000000) | (static_cast<int64>(value[4]) << 32 & 0x000000FF00000000)
| (static_cast<int64>(value[3]) << 24 & 0x00000000FF000000) | (static_cast<int64>(value[2]) << 16 & 0x0000000000FF0000)
| (static_cast<int64>(value[1]) << 8 & 0x000000000000FF00) | (static_cast<int64>(value[0]) & 0x00000000000000FF);
return (static_cast<std::int64_t>(value[7]) << 56 & 0xFF00000000000000) | (static_cast<std::int64_t>(value[6]) << 48 & 0x00FF000000000000)
| (static_cast<std::int64_t>(value[5]) << 40 & 0x0000FF0000000000) | (static_cast<std::int64_t>(value[4]) << 32 & 0x000000FF00000000)
| (static_cast<std::int64_t>(value[3]) << 24 & 0x00000000FF000000) | (static_cast<std::int64_t>(value[2]) << 16 & 0x0000000000FF0000)
| (static_cast<std::int64_t>(value[1]) << 8 & 0x000000000000FF00) | (static_cast<std::int64_t>(value[0]) & 0x00000000000000FF);
#endif
}
/*!
* \brief Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT constexpr uint64 toUInt64(const char *value)
CPP_UTILITIES_EXPORT constexpr std::uint64_t toUInt64(const char *value)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
return (static_cast<uint64>(value[0]) << 56 & 0xFF00000000000000) | (static_cast<uint64>(value[1]) << 48 & 0x00FF000000000000)
| (static_cast<uint64>(value[2]) << 40 & 0x0000FF0000000000) | (static_cast<uint64>(value[3]) << 32 & 0x000000FF00000000)
| (static_cast<uint64>(value[4]) << 24 & 0x00000000FF000000) | (static_cast<uint64>(value[5]) << 16 & 0x0000000000FF0000)
| (static_cast<uint64>(value[6]) << 8 & 0x000000000000FF00) | (static_cast<uint64>(value[7]) & 0x00000000000000FF);
return (static_cast<std::uint64_t>(value[0]) << 56 & 0xFF00000000000000) | (static_cast<std::uint64_t>(value[1]) << 48 & 0x00FF000000000000)
| (static_cast<std::uint64_t>(value[2]) << 40 & 0x0000FF0000000000) | (static_cast<std::uint64_t>(value[3]) << 32 & 0x000000FF00000000)
| (static_cast<std::uint64_t>(value[4]) << 24 & 0x00000000FF000000) | (static_cast<std::uint64_t>(value[5]) << 16 & 0x0000000000FF0000)
| (static_cast<std::uint64_t>(value[6]) << 8 & 0x000000000000FF00) | (static_cast<std::uint64_t>(value[7]) & 0x00000000000000FF);
#else
return (static_cast<uint64>(value[7]) << 56 & 0xFF00000000000000) | (static_cast<uint64>(value[6]) << 48 & 0x00FF000000000000)
| (static_cast<uint64>(value[5]) << 40 & 0x0000FF0000000000) | (static_cast<uint64>(value[4]) << 32 & 0x000000FF00000000)
| (static_cast<uint64>(value[3]) << 24 & 0x00000000FF000000) | (static_cast<uint64>(value[2]) << 16 & 0x0000000000FF0000)
| (static_cast<uint64>(value[1]) << 8 & 0x000000000000FF00) | (static_cast<uint64>(value[0]) & 0x00000000000000FF);
return (static_cast<std::uint64_t>(value[7]) << 56 & 0xFF00000000000000) | (static_cast<std::uint64_t>(value[6]) << 48 & 0x00FF000000000000)
| (static_cast<std::uint64_t>(value[5]) << 40 & 0x0000FF0000000000) | (static_cast<std::uint64_t>(value[4]) << 32 & 0x000000FF00000000)
| (static_cast<std::uint64_t>(value[3]) << 24 & 0x00000000FF000000) | (static_cast<std::uint64_t>(value[2]) << 16 & 0x0000000000FF0000)
| (static_cast<std::uint64_t>(value[1]) << 8 & 0x000000000000FF00) | (static_cast<std::uint64_t>(value[0]) & 0x00000000000000FF);
#endif
}
/*!
* \brief Returns a 32-bit floating point number converted from four bytes at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT inline float32 toFloat32(const char *value)
CPP_UTILITIES_EXPORT inline float toFloat32(const char *value)
{
const int32 val = toInt32(value);
const char *const c = reinterpret_cast<const char *>(&val);
return *reinterpret_cast<const float32 *>(c);
const auto val = toInt32(value);
const auto *const c = reinterpret_cast<const char *>(&val);
return *reinterpret_cast<const float *>(c);
}
/*!
* \brief Returns a 64-bit floating point number converted from eight bytes at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT inline float64 toFloat64(const char *value)
CPP_UTILITIES_EXPORT inline double toFloat64(const char *value)
{
const int64 val = toInt64(value);
const char *const c = reinterpret_cast<const char *>(&val);
return *reinterpret_cast<const float64 *const>(c);
const auto val = toInt64(value);
const auto *const c = reinterpret_cast<const char *>(&val);
return *reinterpret_cast<const double *const>(c);
}
/*!
* \brief Stores the specified 16-bit signed integer value at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT inline void getBytes(int16 value, char *outputbuffer)
CPP_UTILITIES_EXPORT inline void getBytes(std::int16_t value, char *outputbuffer)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
outputbuffer[0] = static_cast<char>((value >> 8) & 0xFF);
@ -145,7 +145,7 @@ CPP_UTILITIES_EXPORT inline void getBytes(int16 value, char *outputbuffer)
/*!
* \brief Stores the specified 16-bit unsigned integer value at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT inline void getBytes(uint16 value, char *outputbuffer)
CPP_UTILITIES_EXPORT inline void getBytes(std::uint16_t value, char *outputbuffer)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
outputbuffer[0] = static_cast<char>((value >> 8) & 0xFF);
@ -160,7 +160,7 @@ CPP_UTILITIES_EXPORT inline void getBytes(uint16 value, char *outputbuffer)
* \brief Stores the specified 24-bit unsigned integer value at a specified position in a char array.
* \remarks Ignores the most significant byte.
*/
CPP_UTILITIES_EXPORT inline void getBytes24(uint32 value, char *outputbuffer)
CPP_UTILITIES_EXPORT inline void getBytes24(std::uint32_t value, char *outputbuffer)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
outputbuffer[0] = static_cast<char>((value >> 16) & 0xFF);
@ -176,7 +176,7 @@ CPP_UTILITIES_EXPORT inline void getBytes24(uint32 value, char *outputbuffer)
/*!
* \brief Stores the specified 32-bit signed integer value at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT inline void getBytes(int32 value, char *outputbuffer)
CPP_UTILITIES_EXPORT inline void getBytes(std::int32_t value, char *outputbuffer)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
outputbuffer[0] = static_cast<char>((value >> 24) & 0xFF);
@ -194,7 +194,7 @@ CPP_UTILITIES_EXPORT inline void getBytes(int32 value, char *outputbuffer)
/*!
* \brief Stores the specified 32-bit signed integer value at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT inline void getBytes(uint32 value, char *outputbuffer)
CPP_UTILITIES_EXPORT inline void getBytes(std::uint32_t value, char *outputbuffer)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
outputbuffer[0] = static_cast<char>((value >> 24) & 0xFF);
@ -212,7 +212,7 @@ CPP_UTILITIES_EXPORT inline void getBytes(uint32 value, char *outputbuffer)
/*!
* \brief Stores the specified 64-bit signed integer value at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT inline void getBytes(int64 value, char *outputbuffer)
CPP_UTILITIES_EXPORT inline void getBytes(std::int64_t value, char *outputbuffer)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
outputbuffer[0] = static_cast<char>((value >> 56) & 0xFF);
@ -238,7 +238,7 @@ CPP_UTILITIES_EXPORT inline void getBytes(int64 value, char *outputbuffer)
/*!
* \brief Stores the specified 64-bit unsigned integer value at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT inline void getBytes(uint64 value, char *outputbuffer)
CPP_UTILITIES_EXPORT inline void getBytes(std::uint64_t value, char *outputbuffer)
{
#if CONVERSION_UTILITIES_BINARY_CONVERSION_INTERNAL == 0
outputbuffer[0] = static_cast<char>((value >> 56) & 0xFF);
@ -264,20 +264,20 @@ CPP_UTILITIES_EXPORT inline void getBytes(uint64 value, char *outputbuffer)
/*!
* \brief Stores the specified 32-bit floating point value at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT inline void getBytes(float32 value, char *outputbuffer)
CPP_UTILITIES_EXPORT inline void getBytes(float value, char *outputbuffer)
{
char *c = reinterpret_cast<char *>(&value);
int32 i = *reinterpret_cast<int32 *>(c);
auto *c = reinterpret_cast<char *>(&value);
auto i = *reinterpret_cast<std::int32_t *>(c);
getBytes(i, outputbuffer);
}
/*!
* \brief Stores the specified 64-bit floating point value at a specified position in a char array.
*/
CPP_UTILITIES_EXPORT inline void getBytes(float64 value, char *outputbuffer)
CPP_UTILITIES_EXPORT inline void getBytes(double value, char *outputbuffer)
{
char *c = reinterpret_cast<char *>(&value);
int64 i = *reinterpret_cast<int64 *>(c);
auto *c = reinterpret_cast<char *>(&value);
auto i = *reinterpret_cast<std::int64_t *>(c);
getBytes(i, outputbuffer);
}

View File

@ -250,7 +250,7 @@ void truncateString(string &str, char terminationChar)
*
* The unit with appropriate binary prefix will be appended.
*/
string dataSizeToString(uint64 sizeInByte, bool includeByte)
string dataSizeToString(std::uint64_t sizeInByte, bool includeByte)
{
stringstream res(stringstream::in | stringstream::out);
res.setf(ios::fixed, ios::floatfield);
@ -321,13 +321,13 @@ const char base64Pad = '=';
* \brief Encodes the specified \a data to Base64.
* \sa [RFC 4648](http://www.ietf.org/rfc/rfc4648.txt)
*/
string encodeBase64(const byte *data, uint32 dataSize)
string encodeBase64(const std::uint8_t *data, std::uint32_t dataSize)
{
string encoded;
byte mod = dataSize % 3;
std::uint8_t mod = dataSize % 3;
encoded.reserve(((dataSize / 3) + (mod > 0)) * 4);
uint32 temp;
for (const byte *end = --data + dataSize - mod; data != end;) {
std::uint32_t temp;
for (const std::uint8_t *end = --data + dataSize - mod; data != end;) {
temp = *++data << 16;
temp |= *++data << 8;
temp |= *++data;
@ -361,12 +361,12 @@ string encodeBase64(const byte *data, uint32 dataSize)
* \throw Throws a ConversionException if the specified string is no valid Base64.
* \sa [RFC 4648](http://www.ietf.org/rfc/rfc4648.txt)
*/
pair<unique_ptr<byte[]>, uint32> decodeBase64(const char *encodedStr, const uint32 strSize)
pair<unique_ptr<std::uint8_t[]>, std::uint32_t> decodeBase64(const char *encodedStr, const std::uint32_t strSize)
{
if (strSize % 4) {
throw ConversionException("invalid size of base64");
}
uint32 decodedSize = (strSize / 4) * 3;
std::uint32_t decodedSize = (strSize / 4) * 3;
const char *const end = encodedStr + strSize;
if (strSize) {
if (*(end - 1) == base64Pad) {
@ -376,11 +376,11 @@ pair<unique_ptr<byte[]>, uint32> decodeBase64(const char *encodedStr, const uint
--decodedSize;
}
}
auto buffer = make_unique<byte[]>(decodedSize);
auto buffer = make_unique<std::uint8_t[]>(decodedSize);
auto *iter = buffer.get() - 1;
while (encodedStr < end) {
int32 temp = 0;
for (byte quantumPos = 0; quantumPos < 4; ++quantumPos, ++encodedStr) {
std::int32_t temp = 0;
for (std::uint8_t quantumPos = 0; quantumPos < 4; ++quantumPos, ++encodedStr) {
temp <<= 6;
if (*encodedStr >= 'A' && *encodedStr <= 'Z') {
temp |= *encodedStr - 'A';

View File

@ -621,10 +621,10 @@ template <typename T> std::string interpretIntegerAsString(T integer, int startO
return std::string(buffer + startOffset, sizeof(T) - startOffset);
}
CPP_UTILITIES_EXPORT std::string dataSizeToString(uint64 sizeInByte, bool includeByte = false);
CPP_UTILITIES_EXPORT std::string dataSizeToString(std::uint64_t sizeInByte, bool includeByte = false);
CPP_UTILITIES_EXPORT std::string bitrateToString(double speedInKbitsPerSecond, bool useByteInsteadOfBits = false);
CPP_UTILITIES_EXPORT std::string encodeBase64(const byte *data, uint32 dataSize);
CPP_UTILITIES_EXPORT std::pair<std::unique_ptr<byte[]>, uint32> decodeBase64(const char *encodedStr, const uint32 strSize);
CPP_UTILITIES_EXPORT std::string encodeBase64(const std::uint8_t *data, std::uint32_t dataSize);
CPP_UTILITIES_EXPORT std::pair<std::unique_ptr<std::uint8_t[]>, std::uint32_t> decodeBase64(const char *encodedStr, const std::uint32_t strSize);
} // namespace ConversionUtilities
#endif // CONVERSION_UTILITIES_STRINGCONVERSION_H

View File

@ -1,74 +0,0 @@
#ifndef CONVERSION_UTILITIES_TYPES_H
#define CONVERSION_UTILITIES_TYPES_H
#include <cstdint>
/*!
* \brief signed byte
*/
typedef std::int8_t sbyte;
/*!
* \brief unsigned byte
*/
typedef std::uint8_t byte;
/*!
* \brief signed 16-bit integer
*/
typedef std::int16_t int16;
/*!
* \brief signed 32-bit integer
*/
typedef std::int32_t int32;
/*!
* \brief signed 64-bit integer
*/
typedef std::int64_t int64;
/*!
* \brief signed pointer
*/
typedef std::intptr_t intptr;
/*!
* \brief unsigned 16-bit integer
*/
typedef std::uint16_t uint16;
/*!
* \brief unsigned 32-bit integer
*/
typedef std::uint32_t uint32;
/*!
* \brief unsigned 64-bit integer
*/
typedef std::uint64_t uint64;
/*!
* \brief unsigned pointer
*/
typedef std::uintptr_t uintptr;
#if __SIZEOF_FLOAT__ == 4
/*!
* \brief 32-bit floating point
*/
typedef float float32;
#else
#error "Unable to define float32!"
#endif
#if __SIZEOF_DOUBLE__ == 8
/*!
* \brief 64-bit floating point
*/
typedef double float64;
#else
#error "Unable to define float64!"
#endif
#endif // CONVERSION_UTILITIES_TYPES_H

View File

@ -97,8 +97,8 @@ void BinaryReader::bufferVariableLengthInteger()
{
static constexpr int maxPrefixLength = 8;
int prefixLength = 1;
const byte beg = static_cast<byte>(m_stream->peek());
byte mask = 0x80;
const auto beg = static_cast<std::uint8_t>(m_stream->peek());
std::uint8_t mask = 0x80;
while (prefixLength <= maxPrefixLength && (beg & mask) == 0) {
++prefixLength;
mask >>= 1;
@ -132,7 +132,7 @@ string BinaryReader::readString(size_t length)
* \deprecated This method is likely refactored/removed in v5.
* \todo Refactor/remove in v5.
*/
string BinaryReader::readTerminatedString(byte termination)
string BinaryReader::readTerminatedString(uint8_t termination)
{
stringstream ss(ios_base::in | ios_base::out | ios_base::binary);
ss.exceptions(ios_base::badbit | ios_base::failbit);
@ -153,12 +153,12 @@ string BinaryReader::readTerminatedString(byte termination)
* \deprecated This method is likely refactored/removed in v5.
* \todo Refactor/remove in v5.
*/
string BinaryReader::readTerminatedString(size_t maxBytesToRead, byte termination)
string BinaryReader::readTerminatedString(size_t maxBytesToRead, std::uint8_t termination)
{
unique_ptr<char[]> buff = make_unique<char[]>(maxBytesToRead);
for (char *i = buff.get(), *end = i + maxBytesToRead; i < end; ++i) {
m_stream->get(*i);
if (*(reinterpret_cast<byte *>(i)) == termination) {
if (*(reinterpret_cast<std::uint8_t *>(i)) == termination) {
return string(buff.get(), i - buff.get());
}
}
@ -175,7 +175,7 @@ string BinaryReader::readTerminatedString(size_t maxBytesToRead, byte terminatio
* \deprecated This method is likely refactored/removed in v5.
* \todo Refactor/remove in v5.
*/
string BinaryReader::readMultibyteTerminatedStringBE(uint16 termination)
string BinaryReader::readMultibyteTerminatedStringBE(std::uint16_t termination)
{
stringstream ss(ios_base::in | ios_base::out | ios_base::binary);
ss.exceptions(ios_base::badbit | ios_base::failbit);
@ -202,7 +202,7 @@ string BinaryReader::readMultibyteTerminatedStringBE(uint16 termination)
* \deprecated This method is likely refactored/removed in v5.
* \todo Refactor/remove in v5.
*/
string BinaryReader::readMultibyteTerminatedStringLE(uint16 termination)
string BinaryReader::readMultibyteTerminatedStringLE(std::uint16_t termination)
{
stringstream ss(ios_base::in | ios_base::out | ios_base::binary);
ss.exceptions(ios_base::badbit | ios_base::failbit);
@ -231,7 +231,7 @@ string BinaryReader::readMultibyteTerminatedStringLE(uint16 termination)
* \deprecated This method is likely refactored/removed in v5.
* \todo Refactor/remove in v5.
*/
string BinaryReader::readMultibyteTerminatedStringBE(std::size_t maxBytesToRead, uint16 termination)
string BinaryReader::readMultibyteTerminatedStringBE(std::size_t maxBytesToRead, std::uint16_t termination)
{
unique_ptr<char[]> buff = make_unique<char[]>(maxBytesToRead);
char *delimChars = m_buffer;
@ -258,7 +258,7 @@ string BinaryReader::readMultibyteTerminatedStringBE(std::size_t maxBytesToRead,
* \deprecated This method is likely refactored/removed in v5.
* \todo Refactor/remove in v5.
*/
string BinaryReader::readMultibyteTerminatedStringLE(std::size_t maxBytesToRead, uint16 termination)
string BinaryReader::readMultibyteTerminatedStringLE(std::size_t maxBytesToRead, std::uint16_t termination)
{
unique_ptr<char[]> buff = make_unique<char[]>(maxBytesToRead);
char *delimChars = m_buffer;
@ -281,11 +281,11 @@ string BinaryReader::readMultibyteTerminatedStringLE(std::size_t maxBytesToRead,
* \remarks Ogg compatible version
* \sa <a href="http://en.wikipedia.org/wiki/Cyclic_redundancy_check">Cyclic redundancy check - Wikipedia</a>
*/
uint32 BinaryReader::readCrc32(size_t length)
std::uint32_t BinaryReader::readCrc32(size_t length)
{
uint32 crc = 0x00;
for (uint32 i = 0; i < length; ++i) {
crc = (crc << 8) ^ crc32Table[((crc >> 24) & 0xff) ^ static_cast<byte>(m_stream->get())];
std::uint32_t crc = 0x00;
for (std::uint32_t i = 0; i < length; ++i) {
crc = (crc << 8) ^ crc32Table[((crc >> 24) & 0xff) ^ static_cast<std::uint8_t>(m_stream->get())];
}
return crc;
}
@ -298,11 +298,11 @@ uint32 BinaryReader::readCrc32(size_t length)
* \remarks Ogg compatible version
* \sa <a href="http://en.wikipedia.org/wiki/Cyclic_redundancy_check">Cyclic redundancy check - Wikipedia</a>
*/
uint32 BinaryReader::computeCrc32(const char *buffer, size_t length)
std::uint32_t BinaryReader::computeCrc32(const char *buffer, size_t length)
{
uint32 crc = 0x00;
std::uint32_t crc = 0x00;
for (const char *i = buffer, *end = buffer + length; i != end; ++i) {
crc = (crc << 8) ^ crc32Table[((crc >> 24) & 0xff) ^ static_cast<byte>(*i)];
crc = (crc << 8) ^ crc32Table[((crc >> 24) & 0xff) ^ static_cast<std::uint8_t>(*i)];
}
return crc;
}
@ -312,7 +312,7 @@ uint32 BinaryReader::computeCrc32(const char *buffer, size_t length)
* \remarks Internally used by readCrc32() method.
* \sa readCrc32()
*/
const uint32 BinaryReader::crc32Table[] = { 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
const std::uint32_t BinaryReader::crc32Table[] = { 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005,
0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9,
0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd,
0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81,

View File

@ -27,72 +27,72 @@ public:
bool canRead() const;
std::istream::pos_type readStreamsize();
void read(char *buffer, std::streamsize length);
void read(byte *buffer, std::streamsize length);
void read(std::uint8_t *buffer, std::streamsize length);
void read(std::vector<char> &buffer, std::streamsize length);
int16 readInt16BE();
uint16 readUInt16BE();
int32 readInt24BE();
uint32 readUInt24BE();
int32 readInt32BE();
uint32 readUInt32BE();
int64 readInt40BE();
uint64 readUInt40BE();
int64 readInt56BE();
uint64 readUInt56BE();
int64 readInt64BE();
uint64 readUInt64BE();
uint64 readVariableLengthUIntBE();
float32 readFloat32BE();
float64 readFloat64BE();
int16 readInt16LE();
uint16 readUInt16LE();
int32 readInt24LE();
uint32 readUInt24LE();
int32 readInt32LE();
uint32 readUInt32LE();
int64 readInt40LE();
uint64 readUInt40LE();
int64 readInt56LE();
uint64 readUInt56LE();
int64 readInt64LE();
uint64 readUInt64LE();
uint64 readVariableLengthUIntLE();
float32 readFloat32LE();
float64 readFloat64LE();
std::int16_t readInt16BE();
std::uint16_t readUInt16BE();
std::int32_t readInt24BE();
std::uint32_t readUInt24BE();
std::int32_t readInt32BE();
std::uint32_t readUInt32BE();
std::int64_t readInt40BE();
std::uint64_t readUInt40BE();
std::int64_t readInt56BE();
std::uint64_t readUInt56BE();
std::int64_t readInt64BE();
std::uint64_t readUInt64BE();
std::uint64_t readVariableLengthUIntBE();
float readFloat32BE();
double readFloat64BE();
std::int16_t readInt16LE();
std::uint16_t readUInt16LE();
std::int32_t readInt24LE();
std::uint32_t readUInt24LE();
std::int32_t readInt32LE();
std::uint32_t readUInt32LE();
std::int64_t readInt40LE();
std::uint64_t readUInt40LE();
std::int64_t readInt56LE();
std::uint64_t readUInt56LE();
std::int64_t readInt64LE();
std::uint64_t readUInt64LE();
std::uint64_t readVariableLengthUIntLE();
float readFloat32LE();
double readFloat64LE();
char readChar();
byte readByte();
std::uint8_t readByte();
bool readBool();
std::string readLengthPrefixedString();
std::string readString(std::size_t length);
std::string readTerminatedString(byte termination = 0);
std::string readTerminatedString(size_t maxBytesToRead, byte termination = 0);
std::string readMultibyteTerminatedStringBE(uint16 termination = 0);
std::string readMultibyteTerminatedStringLE(uint16 termination = 0);
std::string readMultibyteTerminatedStringBE(std::size_t maxBytesToRead, uint16 termination = 0);
std::string readMultibyteTerminatedStringLE(std::size_t maxBytesToRead, uint16 termination = 0);
uint32 readSynchsafeUInt32BE();
float32 readFixed8BE();
float32 readFixed16BE();
uint32 readSynchsafeUInt32LE();
float32 readFixed8LE();
float32 readFixed16LE();
uint32 readCrc32(std::size_t length);
static uint32 computeCrc32(const char *buffer, std::size_t length);
static const uint32 crc32Table[];
std::string readTerminatedString(std::uint8_t termination = 0);
std::string readTerminatedString(size_t maxBytesToRead, std::uint8_t termination = 0);
std::string readMultibyteTerminatedStringBE(std::uint16_t termination = 0);
std::string readMultibyteTerminatedStringLE(std::uint16_t termination = 0);
std::string readMultibyteTerminatedStringBE(std::size_t maxBytesToRead, std::uint16_t termination = 0);
std::string readMultibyteTerminatedStringLE(std::size_t maxBytesToRead, std::uint16_t termination = 0);
std::uint32_t readSynchsafeUInt32BE();
float readFixed8BE();
float readFixed16BE();
std::uint32_t readSynchsafeUInt32LE();
float readFixed8LE();
float readFixed16LE();
std::uint32_t readCrc32(std::size_t length);
static std::uint32_t computeCrc32(const char *buffer, std::size_t length);
static const std::uint32_t crc32Table[];
// declare further overloads for read() to ease use of BinaryReader in templates
void read(char &oneCharacter);
void read(byte &oneByte);
void read(std::uint8_t &oneByte);
void read(bool &oneBool);
void read(std::string &lengthPrefixedString);
void read(int16 &one16BitInt);
void read(uint16 &one16BitUInt);
void read(int32 &one32BitInt);
void read(uint32 &one32BitUInt);
void read(int64 &one64BitInt);
void read(uint64 &one64BitUInt);
void read(float32 &one32BitFloat);
void read(float64 &one64BitFloat);
void read(std::int16_t &one16BitInt);
void read(std::uint16_t &one16BitUInt);
void read(std::int32_t &one32BitInt);
void read(std::uint32_t &one32BitUInt);
void read(std::int64_t &one64BitInt);
void read(std::uint64_t &one64BitUInt);
void read(float &one32BitFloat);
void read(double &one64BitFloat);
private:
void bufferVariableLengthInteger();
@ -195,7 +195,7 @@ inline void BinaryReader::read(char *buffer, std::streamsize length)
/*!
* \brief Reads the specified number of bytes from the stream in the character array.
*/
inline void BinaryReader::read(byte *buffer, std::streamsize length)
inline void BinaryReader::read(uint8_t *buffer, std::streamsize length)
{
m_stream->read(reinterpret_cast<char *>(buffer), length);
}
@ -212,25 +212,25 @@ inline void BinaryReader::read(std::vector<char> &buffer, std::streamsize length
/*!
* \brief Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes.
*/
inline int16 BinaryReader::readInt16BE()
inline std::int16_t BinaryReader::readInt16BE()
{
m_stream->read(m_buffer, sizeof(int16));
m_stream->read(m_buffer, sizeof(std::int16_t));
return ConversionUtilities::BE::toInt16(m_buffer);
}
/*!
* \brief Reads a 16-bit big endian unsigned integer from the current stream and advances the current position of the stream by two bytes.
*/
inline uint16 BinaryReader::readUInt16BE()
inline std::uint16_t BinaryReader::readUInt16BE()
{
m_stream->read(m_buffer, sizeof(uint16));
m_stream->read(m_buffer, sizeof(std::uint16_t));
return ConversionUtilities::BE::toUInt16(m_buffer);
}
/*!
* \brief Reads a 24-bit big endian signed integer from the current stream and advances the current position of the stream by three bytes.
*/
inline int32 BinaryReader::readInt24BE()
inline std::int32_t BinaryReader::readInt24BE()
{
*m_buffer = 0;
m_stream->read(m_buffer + 1, 3);
@ -244,7 +244,7 @@ inline int32 BinaryReader::readInt24BE()
/*!
* \brief Reads a 24-bit big endian unsigned integer from the current stream and advances the current position of the stream by three bytes.
*/
inline uint32 BinaryReader::readUInt24BE()
inline std::uint32_t BinaryReader::readUInt24BE()
{
*m_buffer = 0;
m_stream->read(m_buffer + 1, 3);
@ -254,25 +254,25 @@ inline uint32 BinaryReader::readUInt24BE()
/*!
* \brief Reads a 32-bit big endian signed integer from the current stream and advances the current position of the stream by four bytes.
*/
inline int32 BinaryReader::readInt32BE()
inline std::int32_t BinaryReader::readInt32BE()
{
m_stream->read(m_buffer, sizeof(int32));
m_stream->read(m_buffer, sizeof(std::int32_t));
return ConversionUtilities::BE::toInt32(m_buffer);
}
/*!
* \brief Reads a 32-bit big endian unsigned integer from the current stream and advances the current position of the stream by four bytes.
*/
inline uint32 BinaryReader::readUInt32BE()
inline std::uint32_t BinaryReader::readUInt32BE()
{
m_stream->read(m_buffer, sizeof(uint32));
m_stream->read(m_buffer, sizeof(std::uint32_t));
return ConversionUtilities::BE::toUInt32(m_buffer);
}
/*!
* \brief Reads a 40-bit big endian signed integer from the current stream and advances the current position of the stream by five bytes.
*/
inline int64 BinaryReader::readInt40BE()
inline std::int64_t BinaryReader::readInt40BE()
{
*m_buffer = *(m_buffer + 1) = *(m_buffer + 2) = 0;
m_stream->read(m_buffer + 3, 5);
@ -286,7 +286,7 @@ inline int64 BinaryReader::readInt40BE()
/*!
* \brief Reads a 40-bit big endian unsigned integer from the current stream and advances the current position of the stream by five bytes.
*/
inline uint64 BinaryReader::readUInt40BE()
inline std::uint64_t BinaryReader::readUInt40BE()
{
*m_buffer = *(m_buffer + 1) = *(m_buffer + 2) = 0;
m_stream->read(m_buffer + 3, 5);
@ -296,7 +296,7 @@ inline uint64 BinaryReader::readUInt40BE()
/*!
* \brief Reads a 56-bit big endian signed integer from the current stream and advances the current position of the stream by seven bytes.
*/
inline int64 BinaryReader::readInt56BE()
inline std::int64_t BinaryReader::readInt56BE()
{
*m_buffer = 0;
m_stream->read(m_buffer + 1, 7);
@ -310,7 +310,7 @@ inline int64 BinaryReader::readInt56BE()
/*!
* \brief Reads a 56-bit big endian unsigned integer from the current stream and advances the current position of the stream by seven bytes.
*/
inline uint64 BinaryReader::readUInt56BE()
inline std::uint64_t BinaryReader::readUInt56BE()
{
*m_buffer = 0;
m_stream->read(m_buffer + 1, 7);
@ -320,18 +320,18 @@ inline uint64 BinaryReader::readUInt56BE()
/*!
* \brief Reads a 64-bit big endian signed integer from the current stream and advances the current position of the stream by eight bytes.
*/
inline int64 BinaryReader::readInt64BE()
inline std::int64_t BinaryReader::readInt64BE()
{
m_stream->read(m_buffer, sizeof(int64));
m_stream->read(m_buffer, sizeof(std::int64_t));
return ConversionUtilities::BE::toInt64(m_buffer);
}
/*!
* \brief Reads a 64-bit big endian unsigned integer from the current stream and advances the current position of the stream by eight bytes.
*/
inline uint64 BinaryReader::readUInt64BE()
inline std::uint64_t BinaryReader::readUInt64BE()
{
m_stream->read(m_buffer, sizeof(uint64));
m_stream->read(m_buffer, sizeof(std::uint64_t));
return ConversionUtilities::BE::toUInt64(m_buffer);
}
@ -339,7 +339,7 @@ inline uint64 BinaryReader::readUInt64BE()
* \brief Reads an up to 8 byte long big endian unsigned integer from the current stream and advances the current position of the stream by one to eight byte.
* \throws Throws ConversionException if the size of the integer exceeds the maximum.
*/
inline uint64 BinaryReader::readVariableLengthUIntBE()
inline std::uint64_t BinaryReader::readVariableLengthUIntBE()
{
bufferVariableLengthInteger();
return ConversionUtilities::BE::toUInt64(m_buffer);
@ -348,43 +348,43 @@ inline uint64 BinaryReader::readVariableLengthUIntBE()
/*!
* \brief Reads a 32-bit big endian floating point value from the current stream and advances the current position of the stream by four bytes.
*/
inline float32 BinaryReader::readFloat32BE()
inline float BinaryReader::readFloat32BE()
{
m_stream->read(m_buffer, sizeof(float32));
m_stream->read(m_buffer, sizeof(float));
return ConversionUtilities::BE::toFloat32(m_buffer);
}
/*!
* \brief Reads a 64-bit big endian floating point value from the current stream and advances the current position of the stream by eight bytes.
*/
inline float64 BinaryReader::readFloat64BE()
inline double BinaryReader::readFloat64BE()
{
m_stream->read(m_buffer, sizeof(float64));
m_stream->read(m_buffer, sizeof(double));
return ConversionUtilities::BE::toFloat64(m_buffer);
}
/*!
* \brief Reads a 16-bit little endian signed integer from the current stream and advances the current position of the stream by two bytes.
*/
inline int16 BinaryReader::readInt16LE()
inline std::int16_t BinaryReader::readInt16LE()
{
m_stream->read(m_buffer, sizeof(int16));
m_stream->read(m_buffer, sizeof(std::int16_t));
return ConversionUtilities::LE::toInt16(m_buffer);
}
/*!
* \brief Reads a 16-bit little endian unsigned integer from the current stream and advances the current position of the stream by two bytes.
*/
inline uint16 BinaryReader::readUInt16LE()
inline std::uint16_t BinaryReader::readUInt16LE()
{
m_stream->read(m_buffer, sizeof(uint16));
m_stream->read(m_buffer, sizeof(std::uint16_t));
return ConversionUtilities::LE::toUInt16(m_buffer);
}
/*!
* \brief Reads a 24-bit little endian signed integer from the current stream and advances the current position of the stream by three bytes.
*/
inline int32 BinaryReader::readInt24LE()
inline std::int32_t BinaryReader::readInt24LE()
{
*(m_buffer + 3) = 0;
m_stream->read(m_buffer, 3);
@ -398,7 +398,7 @@ inline int32 BinaryReader::readInt24LE()
/*!
* \brief Reads a 24-bit little endian unsigned integer from the current stream and advances the current position of the stream by three bytes.
*/
inline uint32 BinaryReader::readUInt24LE()
inline std::uint32_t BinaryReader::readUInt24LE()
{
*(m_buffer + 3) = 0;
m_stream->read(m_buffer, 3);
@ -408,25 +408,25 @@ inline uint32 BinaryReader::readUInt24LE()
/*!
* \brief Reads a 32-bit little endian signed integer from the current stream and advances the current position of the stream by four bytes.
*/
inline int32 BinaryReader::readInt32LE()
inline std::int32_t BinaryReader::readInt32LE()
{
m_stream->read(m_buffer, sizeof(int32));
m_stream->read(m_buffer, sizeof(std::int32_t));
return ConversionUtilities::LE::toInt32(m_buffer);
}
/*!
* \brief Reads a 32-bit little endian unsigned integer from the current stream and advances the current position of the stream by four bytes.
*/
inline uint32 BinaryReader::readUInt32LE()
inline std::uint32_t BinaryReader::readUInt32LE()
{
m_stream->read(m_buffer, sizeof(uint32));
m_stream->read(m_buffer, sizeof(std::uint32_t));
return ConversionUtilities::LE::toUInt32(m_buffer);
}
/*!
* \brief Reads a 40-bit little endian signed integer from the current stream and advances the current position of the stream by five bytes.
*/
inline int64 BinaryReader::readInt40LE()
inline std::int64_t BinaryReader::readInt40LE()
{
*(m_buffer + 5) = *(m_buffer + 6) = *(m_buffer + 7) = 0;
m_stream->read(m_buffer, 5);
@ -440,7 +440,7 @@ inline int64 BinaryReader::readInt40LE()
/*!
* \brief Reads a 40-bit little endian unsigned integer from the current stream and advances the current position of the stream by five bytes.
*/
inline uint64 BinaryReader::readUInt40LE()
inline std::uint64_t BinaryReader::readUInt40LE()
{
*(m_buffer + 5) = *(m_buffer + 6) = *(m_buffer + 7) = 0;
m_stream->read(m_buffer, 5);
@ -450,7 +450,7 @@ inline uint64 BinaryReader::readUInt40LE()
/*!
* \brief Reads a 56-bit little endian signed integer from the current stream and advances the current position of the stream by seven bytes.
*/
inline int64 BinaryReader::readInt56LE()
inline std::int64_t BinaryReader::readInt56LE()
{
*(m_buffer + 7) = 0;
m_stream->read(m_buffer, 7);
@ -464,7 +464,7 @@ inline int64 BinaryReader::readInt56LE()
/*!
* \brief Reads a 56-bit little endian unsigned integer from the current stream and advances the current position of the stream by seven bytes.
*/
inline uint64 BinaryReader::readUInt56LE()
inline std::uint64_t BinaryReader::readUInt56LE()
{
*(m_buffer + 7) = 0;
m_stream->read(m_buffer, 7);
@ -474,18 +474,18 @@ inline uint64 BinaryReader::readUInt56LE()
/*!
* \brief Reads a 64-bit little endian signed integer from the current stream and advances the current position of the stream by eight bytes.
*/
inline int64 BinaryReader::readInt64LE()
inline std::int64_t BinaryReader::readInt64LE()
{
m_stream->read(m_buffer, sizeof(int64));
m_stream->read(m_buffer, sizeof(std::int64_t));
return ConversionUtilities::LE::toInt64(m_buffer);
}
/*!
* \brief Reads a 64-bit little endian unsigned integer from the current stream and advances the current position of the stream by eight bytes.
*/
inline uint64 BinaryReader::readUInt64LE()
inline std::uint64_t BinaryReader::readUInt64LE()
{
m_stream->read(m_buffer, sizeof(uint64));
m_stream->read(m_buffer, sizeof(std::uint64_t));
return ConversionUtilities::LE::toUInt64(m_buffer);
}
@ -493,7 +493,7 @@ inline uint64 BinaryReader::readUInt64LE()
* \brief Reads an up to 8 byte long little endian unsigned integer from the current stream and advances the current position of the stream by one to eight byte.
* \throws Throws ConversionException if the size of the integer exceeds the maximum.
*/
inline uint64 BinaryReader::readVariableLengthUIntLE()
inline std::uint64_t BinaryReader::readVariableLengthUIntLE()
{
bufferVariableLengthInteger();
return ConversionUtilities::LE::toUInt64(m_buffer);
@ -502,18 +502,18 @@ inline uint64 BinaryReader::readVariableLengthUIntLE()
/*!
* \brief Reads a 32-bit little endian floating point value from the current stream and advances the current position of the stream by four bytes.
*/
inline float32 BinaryReader::readFloat32LE()
inline float BinaryReader::readFloat32LE()
{
m_stream->read(m_buffer, sizeof(float32));
m_stream->read(m_buffer, sizeof(float));
return ConversionUtilities::LE::toFloat32(m_buffer);
}
/*!
* \brief Reads a 64-bit little endian floating point value from the current stream and advances the current position of the stream by eight bytes.
*/
inline float64 BinaryReader::readFloat64LE()
inline double BinaryReader::readFloat64LE()
{
m_stream->read(m_buffer, sizeof(float64));
m_stream->read(m_buffer, sizeof(double));
return ConversionUtilities::LE::toFloat64(m_buffer);
}
@ -529,10 +529,10 @@ inline char BinaryReader::readChar()
/*!
* \brief Reads a single byte/unsigned character from the current stream and advances the current position of the stream by one byte.
*/
inline byte BinaryReader::readByte()
inline uint8_t BinaryReader::readByte()
{
m_stream->read(m_buffer, sizeof(char));
return static_cast<byte>(m_buffer[0]);
return static_cast<std::uint8_t>(m_buffer[0]);
}
/*!
@ -559,7 +559,7 @@ inline std::string BinaryReader::readLengthPrefixedString()
* \remarks Synchsafe integers appear in ID3 tags that are attached to an MP3 file.
* \sa <a href="http://id3.org/id3v2.4.0-structure">ID3 tag version 2.4.0 - Main Structure</a>
*/
inline uint32 BinaryReader::readSynchsafeUInt32BE()
inline std::uint32_t BinaryReader::readSynchsafeUInt32BE()
{
return ConversionUtilities::toNormalInt(readUInt32BE());
}
@ -567,7 +567,7 @@ inline uint32 BinaryReader::readSynchsafeUInt32BE()
/*!
* \brief Reads a 8.8 fixed point big endian representation from the current stream and returns it as 32-bit floating point value.
*/
inline float32 BinaryReader::readFixed8BE()
inline float BinaryReader::readFixed8BE()
{
return ConversionUtilities::toFloat32(readUInt16BE());
}
@ -575,7 +575,7 @@ inline float32 BinaryReader::readFixed8BE()
/*!
* \brief Reads a 16.16 fixed point big endian representation from the current stream and returns it as 32-bit floating point value.
*/
inline float32 BinaryReader::readFixed16BE()
inline float BinaryReader::readFixed16BE()
{
return ConversionUtilities::toFloat32(readUInt32BE());
}
@ -585,7 +585,7 @@ inline float32 BinaryReader::readFixed16BE()
* \remarks Synchsafe integers appear in ID3 tags that are attached to an MP3 file.
* \sa <a href="http://id3.org/id3v2.4.0-structure">ID3 tag version 2.4.0 - Main Structure</a>
*/
inline uint32 BinaryReader::readSynchsafeUInt32LE()
inline std::uint32_t BinaryReader::readSynchsafeUInt32LE()
{
return ConversionUtilities::toNormalInt(readUInt32LE());
}
@ -593,7 +593,7 @@ inline uint32 BinaryReader::readSynchsafeUInt32LE()
/*!
* \brief Reads a 8.8 fixed point little endian representation from the current stream and returns it as 32-bit floating point value.
*/
inline float32 BinaryReader::readFixed8LE()
inline float BinaryReader::readFixed8LE()
{
return ConversionUtilities::toFloat32(readUInt16LE());
}
@ -601,7 +601,7 @@ inline float32 BinaryReader::readFixed8LE()
/*!
* \brief Reads a 16.16 fixed point little endian representation from the current stream and returns it as 32-bit floating point value.
*/
inline float32 BinaryReader::readFixed16LE()
inline float BinaryReader::readFixed16LE()
{
return ConversionUtilities::toFloat32(readUInt32LE());
}
@ -617,7 +617,7 @@ inline void BinaryReader::read(char &oneCharacter)
/*!
* \brief Reads a single byte/unsigned character from the current stream and advances the current position of the stream by one byte.
*/
inline void BinaryReader::read(byte &oneByte)
inline void BinaryReader::read(uint8_t &oneByte)
{
oneByte = readByte();
}
@ -645,7 +645,7 @@ inline void BinaryReader::read(std::string &lengthPrefixedString)
/*!
* \brief Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryReader::read(int16 &one16BitInt)
inline void BinaryReader::read(std::int16_t &one16BitInt)
{
one16BitInt = readInt16BE();
}
@ -653,7 +653,7 @@ inline void BinaryReader::read(int16 &one16BitInt)
/*!
* \brief Reads a 16-bit big endian unsigned integer from the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryReader::read(uint16 &one16BitUInt)
inline void BinaryReader::read(std::uint16_t &one16BitUInt)
{
one16BitUInt = readUInt16BE();
}
@ -661,7 +661,7 @@ inline void BinaryReader::read(uint16 &one16BitUInt)
/*!
* \brief Reads a 16-bit big endian signed integer from the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryReader::read(int32 &one32BitInt)
inline void BinaryReader::read(std::int32_t &one32BitInt)
{
one32BitInt = readInt32BE();
}
@ -669,7 +669,7 @@ inline void BinaryReader::read(int32 &one32BitInt)
/*!
* \brief Reads a 32-bit big endian unsigned integer from the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryReader::read(uint32 &one32BitUInt)
inline void BinaryReader::read(std::uint32_t &one32BitUInt)
{
one32BitUInt = readUInt32BE();
}
@ -677,7 +677,7 @@ inline void BinaryReader::read(uint32 &one32BitUInt)
/*!
* \brief Reads a 64-bit big endian signed integer from the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryReader::read(int64 &one64BitInt)
inline void BinaryReader::read(std::int64_t &one64BitInt)
{
one64BitInt = readInt64BE();
}
@ -685,7 +685,7 @@ inline void BinaryReader::read(int64 &one64BitInt)
/*!
* \brief Reads a 64-bit big endian unsigned integer from the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryReader::read(uint64 &one64BitUInt)
inline void BinaryReader::read(std::uint64_t &one64BitUInt)
{
one64BitUInt = readUInt64BE();
}
@ -693,7 +693,7 @@ inline void BinaryReader::read(uint64 &one64BitUInt)
/*!
* \brief Reads a 32-bit big endian floating point value from the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryReader::read(float32 &one32BitFloat)
inline void BinaryReader::read(float &one32BitFloat)
{
one32BitFloat = readFloat32BE();
}
@ -701,7 +701,7 @@ inline void BinaryReader::read(float32 &one32BitFloat)
/*!
* \brief Reads a 64-bit big endian floating point value from the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryReader::read(float64 &one64BitFloat)
inline void BinaryReader::read(double &one64BitFloat)
{
one64BitFloat = readFloat64BE();
}

View File

@ -74,10 +74,10 @@ void BinaryWriter::setStream(ostream *stream, bool giveOwnership)
/*!
* \brief Writes the specified integer \a value. Conversion to bytes is done using the specified function.
*/
void BinaryWriter::writeVariableLengthInteger(uint64 value, void (*getBytes)(uint64, char *))
void BinaryWriter::writeVariableLengthInteger(std::uint64_t value, void (*getBytes)(std::uint64_t, char *))
{
uint64 boundCheck = 0x80;
byte prefixLength = 1;
std::uint64_t boundCheck = 0x80;
std::uint8_t prefixLength = 1;
for (; boundCheck != 0x8000000000000000; boundCheck <<= 7, ++prefixLength) {
if (value < boundCheck) {
getBytes(value | boundCheck, m_buffer);

View File

@ -2,8 +2,8 @@
#define IOUTILITIES_BINARYWRITER_H
#include "../conversion/binaryconversion.h"
#include "../conversion/types.h"
#include <cstdint>
#include <cstring>
#include <ostream>
#include <string>
@ -29,66 +29,66 @@ public:
void write(const char *buffer, std::streamsize length);
void write(const std::vector<char> &buffer, std::streamsize length);
void writeChar(char value);
void writeByte(byte value);
void writeInt16BE(int16 value);
void writeUInt16BE(uint16 value);
void writeInt24BE(int32 value);
void writeUInt24BE(uint32 value);
void writeInt32BE(int32 value);
void writeUInt32BE(uint32 value);
void writeInt40BE(int64 value);
void writeUInt40BE(uint64 value);
void writeInt56BE(int64 value);
void writeUInt56BE(uint64 value);
void writeInt64BE(int64 value);
void writeUInt64BE(uint64 value);
void writeVariableLengthUIntBE(uint64 value);
void writeFloat32BE(float32 value);
void writeFloat64BE(float64 value);
void writeInt16LE(int16 value);
void writeUInt16LE(uint16 value);
void writeInt24LE(int32 value);
void writeUInt24LE(uint32 value);
void writeInt32LE(int32 value);
void writeUInt32LE(uint32 value);
void writeInt40LE(int64 value);
void writeUInt40LE(uint64 value);
void writeInt56LE(int64 value);
void writeUInt56LE(uint64 value);
void writeInt64LE(int64 value);
void writeUInt64LE(uint64 value);
void writeVariableLengthUIntLE(uint64 value);
void writeFloat32LE(float32 value);
void writeFloat64LE(float64 value);
void writeByte(std::uint8_t value);
void writeInt16BE(std::int16_t value);
void writeUInt16BE(std::uint16_t value);
void writeInt24BE(std::int32_t value);
void writeUInt24BE(std::uint32_t value);
void writeInt32BE(std::int32_t value);
void writeUInt32BE(std::uint32_t value);
void writeInt40BE(std::int64_t value);
void writeUInt40BE(std::uint64_t value);
void writeInt56BE(std::int64_t value);
void writeUInt56BE(std::uint64_t value);
void writeInt64BE(std::int64_t value);
void writeUInt64BE(std::uint64_t value);
void writeVariableLengthUIntBE(std::uint64_t value);
void writeFloat32BE(float value);
void writeFloat64BE(double value);
void writeInt16LE(std::int16_t value);
void writeUInt16LE(std::uint16_t value);
void writeInt24LE(std::int32_t value);
void writeUInt24LE(std::uint32_t value);
void writeInt32LE(std::int32_t value);
void writeUInt32LE(std::uint32_t value);
void writeInt40LE(std::int64_t value);
void writeUInt40LE(std::uint64_t value);
void writeInt56LE(std::int64_t value);
void writeUInt56LE(std::uint64_t value);
void writeInt64LE(std::int64_t value);
void writeUInt64LE(std::uint64_t value);
void writeVariableLengthUIntLE(std::uint64_t value);
void writeFloat32LE(float value);
void writeFloat64LE(double value);
void writeString(const std::string &value);
void writeTerminatedString(const std::string &value);
void writeLengthPrefixedString(const std::string &value);
void writeLengthPrefixedCString(const char *value, std::size_t size);
void writeBool(bool value);
void writeSynchsafeUInt32BE(uint32 valueToConvertAndWrite);
void writeFixed8BE(float32 valueToConvertAndWrite);
void writeFixed16BE(float32 valueToConvertAndWrite);
void writeSynchsafeUInt32LE(uint32 valueToConvertAndWrite);
void writeFixed8LE(float32 valueToConvertAndWrite);
void writeFixed16LE(float32 valueToConvertAndWrite);
void writeSynchsafeUInt32BE(std::uint32_t valueToConvertAndWrite);
void writeFixed8BE(float valueToConvertAndWrite);
void writeFixed16BE(float valueToConvertAndWrite);
void writeSynchsafeUInt32LE(std::uint32_t valueToConvertAndWrite);
void writeFixed8LE(float valueToConvertAndWrite);
void writeFixed16LE(float valueToConvertAndWrite);
// declare further overloads for write() to ease use of BinaryWriter in templates
void write(char oneChar);
void write(byte oneByte);
void write(std::uint8_t oneByte);
void write(bool oneBool);
void write(const std::string &lengthPrefixedString);
void write(const char *lengthPrefixedString);
void write(int16 one16BitInt);
void write(uint16 one16BitUint);
void write(int32 one32BitInt);
void write(uint32 one32BitUint);
void write(int64 one64BitInt);
void write(uint64 one64BitUint);
void write(float32 one32BitFloat);
void write(float64 one64BitFloat);
void write(std::int16_t one16BitInt);
void write(std::uint16_t one16BitUint);
void write(std::int32_t one32BitInt);
void write(std::uint32_t one32BitUint);
void write(std::int64_t one64BitInt);
void write(std::uint64_t one64BitUint);
void write(float one32BitFloat);
void write(double one64BitFloat);
private:
void writeVariableLengthInteger(uint64 size, void (*getBytes)(uint64, char *));
void writeVariableLengthInteger(std::uint64_t size, void (*getBytes)(std::uint64_t, char *));
std::ostream *m_stream;
bool m_ownership;
@ -198,7 +198,7 @@ inline void BinaryWriter::writeChar(char value)
/*!
* \brief Writes a single byte to the current stream and advances the current position of the stream by one byte.
*/
inline void BinaryWriter::writeByte(byte value)
inline void BinaryWriter::writeByte(uint8_t value)
{
m_buffer[0] = *reinterpret_cast<char *>(&value);
m_stream->write(m_buffer, 1);
@ -215,26 +215,26 @@ inline void BinaryWriter::writeBool(bool value)
/*!
* \brief Writes a 16-bit big endian signed integer to the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryWriter::writeInt16BE(int16 value)
inline void BinaryWriter::writeInt16BE(std::int16_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(int16));
m_stream->write(m_buffer, sizeof(std::int16_t));
}
/*!
* \brief Writes a 16-bit big endian unsigned integer to the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryWriter::writeUInt16BE(uint16 value)
inline void BinaryWriter::writeUInt16BE(std::uint16_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(uint16));
m_stream->write(m_buffer, sizeof(std::uint16_t));
}
/*!
* \brief Writes a 24-bit big endian signed integer to the current stream and advances the current position of the stream by three bytes.
* \remarks The most significant byte of the specified 32-bit signed integer \a value will be discarded.
*/
inline void BinaryWriter::writeInt24BE(int32 value)
inline void BinaryWriter::writeInt24BE(std::int32_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 1, 3);
@ -244,7 +244,7 @@ inline void BinaryWriter::writeInt24BE(int32 value)
* \brief Writes a 24-bit big endian unsigned integer to the current stream and advances the current position of the stream by three bytes.
* \remarks The most significant byte of the specified 32-bit unsigned integer \a value will be discarded.
*/
inline void BinaryWriter::writeUInt24BE(uint32 value)
inline void BinaryWriter::writeUInt24BE(std::uint32_t value)
{
// discard most significant byte
ConversionUtilities::BE::getBytes(value, m_buffer);
@ -254,26 +254,26 @@ inline void BinaryWriter::writeUInt24BE(uint32 value)
/*!
* \brief Writes a 32-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::writeInt32BE(int32 value)
inline void BinaryWriter::writeInt32BE(std::int32_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(int32));
m_stream->write(m_buffer, sizeof(std::int32_t));
}
/*!
* \brief Writes a 32-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::writeUInt32BE(uint32 value)
inline void BinaryWriter::writeUInt32BE(std::uint32_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(uint32));
m_stream->write(m_buffer, sizeof(std::uint32_t));
}
/*!
* \brief Writes a 40-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
* \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
*/
inline void BinaryWriter::writeInt40BE(int64 value)
inline void BinaryWriter::writeInt40BE(std::int64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 3, 5);
@ -283,7 +283,7 @@ inline void BinaryWriter::writeInt40BE(int64 value)
* \brief Writes a 40-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
* \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
*/
inline void BinaryWriter::writeUInt40BE(uint64 value)
inline void BinaryWriter::writeUInt40BE(std::uint64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 3, 5);
@ -293,7 +293,7 @@ inline void BinaryWriter::writeUInt40BE(uint64 value)
* \brief Writes a 56-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
* \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
*/
inline void BinaryWriter::writeInt56BE(int64 value)
inline void BinaryWriter::writeInt56BE(std::int64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 1, 7);
@ -303,7 +303,7 @@ inline void BinaryWriter::writeInt56BE(int64 value)
* \brief Writes a 56-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
* \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
*/
inline void BinaryWriter::writeUInt56BE(uint64 value)
inline void BinaryWriter::writeUInt56BE(std::uint64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 1, 7);
@ -312,71 +312,71 @@ inline void BinaryWriter::writeUInt56BE(uint64 value)
/*!
* \brief Writes a 64-bit big endian signed integer to the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryWriter::writeInt64BE(int64 value)
inline void BinaryWriter::writeInt64BE(std::int64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(int64));
m_stream->write(m_buffer, sizeof(std::int64_t));
}
/*!
* \brief Writes a 64-bit big endian unsigned integer to the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryWriter::writeUInt64BE(uint64 value)
inline void BinaryWriter::writeUInt64BE(std::uint64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(uint64));
m_stream->write(m_buffer, sizeof(std::uint64_t));
}
/*!
* \brief Writes an up to 8 byte long big endian unsigned integer to the current stream and advances the current position of the stream by one to eight bytes.
* \throws Throws ConversionException if \a value exceeds the maximum.
*/
inline void BinaryWriter::writeVariableLengthUIntBE(uint64 value)
inline void BinaryWriter::writeVariableLengthUIntBE(std::uint64_t value)
{
writeVariableLengthInteger(value, static_cast<void (*)(uint64, char *)>(&ConversionUtilities::BE::getBytes));
writeVariableLengthInteger(value, static_cast<void (*)(std::uint64_t, char *)>(&ConversionUtilities::BE::getBytes));
}
/*!
* \brief Writes a 32-bit big endian floating point \a value to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::writeFloat32BE(float32 value)
inline void BinaryWriter::writeFloat32BE(float value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(float32));
m_stream->write(m_buffer, sizeof(float));
}
/*!
* \brief Writes a 64-bit big endian floating point \a value to the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryWriter::writeFloat64BE(float64 value)
inline void BinaryWriter::writeFloat64BE(double value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(float64));
m_stream->write(m_buffer, sizeof(double));
}
/*!
* \brief Writes a 16-bit little endian signed integer to the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryWriter::writeInt16LE(int16 value)
inline void BinaryWriter::writeInt16LE(std::int16_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(int16));
m_stream->write(m_buffer, sizeof(std::int16_t));
}
/*!
* \brief Writes a 16-bit little endian unsigned integer to the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryWriter::writeUInt16LE(uint16 value)
inline void BinaryWriter::writeUInt16LE(std::uint16_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(uint16));
m_stream->write(m_buffer, sizeof(std::uint16_t));
}
/*!
* \brief Writes a 24-bit little endian signed integer to the current stream and advances the current position of the stream by three bytes.
* \remarks The most significant byte of the specified 32-bit signed integer \a value will be discarded.
*/
inline void BinaryWriter::writeInt24LE(int32 value)
inline void BinaryWriter::writeInt24LE(std::int32_t value)
{
// discard most significant byte
ConversionUtilities::LE::getBytes(value, m_buffer);
@ -387,7 +387,7 @@ inline void BinaryWriter::writeInt24LE(int32 value)
* \brief Writes a 24-bit little endian unsigned integer to the current stream and advances the current position of the stream by three bytes.
* \remarks The most significant byte of the specified 32-bit unsigned integer \a value will be discarded.
*/
inline void BinaryWriter::writeUInt24LE(uint32 value)
inline void BinaryWriter::writeUInt24LE(std::uint32_t value)
{
// discard most significant byte
ConversionUtilities::LE::getBytes(value, m_buffer);
@ -397,26 +397,26 @@ inline void BinaryWriter::writeUInt24LE(uint32 value)
/*!
* \brief Writes a 32-bit little endian signed integer to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::writeInt32LE(int32 value)
inline void BinaryWriter::writeInt32LE(std::int32_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(int32));
m_stream->write(m_buffer, sizeof(std::int32_t));
}
/*!
* \brief Writes a 32-bit little endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::writeUInt32LE(uint32 value)
inline void BinaryWriter::writeUInt32LE(std::uint32_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(uint32));
m_stream->write(m_buffer, sizeof(std::uint32_t));
}
/*!
* \brief Writes a 40-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
* \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
*/
inline void BinaryWriter::writeInt40LE(int64 value)
inline void BinaryWriter::writeInt40LE(std::int64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, 5);
@ -426,7 +426,7 @@ inline void BinaryWriter::writeInt40LE(int64 value)
* \brief Writes a 40-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
* \remarks The most significant bytes of the specified 64-bit unsigned integer \a value will be discarded.
*/
inline void BinaryWriter::writeUInt40LE(uint64 value)
inline void BinaryWriter::writeUInt40LE(std::uint64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, 5);
@ -436,7 +436,7 @@ inline void BinaryWriter::writeUInt40LE(uint64 value)
* \brief Writes a 56-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
* \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
*/
inline void BinaryWriter::writeInt56LE(int64 value)
inline void BinaryWriter::writeInt56LE(std::int64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, 7);
@ -446,7 +446,7 @@ inline void BinaryWriter::writeInt56LE(int64 value)
* \brief Writes a 56-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
* \remarks The most significant byte of the specified 64-bit unsigned integer \a value will be discarded.
*/
inline void BinaryWriter::writeUInt56LE(uint64 value)
inline void BinaryWriter::writeUInt56LE(std::uint64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, 7);
@ -455,46 +455,46 @@ inline void BinaryWriter::writeUInt56LE(uint64 value)
/*!
* \brief Writes a 64-bit little endian signed integer to the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryWriter::writeInt64LE(int64 value)
inline void BinaryWriter::writeInt64LE(std::int64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(int64));
m_stream->write(m_buffer, sizeof(std::int64_t));
}
/*!
* \brief Writes a 64-bit little endian unsigned integer to the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryWriter::writeUInt64LE(uint64 value)
inline void BinaryWriter::writeUInt64LE(std::uint64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(uint64));
m_stream->write(m_buffer, sizeof(std::uint64_t));
}
/*!
* \brief Writes an up to 8 byte long little endian unsigned integer to the current stream and advances the current position of the stream by one to eight bytes.
* \throws Throws ConversionException if \a value exceeds the maximum.
*/
inline void BinaryWriter::writeVariableLengthUIntLE(uint64 value)
inline void BinaryWriter::writeVariableLengthUIntLE(std::uint64_t value)
{
writeVariableLengthInteger(value, static_cast<void (*)(uint64, char *)>(&ConversionUtilities::LE::getBytes));
writeVariableLengthInteger(value, static_cast<void (*)(std::uint64_t, char *)>(&ConversionUtilities::LE::getBytes));
}
/*!
* \brief Writes a 32-bit little endian floating point \a value to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::writeFloat32LE(float32 value)
inline void BinaryWriter::writeFloat32LE(float value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(float32));
m_stream->write(m_buffer, sizeof(float));
}
/*!
* \brief Writes a 64-bit little endian floating point \a value to the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryWriter::writeFloat64LE(float64 value)
inline void BinaryWriter::writeFloat64LE(double value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(float64));
m_stream->write(m_buffer, sizeof(double));
}
/*!
@ -544,7 +544,7 @@ inline void BinaryWriter::writeLengthPrefixedCString(const char *value, std::siz
* \remarks Synchsafe integers appear in ID3 tags that are attached to an MP3 file.
* \sa <a href="http://id3.org/id3v2.4.0-structure">ID3 tag version 2.4.0 - Main Structure</a>
*/
inline void BinaryWriter::writeSynchsafeUInt32BE(uint32 valueToConvertAndWrite)
inline void BinaryWriter::writeSynchsafeUInt32BE(std::uint32_t valueToConvertAndWrite)
{
writeUInt32BE(ConversionUtilities::toSynchsafeInt(valueToConvertAndWrite));
}
@ -552,7 +552,7 @@ inline void BinaryWriter::writeSynchsafeUInt32BE(uint32 valueToConvertAndWrite)
/*!
* \brief Writes the 8.8 fixed point big endian representation for the specified 32-bit floating point \a value to the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryWriter::writeFixed8BE(float32 valueToConvertAndWrite)
inline void BinaryWriter::writeFixed8BE(float valueToConvertAndWrite)
{
writeUInt16BE(ConversionUtilities::toFixed8(valueToConvertAndWrite));
}
@ -560,7 +560,7 @@ inline void BinaryWriter::writeFixed8BE(float32 valueToConvertAndWrite)
/*!
* \brief Writes the 16.16 fixed point big endian representation for the specified 32-bit floating point \a value to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::writeFixed16BE(float32 valueToConvertAndWrite)
inline void BinaryWriter::writeFixed16BE(float valueToConvertAndWrite)
{
writeUInt32BE(ConversionUtilities::toFixed16(valueToConvertAndWrite));
}
@ -570,7 +570,7 @@ inline void BinaryWriter::writeFixed16BE(float32 valueToConvertAndWrite)
* \remarks Synchsafe integers appear in ID3 tags that are attached to an MP3 file.
* \sa <a href="http://id3.org/id3v2.4.0-structure">ID3 tag version 2.4.0 - Main Structure</a>
*/
inline void BinaryWriter::writeSynchsafeUInt32LE(uint32 valueToConvertAndWrite)
inline void BinaryWriter::writeSynchsafeUInt32LE(std::uint32_t valueToConvertAndWrite)
{
writeUInt32LE(ConversionUtilities::toSynchsafeInt(valueToConvertAndWrite));
}
@ -578,7 +578,7 @@ inline void BinaryWriter::writeSynchsafeUInt32LE(uint32 valueToConvertAndWrite)
/*!
* \brief Writes the 8.8 fixed point little endian representation for the specified 32-bit floating point \a value to the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryWriter::writeFixed8LE(float32 valueToConvertAndWrite)
inline void BinaryWriter::writeFixed8LE(float valueToConvertAndWrite)
{
writeUInt16LE(ConversionUtilities::toFixed8(valueToConvertAndWrite));
}
@ -586,7 +586,7 @@ inline void BinaryWriter::writeFixed8LE(float32 valueToConvertAndWrite)
/*!
* \brief Writes the 16.16 fixed point little endian representation for the specified 32-bit floating point \a value to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::writeFixed16LE(float32 valueToConvertAndWrite)
inline void BinaryWriter::writeFixed16LE(float valueToConvertAndWrite)
{
writeUInt32LE(ConversionUtilities::toFixed16(valueToConvertAndWrite));
}
@ -602,7 +602,7 @@ inline void BinaryWriter::write(char oneChar)
/*!
* \brief Writes a single byte to the current stream and advances the current position of the stream by one byte.
*/
inline void BinaryWriter::write(byte oneByte)
inline void BinaryWriter::write(std::uint8_t oneByte)
{
writeByte(oneByte);
}
@ -638,7 +638,7 @@ inline void BinaryWriter::write(const char *lengthPrefixedString)
/*!
* \brief Writes a 16-bit big endian signed integer to the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryWriter::write(int16 one16BitInt)
inline void BinaryWriter::write(std::int16_t one16BitInt)
{
writeInt16BE(one16BitInt);
}
@ -646,7 +646,7 @@ inline void BinaryWriter::write(int16 one16BitInt)
/*!
* \brief Writes a 16-bit big endian unsigned integer to the current stream and advances the current position of the stream by two bytes.
*/
inline void BinaryWriter::write(uint16 one16BitUint)
inline void BinaryWriter::write(std::uint16_t one16BitUint)
{
writeUInt16BE(one16BitUint);
}
@ -654,7 +654,7 @@ inline void BinaryWriter::write(uint16 one16BitUint)
/*!
* \brief Writes a 32-bit big endian signed integer to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::write(int32 one32BitInt)
inline void BinaryWriter::write(std::int32_t one32BitInt)
{
writeInt32BE(one32BitInt);
}
@ -662,7 +662,7 @@ inline void BinaryWriter::write(int32 one32BitInt)
/*!
* \brief Writes a 32-bit big endian unsigned integer to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::write(uint32 one32BitUint)
inline void BinaryWriter::write(std::uint32_t one32BitUint)
{
writeUInt32BE(one32BitUint);
}
@ -670,7 +670,7 @@ inline void BinaryWriter::write(uint32 one32BitUint)
/*!
* \brief Writes a 64-bit big endian signed integer to the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryWriter::write(int64 one64BitInt)
inline void BinaryWriter::write(std::int64_t one64BitInt)
{
writeInt64BE(one64BitInt);
}
@ -678,7 +678,7 @@ inline void BinaryWriter::write(int64 one64BitInt)
/*!
* \brief Writes a 64-bit big endian unsigned integer to the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryWriter::write(uint64 one64BitUint)
inline void BinaryWriter::write(std::uint64_t one64BitUint)
{
writeUInt64BE(one64BitUint);
}
@ -686,7 +686,7 @@ inline void BinaryWriter::write(uint64 one64BitUint)
/*!
* \brief Writes a 32-bit big endian floating point \a value to the current stream and advances the current position of the stream by four bytes.
*/
inline void BinaryWriter::write(float32 one32BitFloat)
inline void BinaryWriter::write(float one32BitFloat)
{
writeFloat32BE(one32BitFloat);
}
@ -694,7 +694,7 @@ inline void BinaryWriter::write(float32 one32BitFloat)
/*!
* \brief Writes a 64-bit big endian floating point \a value to the current stream and advances the current position of the stream by eight bytes.
*/
inline void BinaryWriter::write(float64 one64BitFloat)
inline void BinaryWriter::write(double one64BitFloat)
{
writeFloat64BE(one64BitFloat);
}

View File

@ -1,9 +1,9 @@
#ifndef IOUTILITIES_BITREADER_H
#define IOUTILITIES_BITREADER_H
#include "../conversion/types.h"
#include "../global.h"
#include <cstdint>
#include <ios>
#include <iostream>
#include <type_traits>
@ -15,11 +15,11 @@ public:
BitReader(const char *buffer, std::size_t bufferSize);
BitReader(const char *buffer, const char *end);
template <typename intType> intType readBits(byte bitCount);
byte readBit();
template <typename intType> intType readBits(std::uint8_t bitCount);
std::uint8_t readBit();
template <typename intType> intType readUnsignedExpGolombCodedBits();
template <typename intType> intType readSignedExpGolombCodedBits();
template <typename intType> intType showBits(byte bitCount);
template <typename intType> intType showBits(std::uint8_t bitCount);
void skipBits(std::size_t bitCount);
void align();
std::size_t bitsAvailable();
@ -27,9 +27,9 @@ public:
void reset(const char *buffer, const char *end);
private:
const byte *m_buffer;
const byte *m_end;
byte m_bitsAvail;
const std::uint8_t *m_buffer;
const std::uint8_t *m_end;
std::uint8_t m_bitsAvail;
};
/*!
@ -50,8 +50,8 @@ inline BitReader::BitReader(const char *buffer, std::size_t bufferSize)
* - \a end must be greather than \a buffer.
*/
inline BitReader::BitReader(const char *buffer, const char *end)
: m_buffer(reinterpret_cast<const byte *>(buffer))
, m_end(reinterpret_cast<const byte *>(end))
: m_buffer(reinterpret_cast<const std::uint8_t *>(buffer))
, m_end(reinterpret_cast<const std::uint8_t *>(end))
, m_bitsAvail(8)
{
}
@ -64,10 +64,10 @@ inline BitReader::BitReader(const char *buffer, const char *end)
* \throws Throws ios_base::failure if the end of the buffer is exceeded.
* The reader becomes invalid in that case.
*/
template <typename intType> intType BitReader::readBits(byte bitCount)
template <typename intType> intType BitReader::readBits(std::uint8_t bitCount)
{
intType val = 0;
for (byte readAtOnce; bitCount; bitCount -= readAtOnce) {
for (std::uint8_t readAtOnce; bitCount; bitCount -= readAtOnce) {
if (!m_bitsAvail) {
if (++m_buffer >= m_end) {
throw std::ios_base::failure("end of buffer exceeded");
@ -85,9 +85,9 @@ template <typename intType> intType BitReader::readBits(byte bitCount)
* \throws Throws ios_base::failure if the end of the buffer is exceeded.
* The reader becomes invalid in that case.
*/
inline byte BitReader::readBit()
inline std::uint8_t BitReader::readBit()
{
return readBits<byte>(1) == 1;
return readBits<std::uint8_t>(1) == 1;
}
/*!
@ -100,7 +100,7 @@ inline byte BitReader::readBit()
*/
template <typename intType> intType BitReader::readUnsignedExpGolombCodedBits()
{
byte count = 0;
std::uint8_t count = 0;
while (!readBit()) {
++count;
}
@ -124,7 +124,7 @@ template <typename intType> intType BitReader::readSignedExpGolombCodedBits()
/*!
* \brief Reads the specified number of bits from the buffer without advancing the current position.
*/
template <typename intType> intType BitReader::showBits(byte bitCount)
template <typename intType> intType BitReader::showBits(std::uint8_t bitCount)
{
auto tmp = *this;
return tmp.readBits<intType>(bitCount);
@ -146,8 +146,8 @@ inline std::size_t BitReader::bitsAvailable()
*/
inline void BitReader::reset(const char *buffer, std::size_t bufferSize)
{
m_buffer = reinterpret_cast<const byte *>(buffer);
m_end = reinterpret_cast<const byte *>(buffer + bufferSize);
m_buffer = reinterpret_cast<const std::uint8_t *>(buffer);
m_end = reinterpret_cast<const std::uint8_t *>(buffer + bufferSize);
m_bitsAvail = 8;
}
@ -159,8 +159,8 @@ inline void BitReader::reset(const char *buffer, std::size_t bufferSize)
*/
inline void BitReader::reset(const char *buffer, const char *end)
{
m_buffer = reinterpret_cast<const byte *>(buffer);
m_end = reinterpret_cast<const byte *>(end);
m_buffer = reinterpret_cast<const std::uint8_t *>(buffer);
m_end = reinterpret_cast<const std::uint8_t *>(end);
m_bitsAvail = 8;
}

View File

@ -42,10 +42,10 @@ int factorial(int number)
* \brief Computes \a base power \a exponent modulo \a module.
* \todo Make constexpr/template in v5.
*/
uint64 powerModulo(const uint64 base, const uint64 exponent, const uint64 module)
std::uint64_t powerModulo(const std::uint64_t base, const std::uint64_t exponent, const std::uint64_t module)
{
uint64 res = 1;
for (uint64 mask = 0x8000000000000000; mask; mask >>= 1) {
std::uint64_t res = 1;
for (std::uint64_t mask = 0x8000000000000000; mask; mask >>= 1) {
if (mask & exponent) {
res *= base;
}
@ -61,9 +61,9 @@ uint64 powerModulo(const uint64 base, const uint64 exponent, const uint64 module
* \brief Computes the inverse of \a number modulo \a module.
* \todo Make constexpr/template in v5.
*/
int64 inverseModulo(int64 number, int64 module)
std::int64_t inverseModulo(std::int64_t number, std::int64_t module)
{
int64 y1 = 0, y2 = 1, tmp;
std::int64_t y1 = 0, y2 = 1, tmp;
while (number != 1) {
tmp = y1 - (module / number) * y2;
y1 = y2;
@ -79,9 +79,9 @@ int64 inverseModulo(int64 number, int64 module)
* \brief Computes the order of \a number modulo \a module.
* \todo Make constexpr/template in v5.
*/
uint64 orderModulo(const uint64 number, const uint64 module)
std::uint64_t orderModulo(const std::uint64_t number, const std::uint64_t module)
{
uint64 order = 1;
std::uint64_t order = 1;
for (; powerModulo(number, order, module) != 1 && order != module; ++order)
;
return order != module ? order : 0;

View File

@ -1,16 +1,17 @@
#ifndef MATHUTILITIES_H
#define MATHUTILITIES_H
#include "../conversion/types.h"
#include "../global.h"
#include <cstdint>
namespace MathUtilities {
CPP_UTILITIES_EXPORT int digitsum(int number, int base = 10);
CPP_UTILITIES_EXPORT int factorial(int number);
CPP_UTILITIES_EXPORT uint64 powerModulo(uint64 base, uint64 expontent, uint64 module);
CPP_UTILITIES_EXPORT int64 inverseModulo(int64 number, int64 module);
CPP_UTILITIES_EXPORT uint64 orderModulo(uint64 number, uint64 module);
CPP_UTILITIES_EXPORT std::uint64_t powerModulo(std::uint64_t base, std::uint64_t expontent, std::uint64_t module);
CPP_UTILITIES_EXPORT std::int64_t inverseModulo(std::int64_t number, std::int64_t module);
CPP_UTILITIES_EXPORT std::uint64_t orderModulo(std::uint64_t number, std::uint64_t module);
/// \brief Returns the smallest of the given items.
template <typename T> constexpr T min(T first, T second)

View File

@ -21,9 +21,9 @@ using namespace CPPUNIT_NS;
// compile-time checks for binary conversion
static_assert(toSynchsafeInt(255) == 383, "toSynchsafeInt()");
static_assert(toNormalInt(383) == 255, "toNormalInt()");
static_assert(swapOrder(static_cast<uint16>(0xABCD)) == 0xCDAB, "swapOrder(uint16)");
static_assert(swapOrder(static_cast<uint32>(0xABCDEF12)) == 0x12EFCDAB, "swapOrder(uint32)");
static_assert(swapOrder(static_cast<uint64>(0xABCDEF1234567890)) == 0x9078563412EFCDAB, "swapOrder(uint64)");
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(static_cast<std::uint64_t>(0xABCDEF1234567890)) == 0x9078563412EFCDAB, "swapOrder(uint64)");
/*!
* \brief The ConversionTests class tests classes and methods of the ConversionUtilities namespace.
@ -140,7 +140,7 @@ void ConversionTests::testConversion(
void ConversionTests::testBinaryConversions()
{
// test to...() / getBytes() with random numbers
for (byte b = 1; b < 100; ++b) {
for (auto b = 1; b < 100; ++b) {
TEST_BE_CONVERSION(toUInt16);
TEST_BE_CONVERSION(toUInt32);
TEST_BE_CONVERSION(toUInt64);
@ -163,21 +163,21 @@ void ConversionTests::testBinaryConversions()
*/
void ConversionTests::testSwapOrderFunctions()
{
CPPUNIT_ASSERT(swapOrder(static_cast<uint16>(0x7825)) == 0x2578);
CPPUNIT_ASSERT(swapOrder(static_cast<uint32>(0x12345678)) == 0x78563412);
CPPUNIT_ASSERT(swapOrder(static_cast<uint64>(0x1122334455667788)) == 0x8877665544332211);
CPPUNIT_ASSERT(swapOrder(static_cast<std::uint16_t>(0x7825)) == 0x2578);
CPPUNIT_ASSERT(swapOrder(static_cast<std::uint32_t>(0x12345678)) == 0x78563412);
CPPUNIT_ASSERT(swapOrder(static_cast<std::uint64_t>(0x1122334455667788)) == 0x8877665544332211);
}
/*!
* \brief Internally used for string encoding tests to check results.
*/
void assertEqual(const char *message, const byte *expectedValues, size_t expectedSize, const StringData &actualValues)
void assertEqual(const char *message, const std::uint8_t *expectedValues, size_t expectedSize, const StringData &actualValues)
{
// check whether number of elements matches
CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expectedSize, actualValues.second);
// check whether contents match
auto *end = expectedValues + expectedSize;
auto *i = reinterpret_cast<byte *>(actualValues.first.get());
auto *i = reinterpret_cast<std::uint8_t *>(actualValues.first.get());
for (; expectedValues != end; ++expectedValues, ++i) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(message, asHexNumber(*expectedValues), asHexNumber(*i));
}
@ -207,14 +207,14 @@ void assertEqual(const char *message, const byte *expectedValues, size_t expecte
void ConversionTests::testStringEncodingConversions()
{
// define test string "ABCD" for the different encodings
const byte simpleString[] = { 'A', 'B', 'C', 'D' };
const uint16 simpleUtf16LEString[] = { 0x0041, 0x0042, 0x0043, 0x0044 };
const uint16 simpleUtf16BEString[] = { 0x4100, 0x4200, 0x4300, 0x4400 };
const std::uint8_t simpleString[] = { 'A', 'B', 'C', 'D' };
const std::uint16_t simpleUtf16LEString[] = { 0x0041, 0x0042, 0x0043, 0x0044 };
const std::uint16_t simpleUtf16BEString[] = { 0x4100, 0x4200, 0x4300, 0x4400 };
// define test string "ABÖCD" for the different encodings
const byte latin1String[] = { 'A', 'B', 0xD6, 'C', 'D' };
const byte utf8String[] = { 'A', 'B', 0xC3, 0x96, 'C', 'D' };
const uint16 utf16LEString[] = { 0x0041, 0x0042, 0x00D6, 0x0043, 0x0044 };
const uint16 utf16BEString[] = { 0x4100, 0x4200, 0xD600, 0x4300, 0x4400 };
const std::uint8_t latin1String[] = { 'A', 'B', 0xD6, 'C', 'D' };
const std::uint8_t utf8String[] = { 'A', 'B', 0xC3, 0x96, 'C', 'D' };
const std::uint16_t utf16LEString[] = { 0x0041, 0x0042, 0x00D6, 0x0043, 0x0044 };
const std::uint16_t utf16BEString[] = { 0x4100, 0x4200, 0xD600, 0x4300, 0x4400 };
// test conversion to UTF-8
assertEqual("Latin-1 to UTF-8 (simple)", simpleString, 4, convertLatin1ToUtf8(reinterpret_cast<const char *>(simpleString), 4));
assertEqual("Latin-1 to UTF-8", utf8String, 6, convertLatin1ToUtf8(reinterpret_cast<const char *>(latin1String), 5));
@ -227,13 +227,13 @@ void ConversionTests::testStringEncodingConversions()
// test conversion from UTF-8
assertEqual("UTF-8 to Latin-1 (simple)", simpleString, 4, convertUtf8ToLatin1(reinterpret_cast<const char *>(simpleString), 4));
assertEqual("UTF-8 to Latin-1", latin1String, 5, convertUtf8ToLatin1(reinterpret_cast<const char *>(utf8String), 6));
assertEqual("UTF-8 to UFT-16LE (simple)", reinterpret_cast<const byte *>(LE_STR_FOR_ENDIANNESS(simpleUtf16)), 8,
assertEqual("UTF-8 to UFT-16LE (simple)", reinterpret_cast<const std::uint8_t *>(LE_STR_FOR_ENDIANNESS(simpleUtf16)), 8,
convertUtf8ToUtf16LE(reinterpret_cast<const char *>(simpleString), 4));
assertEqual("UTF-8 to UFT-16LE", reinterpret_cast<const byte *>(LE_STR_FOR_ENDIANNESS(utf16)), 10,
assertEqual("UTF-8 to UFT-16LE", reinterpret_cast<const std::uint8_t *>(LE_STR_FOR_ENDIANNESS(utf16)), 10,
convertUtf8ToUtf16LE(reinterpret_cast<const char *>(utf8String), 6));
assertEqual("UTF-8 to UFT-16BE (simple)", reinterpret_cast<const byte *>(BE_STR_FOR_ENDIANNESS(simpleUtf16)), 8,
assertEqual("UTF-8 to UFT-16BE (simple)", reinterpret_cast<const std::uint8_t *>(BE_STR_FOR_ENDIANNESS(simpleUtf16)), 8,
convertUtf8ToUtf16BE(reinterpret_cast<const char *>(simpleString), 4));
assertEqual("UTF-8 to UFT-16BE", reinterpret_cast<const byte *>(BE_STR_FOR_ENDIANNESS(utf16)), 10,
assertEqual("UTF-8 to UFT-16BE", reinterpret_cast<const std::uint8_t *>(BE_STR_FOR_ENDIANNESS(utf16)), 10,
convertUtf8ToUtf16BE(reinterpret_cast<const char *>(utf8String), 6));
CPPUNIT_ASSERT_THROW(convertString("invalid charset", "UTF-8", "foo", 3, 1.0f), ConversionException);
}
@ -246,45 +246,45 @@ void ConversionTests::testStringConversions()
// stringToNumber() / numberToString() with zero and random numbers
CPPUNIT_ASSERT_EQUAL("0"s, numberToString<unsigned int>(0));
CPPUNIT_ASSERT_EQUAL("0"s, numberToString<signed int>(0));
uniform_int_distribution<int64> randomDistSigned(numeric_limits<int64>::min());
uniform_int_distribution<uint64> randomDistUnsigned(0);
uniform_int_distribution<std::int64_t> randomDistSigned(numeric_limits<std::int64_t>::min());
uniform_int_distribution<std::uint64_t> randomDistUnsigned(0);
const string stringMsg("string"), wideStringMsg("wide string"), bufferMsg("buffer");
for (byte b = 1; b < 100; ++b) {
for (std::uint8_t b = 1; b < 100; ++b) {
auto signedRandom = randomDistSigned(m_randomEngine);
auto unsignedRandom = randomDistUnsigned(m_randomEngine);
for (const auto base : initializer_list<byte>{ 2, 8, 10, 16 }) {
const auto asString = numberToString<uint64, string>(unsignedRandom, static_cast<string::value_type>(base));
const auto asWideString = numberToString<uint64, wstring>(unsignedRandom, base);
CPPUNIT_ASSERT_EQUAL_MESSAGE(stringMsg, unsignedRandom, stringToNumber<uint64>(asString, static_cast<string::value_type>(base)));
CPPUNIT_ASSERT_EQUAL_MESSAGE(wideStringMsg, unsignedRandom, stringToNumber<uint64>(asWideString, base));
CPPUNIT_ASSERT_EQUAL_MESSAGE(bufferMsg, unsignedRandom, bufferToNumber<uint64>(asString.data(), asString.size(), base));
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 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(wideStringMsg, unsignedRandom, stringToNumber<std::uint64_t>(asWideString, base));
CPPUNIT_ASSERT_EQUAL_MESSAGE(bufferMsg, unsignedRandom, bufferToNumber<std::uint64_t>(asString.data(), asString.size(), base));
}
for (const auto base : initializer_list<byte>{ 10 }) {
const auto asString = numberToString<int64, string>(signedRandom, static_cast<string::value_type>(base));
const auto asWideString = numberToString<int64, wstring>(signedRandom, base);
CPPUNIT_ASSERT_EQUAL_MESSAGE(stringMsg, signedRandom, stringToNumber<int64>(asString, static_cast<string::value_type>(base)));
CPPUNIT_ASSERT_EQUAL_MESSAGE(wideStringMsg, signedRandom, stringToNumber<int64>(asWideString, base));
CPPUNIT_ASSERT_EQUAL_MESSAGE(bufferMsg, signedRandom, bufferToNumber<int64>(asString.data(), asString.size(), base));
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 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(wideStringMsg, signedRandom, stringToNumber<std::int64_t>(asWideString, base));
CPPUNIT_ASSERT_EQUAL_MESSAGE(bufferMsg, signedRandom, bufferToNumber<std::int64_t>(asString.data(), asString.size(), base));
}
}
// stringToNumber() with spaces at the beginning, leading zeroes, different types and other corner cases
CPPUNIT_ASSERT_EQUAL(1, stringToNumber<int32>("01"));
CPPUNIT_ASSERT_EQUAL(1, stringToNumber<int32>(L"01"s));
CPPUNIT_ASSERT_EQUAL(1, stringToNumber<int32>(u"01"s));
CPPUNIT_ASSERT_EQUAL(-23, stringToNumber<int32>(" - 023"s));
CPPUNIT_ASSERT_EQUAL(-23, bufferToNumber<int32>(" - 023", 6));
CPPUNIT_ASSERT_EQUAL(1u, stringToNumber<uint32>("01"));
CPPUNIT_ASSERT_EQUAL(1u, stringToNumber<uint32>(L"01"s));
CPPUNIT_ASSERT_EQUAL(1u, stringToNumber<uint32>(u"01"s));
CPPUNIT_ASSERT_EQUAL(23u, stringToNumber<uint32>(" 023"s));
CPPUNIT_ASSERT_EQUAL(23u, bufferToNumber<uint32>(" 023", 5));
CPPUNIT_ASSERT_EQUAL(255u, stringToNumber<uint32>("fF", 16));
CPPUNIT_ASSERT_THROW(stringToNumber<uint32>("fF", 15), ConversionException);
CPPUNIT_ASSERT_THROW(stringToNumber<uint32>("(", 15), ConversionException);
CPPUNIT_ASSERT_EQUAL(1, stringToNumber<std::int32_t>("01"));
CPPUNIT_ASSERT_EQUAL(1, stringToNumber<std::int32_t>(L"01"s));
CPPUNIT_ASSERT_EQUAL(1, stringToNumber<std::int32_t>(u"01"s));
CPPUNIT_ASSERT_EQUAL(-23, stringToNumber<std::int32_t>(" - 023"s));
CPPUNIT_ASSERT_EQUAL(-23, bufferToNumber<std::int32_t>(" - 023", 6));
CPPUNIT_ASSERT_EQUAL(1u, stringToNumber<std::uint32_t>("01"));
CPPUNIT_ASSERT_EQUAL(1u, stringToNumber<std::uint32_t>(L"01"s));
CPPUNIT_ASSERT_EQUAL(1u, stringToNumber<std::uint32_t>(u"01"s));
CPPUNIT_ASSERT_EQUAL(23u, stringToNumber<std::uint32_t>(" 023"s));
CPPUNIT_ASSERT_EQUAL(23u, bufferToNumber<std::uint32_t>(" 023", 5));
CPPUNIT_ASSERT_EQUAL(255u, stringToNumber<std::uint32_t>("fF", 16));
CPPUNIT_ASSERT_THROW(stringToNumber<std::uint32_t>("fF", 15), ConversionException);
CPPUNIT_ASSERT_THROW(stringToNumber<std::uint32_t>("(", 15), ConversionException);
// interpretIntegerAsString()
CPPUNIT_ASSERT_EQUAL("TEST"s, interpretIntegerAsString<uint32>(0x54455354));
CPPUNIT_ASSERT_EQUAL("TEST"s, interpretIntegerAsString<std::uint32_t>(0x54455354));
// splitString() / joinStrings()
vector<string> splitTestExpected({ "1", "2,3" });
@ -327,13 +327,13 @@ void ConversionTests::testStringConversions()
CPPUNIT_ASSERT_EQUAL("foo"s, truncateTest);
// encodeBase64() / decodeBase64() with random data
uniform_int_distribution<byte> randomDistChar;
byte originalBase64Data[4047];
for (byte &c : originalBase64Data) {
uniform_int_distribution<std::uint8_t> randomDistChar;
std::uint8_t originalBase64Data[4047];
for (std::uint8_t &c : originalBase64Data) {
c = randomDistChar(m_randomEngine);
}
auto encodedBase64Data = encodeBase64(originalBase64Data, sizeof(originalBase64Data));
auto decodedBase64Data = decodeBase64(encodedBase64Data.data(), static_cast<uint32>(encodedBase64Data.size()));
auto decodedBase64Data = decodeBase64(encodedBase64Data.data(), static_cast<std::uint32_t>(encodedBase64Data.size()));
CPPUNIT_ASSERT(decodedBase64Data.second == sizeof(originalBase64Data));
for (unsigned int i = 0; i < sizeof(originalBase64Data); ++i) {
CPPUNIT_ASSERT(decodedBase64Data.first[i] == originalBase64Data[i]);
@ -341,11 +341,11 @@ void ConversionTests::testStringConversions()
// test padding
encodedBase64Data = encodeBase64(originalBase64Data, sizeof(originalBase64Data) - 1);
CPPUNIT_ASSERT_EQUAL('=', encodedBase64Data.at(encodedBase64Data.size() - 1));
CPPUNIT_ASSERT_NO_THROW(decodeBase64(encodedBase64Data.data(), static_cast<uint32>(encodedBase64Data.size())));
CPPUNIT_ASSERT_NO_THROW(decodeBase64(encodedBase64Data.data(), static_cast<std::uint32_t>(encodedBase64Data.size())));
encodedBase64Data = encodeBase64(originalBase64Data, sizeof(originalBase64Data) - 2);
CPPUNIT_ASSERT_EQUAL('=', encodedBase64Data.at(encodedBase64Data.size() - 1));
CPPUNIT_ASSERT_EQUAL('=', encodedBase64Data.at(encodedBase64Data.size() - 2));
CPPUNIT_ASSERT_NO_THROW(decodeBase64(encodedBase64Data.data(), static_cast<uint32>(encodedBase64Data.size())));
CPPUNIT_ASSERT_NO_THROW(decodeBase64(encodedBase64Data.data(), static_cast<std::uint32_t>(encodedBase64Data.size())));
// test check for invalid size
CPPUNIT_ASSERT_THROW(decodeBase64(encodedBase64Data.data(), 3), ConversionException);

View File

@ -140,9 +140,9 @@ void IoTests::testBinaryReader()
testFile.seekg(-4, ios_base::cur);
CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringLE(5, 0x0066));
testFile.seekg(-4, ios_base::cur);
CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringBE(static_cast<uint16>(0x6600)));
CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringBE(static_cast<std::uint16_t>(0x6600)));
testFile.seekg(-4, ios_base::cur);
CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringLE(static_cast<uint16>(0x0066)));
CPPUNIT_ASSERT_EQUAL("de"s, reader.readMultibyteTerminatedStringLE(static_cast<std::uint16_t>(0x0066)));
CPPUNIT_ASSERT_THROW(reader.readLengthPrefixedString(), ConversionException);
CPPUNIT_ASSERT_MESSAGE("pos in stream not advanced on conversion error", reader.readByte() == 0);
@ -243,23 +243,22 @@ void IoTests::testBinaryWriter()
*/
void IoTests::testBitReader()
{
const byte testData[] = { 0x81, 0x90, 0x3C, 0x44, 0x28, 0x00, 0x44, 0x10, 0x20, 0xFF, 0xFA };
const std::uint8_t testData[] = { 0x81, 0x90, 0x3C, 0x44, 0x28, 0x00, 0x44, 0x10, 0x20, 0xFF, 0xFA };
BitReader reader(reinterpret_cast<const char *>(testData), sizeof(testData));
CPPUNIT_ASSERT(reader.readBit() == 1);
reader.skipBits(6);
CPPUNIT_ASSERT_EQUAL(static_cast<byte>(3), reader.showBits<byte>(2));
CPPUNIT_ASSERT_EQUAL(static_cast<byte>(3), reader.readBits<byte>(2));
CPPUNIT_ASSERT_EQUAL(static_cast<uint32>(0x103C4428 << 1), reader.readBits<uint32>(32));
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(3), reader.showBits<std::uint8_t>(2));
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(3), reader.readBits<std::uint8_t>(2));
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint32_t>(0x103C4428 << 1), reader.readBits<std::uint32_t>(32));
reader.align();
CPPUNIT_ASSERT_EQUAL(static_cast<byte>(0x44), reader.readBits<byte>(8));
CPPUNIT_ASSERT_EQUAL(static_cast<byte>(7), reader.readUnsignedExpGolombCodedBits<byte>());
CPPUNIT_ASSERT_EQUAL(static_cast<sbyte>(4), reader.readSignedExpGolombCodedBits<sbyte>());
CPPUNIT_ASSERT_EQUAL(static_cast<byte>(0), reader.readBit());
CPPUNIT_ASSERT_EQUAL(static_cast<byte>(0), reader.readBit());
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(0x44), reader.readBits<std::uint8_t>(8));
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(7), reader.readUnsignedExpGolombCodedBits<std::uint8_t>());
CPPUNIT_ASSERT_EQUAL(static_cast<std::int8_t>(4), reader.readSignedExpGolombCodedBits<std::int8_t>());
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(0), reader.readBit());
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(0), reader.readBit());
reader.skipBits(8 + 4);
CPPUNIT_ASSERT_EQUAL(4_st, reader.bitsAvailable());
CPPUNIT_ASSERT_EQUAL(static_cast<byte>(0xA), reader.readBits<byte>(4));
}
CPPUNIT_ASSERT_EQUAL(static_cast<std::uint8_t>(0xA), reader.readBits<std::uint8_t>(4));
CPPUNIT_ASSERT_THROW(reader.readBit(), std::ios_base::failure);
CPPUNIT_ASSERT_THROW(reader.skipBits(1), std::ios_base::failure);
reader.reset(reinterpret_cast<const char *>(testData), sizeof(testData));
@ -358,7 +357,7 @@ void IoTests::testCopy()
// test
testFile.seekg(0);
for (byte i = 0; i < 50; ++i) {
for (auto i = 0; i < 50; ++i) {
CPPUNIT_ASSERT(testFile.get() == outputStream.get());
}
}

View File

@ -52,7 +52,6 @@ public:
CPPUNIT_TEST_SUITE_REGISTRATION(MathTests);
void MathTests::testDigitsum()
{
CPPUNIT_ASSERT_EQUAL(0, digitsum(0));

View File

@ -2,8 +2,6 @@
#define TESTUTILS_H
#include "../application/argumentparser.h"
#include "../conversion/stringbuilder.h" // FIXME: remove in v5
#include "../conversion/types.h"
#include "../misc/traits.h"
#include <iomanip>
@ -23,7 +21,7 @@ enum class WorkingCopyMode {
class CPP_UTILITIES_EXPORT TestApplication {
public:
explicit TestApplication();
explicit TestApplication(int argc, const char * const *argv);
explicit TestApplication(int argc, const char *const *argv);
~TestApplication();
operator bool() const;
@ -279,18 +277,18 @@ constexpr std::size_t operator"" _st(unsigned long long size)
* \brief Literal for uint64 to ease asserting uint64 with CPPUNIT_ASSERT_EQUAL.
* \remarks Just using "ul"-suffix does not compile under 32-bit architecture!
*/
constexpr uint64 operator"" _uint64(unsigned long long size)
constexpr std::uint64_t operator"" _uint64(unsigned long long size)
{
return static_cast<uint64>(size);
return static_cast<std::uint64_t>(size);
}
/*!
* \brief Literal for int64 to ease asserting int64 with CPPUNIT_ASSERT_EQUAL.
* \remarks Just using "l"-suffix does not compile under 32-bit architecture!
*/
constexpr int64 operator"" _int64(unsigned long long size)
constexpr std::int64_t operator"" _int64(unsigned long long size)
{
return static_cast<int64>(size);
return static_cast<std::int64_t>(size);
}
} // namespace Literals
} // namespace TestUtilities