Browse Source

Remove types

sendfile
Martchus 3 years ago
parent
commit
9a50d2b8df
  1. 1
      CMakeLists.txt
  2. 14
      chrono/datetime.cpp
  3. 23
      chrono/datetime.h
  4. 40
      chrono/timespan.h
  5. 30
      conversion/binaryconversion.h
  6. 124
      conversion/binaryconversionprivate.h
  7. 20
      conversion/stringconversion.cpp
  8. 6
      conversion/stringconversion.h
  9. 74
      conversion/types.h
  10. 34
      io/binaryreader.cpp
  11. 240
      io/binaryreader.h
  12. 6
      io/binarywriter.cpp
  13. 224
      io/binarywriter.h
  14. 38
      io/bitreader.h
  15. 14
      math/math.cpp
  16. 9
      math/math.h
  17. 110
      tests/conversiontests.cpp
  18. 27
      tests/iotests.cpp
  19. 1
      tests/mathtests.cpp
  20. 12
      tests/testutils.h

1
CMakeLists.txt

@ -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

14
chrono/datetime.cpp

@ -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);
}
/*!

23
chrono/datetime.h

@ -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;
}

40
chrono/timespan.h

@ -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;
}

30
conversion/binaryconversion.h

@ -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))

124
conversion/binaryconversionprivate.h

@ -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);
}

20
conversion/stringconversion.cpp

@ -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';

6
conversion/stringconversion.h

@ -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

74
conversion/types.h

@ -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

34
io/binaryreader.cpp

@ -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,

240
io/binaryreader.h

@ -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()
/*!