Browse Source

Have everything in one top-level namespace

sendfile
Martchus 3 years ago
parent
commit
b48b2f5c06
  1. 16
      application/argumentparser.cpp
  2. 27
      application/argumentparser.h
  3. 6
      application/argumentparserprivate.h
  4. 4
      application/commandlineutils.cpp
  5. 4
      application/commandlineutils.h
  6. 4
      application/fakeqtconfigarguments.cpp
  7. 6
      application/fakeqtconfigarguments.h
  8. 8
      chrono/datetime.cpp
  9. 8
      chrono/datetime.h
  10. 10
      chrono/format.h
  11. 6
      chrono/period.cpp
  12. 4
      chrono/period.h
  13. 8
      chrono/timespan.cpp
  14. 11
      chrono/timespan.h
  15. 4
      conversion/binaryconversion.h
  16. 4
      conversion/conversionexception.cpp
  17. 4
      conversion/conversionexception.h
  18. 4
      conversion/stringbuilder.h
  19. 11
      conversion/stringconversion.cpp
  20. 8
      conversion/stringconversion.h
  21. 4
      io/ansiescapecodes.cpp
  22. 2
      io/ansiescapecodes.h
  23. 11
      io/binaryreader.cpp
  24. 76
      io/binaryreader.h
  25. 8
      io/binarywriter.cpp
  26. 76
      io/binarywriter.h
  27. 4
      io/bitreader.cpp
  28. 4
      io/bitreader.h
  29. 4
      io/copy.h
  30. 4
      io/inifile.cpp
  31. 4
      io/inifile.h
  32. 4
      io/misc.cpp
  33. 2
      io/misc.h
  34. 4
      io/nativefilestream.cpp
  35. 4
      io/nativefilestream.h
  36. 4
      io/path.cpp
  37. 4
      io/path.h
  38. 11
      misc/levenshtein.cpp
  39. 4
      misc/levenshtein.h
  40. 12
      misc/math.cpp
  41. 4
      misc/math.h
  42. 4
      misc/multiarray.h
  43. 4
      misc/parseerror.cpp
  44. 4
      misc/parseerror.h
  45. 8
      misc/traits.h
  46. 11
      tests/argumentparsertests.cpp
  47. 5
      tests/chronotests.cpp
  48. 3
      tests/conversiontests.cpp
  49. 2
      tests/cppunit.h
  50. 15
      tests/iotests.cpp
  51. 8
      tests/mathtests.cpp
  52. 8
      tests/misctests.cpp
  53. 6
      tests/outputcheck.h
  54. 9
      tests/testutils.cpp
  55. 23
      tests/testutils.h
  56. 2
      tests/traitstests.cpp

16
application/argumentparser.cpp

@ -21,15 +21,13 @@
using namespace std;
using namespace std::placeholders;
using namespace std::literals;
using namespace ConversionUtilities;
using namespace EscapeCodes;
using namespace IoUtilities;
using namespace CppUtilities::EscapeCodes;
/*!
* \namespace ApplicationUtilities
* \brief Contains currently only ArgumentParser and related classes.
* \namespace CppUtilities
* \brief Contains all utilities provides by the c++utilities library.
*/
namespace ApplicationUtilities {
namespace CppUtilities {
/*!
* \brief The ArgumentDenotationType enum specifies the type of a given argument denotation.
@ -82,7 +80,7 @@ struct ArgumentSuggestion {
ArgumentSuggestion::ArgumentSuggestion(const char *unknownArg, size_t unknownArgSize, const char *suggestion, size_t suggestionSize, bool isOperation)
: suggestion(suggestion)
, suggestionSize(suggestionSize)
, editingDistance(MiscUtilities::computeDamerauLevenshteinDistance(unknownArg, unknownArgSize, suggestion, suggestionSize))
, editingDistance(computeDamerauLevenshteinDistance(unknownArg, unknownArgSize, suggestion, suggestionSize))
, hasDashPrefix(isOperation)
{
}
@ -1022,7 +1020,7 @@ bool ArgumentParser::isUncombinableMainArgPresent() const
* - Verifies the sub arguments, too.
* - For debugging purposes only; hence only used in debug builds.
*/
void ApplicationUtilities::ArgumentParser::verifyArgs(const ArgumentVector &args)
void ArgumentParser::verifyArgs(const ArgumentVector &args)
{
vector<const Argument *> verifiedArgs;
verifiedArgs.reserve(args.size());
@ -1745,4 +1743,4 @@ void ArgumentOccurrence::throwNumberOfValuesNotSufficient(unsigned long valuesTo
" have been specified."));
}
} // namespace ApplicationUtilities
} // namespace CppUtilities

27
application/argumentparser.h

@ -2,7 +2,6 @@
#define APPLICATION_UTILITIES_ARGUMENTPARSER_H
#include "../conversion/stringconversion.h"
#include "../global.h"
#include "../misc/traits.h"
#include <functional>
@ -13,9 +12,9 @@
#include <cassert>
#endif
class ArgumentParserTests;
class ArgumentParserTests; // not a public class (only used for internal tests)
namespace ApplicationUtilities {
namespace CppUtilities {
/*!
* \brief Stores information about an application.
@ -42,7 +41,7 @@ CPP_UTILITIES_EXPORT extern ApplicationInfo applicationInfo;
* used by ArgumentParser::printHelp().
* \remarks Reads those data from the config header so "config.h" must be included.
*/
#define SET_DEPENDENCY_INFO ::ApplicationUtilities::applicationInfo.dependencyVersions = DEPENCENCY_VERSIONS
#define SET_DEPENDENCY_INFO ::CppUtilities::applicationInfo.dependencyVersions = DEPENCENCY_VERSIONS
/*!
* \def SET_APPLICATION_INFO
@ -50,13 +49,13 @@ CPP_UTILITIES_EXPORT extern ApplicationInfo applicationInfo;
* \remarks Reads those data from the config header so "config.h" must be included.
*/
#define SET_APPLICATION_INFO \
::ApplicationUtilities::applicationInfo.name = APP_NAME; \
::ApplicationUtilities::applicationInfo.author = APP_AUTHOR; \
::ApplicationUtilities::applicationInfo.version = APP_VERSION; \
::ApplicationUtilities::applicationInfo.url = APP_URL; \
::ApplicationUtilities::applicationInfo.description = APP_DESCRIPTION; \
::ApplicationUtilities::applicationInfo.license = PROJECT_LICENSE; \
::ApplicationUtilities::applicationInfo.credits = APP_CREDITS; \
::CppUtilities::applicationInfo.name = APP_NAME; \
::CppUtilities::applicationInfo.author = APP_AUTHOR; \
::CppUtilities::applicationInfo.version = APP_VERSION; \
::CppUtilities::applicationInfo.url = APP_URL; \
::CppUtilities::applicationInfo.description = APP_DESCRIPTION; \
::CppUtilities::applicationInfo.license = PROJECT_LICENSE; \
::CppUtilities::applicationInfo.credits = APP_CREDITS; \
SET_DEPENDENCY_INFO
class Argument;
@ -149,7 +148,7 @@ template <typename TargetType, Traits::EnableIf<std::is_same<TargetType, std::st
template <typename TargetType, Traits::EnableIf<std::is_arithmetic<TargetType>> * = nullptr> TargetType convert(const char *value)
{
return ConversionUtilities::stringToNumber<TargetType>(value);
return stringToNumber<TargetType>(value);
}
/// \cond
@ -176,7 +175,7 @@ template <typename FirstTargetType, typename... RemainingTargetTypes> struct Arg
// FIXME: maybe use std::expected here when available
try {
return std::make_tuple<FirstTargetType>(ValueConversion::convert<FirstTargetType>(*firstValue));
} catch (const ConversionUtilities::ConversionException &exception) {
} catch (const ConversionException &exception) {
throw ArgumentValueConversionError{ exception.what(), *firstValue, typeid(FirstTargetType).name() };
}
}
@ -1203,6 +1202,6 @@ inline NoColorArgument &ArgumentParser::noColorArg()
return m_noColorArg;
}
} // namespace ApplicationUtilities
} // namespace CppUtilities
#endif // APPLICATION_UTILITIES_ARGUMENTPARSER_H

6
application/argumentparserprivate.h

@ -4,12 +4,12 @@
#include "./argumentparser.h"
#include "./commandlineutils.h"
namespace ApplicationUtilities {
namespace CppUtilities {
class CPP_UTILITIES_EXPORT ArgumentReader {
public:
ArgumentReader(ArgumentParser &parser, const char *const *argv, const char *const *end, bool completionMode = false);
ApplicationUtilities::ArgumentReader &reset(const char *const *argv, const char *const *end);
ArgumentReader &reset(const char *const *argv, const char *const *end);
bool read();
bool read(ArgumentVector &args);
@ -56,6 +56,6 @@ inline Wrapper::Wrapper(const char *str, Indentation currentIndentation)
{
}
} // namespace ApplicationUtilities
} // namespace CppUtilities
#endif // APPLICATION_UTILITIES_ARGUMENTPARSER_PRIVATE_H

4
application/commandlineutils.cpp

@ -13,7 +13,7 @@
using namespace std;
namespace ApplicationUtilities {
namespace CppUtilities {
/*!
* \brief Prompts for confirmation displaying the specified \a message.
@ -158,4 +158,4 @@ pair<vector<unique_ptr<char[]>>, vector<char *>> convertArgsToUtf8()
}
#endif
} // namespace ApplicationUtilities
} // namespace CppUtilities

4
application/commandlineutils.h

@ -10,7 +10,7 @@
#include <vector>
#endif
namespace ApplicationUtilities {
namespace CppUtilities {
/*!
* \brief The Response enum is used to specify the default response for the confirmPrompt() method.
@ -88,6 +88,6 @@ inline CPP_UTILITIES_EXPORT std::ostream &operator<<(std::ostream &out, Indentat
return out;
}
} // namespace ApplicationUtilities
} // namespace CppUtilities
#endif // APPLICATIONUTILITIES_COMMANDLINEUTILS_H

4
application/fakeqtconfigarguments.cpp

@ -1,6 +1,6 @@
#include "./fakeqtconfigarguments.h"
namespace ApplicationUtilities {
namespace CppUtilities {
/*!
* \class FakeQtConfigArguments
@ -20,4 +20,4 @@ FakeQtConfigArguments::FakeQtConfigArguments()
{
}
} // namespace ApplicationUtilities
} // namespace CppUtilities

6
application/fakeqtconfigarguments.h

@ -3,7 +3,7 @@
#include "./argumentparser.h"
namespace ApplicationUtilities {
namespace CppUtilities {
class CPP_UTILITIES_EXPORT FakeQtConfigArguments {
public:
@ -43,10 +43,10 @@ inline bool FakeQtConfigArguments::areQtGuiArgsPresent() const
return m_qtWidgetsGuiArg.isPresent() || m_qtQuickGuiArg.isPresent();
}
} // namespace ApplicationUtilities
} // namespace CppUtilities
#ifndef QT_CONFIG_ARGUMENTS
#define QT_CONFIG_ARGUMENTS ApplicationUtilities::FakeQtConfigArguments
#define QT_CONFIG_ARGUMENTS CppUtilities::FakeQtConfigArguments
#endif
#endif // APPLICATIONUTILITIES_FAKEQTCONFIGARGUMENTS_H

8
chrono/datetime.cpp

@ -8,8 +8,8 @@
#include <stdexcept>
using namespace std;
using namespace ChronoUtilities;
using namespace ConversionUtilities;
namespace CppUtilities {
const int DateTime::m_daysPerYear = 365;
const int DateTime::m_daysPer4Years = 1461;
@ -34,7 +34,7 @@ template <typename num1, typename num2, typename num3> constexpr bool inRangeExc
}
/*!
* \class ChronoUtilities::DateTime
* \class DateTime
* \brief Represents an instant in time, typically expressed as a date and time of day.
* \remarks
* - Time values are measured in 100-nanosecond units called ticks,
@ -407,3 +407,5 @@ int DateTime::getDatePart(DatePart part) const
}
return 0;
}
} // namespace CppUtilities

8
chrono/datetime.h

@ -8,7 +8,7 @@
#include <limits>
#include <string>
namespace ChronoUtilities {
namespace CppUtilities {
/*!
* \brief Specifies the output format.
@ -513,11 +513,11 @@ inline DateTime &DateTime::operator-=(const TimeSpan &timeSpan)
m_ticks -= timeSpan.m_ticks;
return *this;
}
} // namespace ChronoUtilities
} // namespace CppUtilities
namespace std {
template <> struct hash<ChronoUtilities::DateTime> {
inline size_t operator()(const ChronoUtilities::DateTime &dateTime) const
template <> struct hash<CppUtilities::DateTime> {
inline size_t operator()(const CppUtilities::DateTime &dateTime) const
{
return hash<decltype(dateTime.totalTicks())>()(dateTime.totalTicks());
}

10
chrono/format.h

@ -6,17 +6,17 @@
#include <ostream>
inline std::ostream &operator<<(std::ostream &out, const ChronoUtilities::DateTime &value)
inline std::ostream &operator<<(std::ostream &out, const CppUtilities::DateTime &value)
{
return out << value.toString(ChronoUtilities::DateTimeOutputFormat::DateAndTime, false);
return out << value.toString(CppUtilities::DateTimeOutputFormat::DateAndTime, false);
}
inline std::ostream &operator<<(std::ostream &out, const ChronoUtilities::TimeSpan &value)
inline std::ostream &operator<<(std::ostream &out, const CppUtilities::TimeSpan &value)
{
return out << value.toString(ChronoUtilities::TimeSpanOutputFormat::Normal, false);
return out << value.toString(CppUtilities::TimeSpanOutputFormat::Normal, false);
}
inline std::ostream &operator<<(std::ostream &out, const ChronoUtilities::Period &value)
inline std::ostream &operator<<(std::ostream &out, const CppUtilities::Period &value)
{
return out << value.years() << " years, " << value.months() << " months, " << value.days() << " days";
}

6
chrono/period.cpp

@ -1,9 +1,9 @@
#include "./period.h"
namespace ChronoUtilities {
namespace CppUtilities {
/*!
* \class ChronoUtilities::Period
* \class Period
* \brief Represents a period of time.
*
* In contrast to the TimeSpan class, a Period represents a duration between a concrete
@ -78,4 +78,4 @@ DateTime operator+(DateTime begin, Period period)
return DateTime::fromDate(year, month, day) + begin.timeOfDay();
}
} // namespace ChronoUtilities
} // namespace CppUtilities

4
chrono/period.h

@ -3,7 +3,7 @@
#include "./datetime.h"
namespace ChronoUtilities {
namespace CppUtilities {
class CPP_UTILITIES_EXPORT Period {
public:
@ -52,6 +52,6 @@ constexpr int Period::days() const
DateTime CPP_UTILITIES_EXPORT operator+(DateTime begin, Period period);
} // namespace ChronoUtilities
} // namespace CppUtilities
#endif // CHRONO_UTILITIES_PERIOD_H

8
chrono/timespan.cpp

@ -8,11 +8,11 @@
#include <vector>
using namespace std;
using namespace ChronoUtilities;
using namespace ConversionUtilities;
namespace CppUtilities {
/*!
* \class ChronoUtilities::TimeSpan
* \class TimeSpan
* \brief Represents a time interval.
*
* Note that the TimeSpan class is meant to express a time interval independently of the
@ -181,3 +181,5 @@ void TimeSpan::toString(string &result, TimeSpanOutputFormat format, bool fullSe
}
result = s.str();
}
} // namespace CppUtilities

11
chrono/timespan.h

@ -8,10 +8,7 @@
#include <limits>
#include <string>
/*!
* \brief Contains classes providing a means for handling date and time information.
*/
namespace ChronoUtilities {
namespace CppUtilities {
class DateTime;
@ -409,11 +406,11 @@ constexpr inline bool TimeSpan::isInfinity() const
{
return m_ticks == std::numeric_limits<decltype(m_ticks)>::max();
}
} // namespace ChronoUtilities
} // namespace CppUtilities
namespace std {
template <> struct hash<ChronoUtilities::TimeSpan> {
inline size_t operator()(const ChronoUtilities::TimeSpan &timeSpan) const
template <> struct hash<CppUtilities::TimeSpan> {
inline size_t operator()(const CppUtilities::TimeSpan &timeSpan) const
{
return hash<decltype(timeSpan.totalTicks())>()(timeSpan.totalTicks());
}

4
conversion/binaryconversion.h

@ -71,7 +71,7 @@
#error "Middle endian byte order is not supported!"
#endif
namespace ConversionUtilities {
namespace CppUtilities {
/*!
* \brief Encapsulates binary conversion functions using the big endian byte order.
@ -173,6 +173,6 @@ CPP_UTILITIES_EXPORT constexpr std::uint64_t swapOrder(std::uint64_t value)
| ((value & 0x000000FF00000000) >> (1 * 8)) | ((value & 0x00000000FF000000) << (1 * 8)) | ((value & 0x0000000000FF0000) << (3 * 8))
| ((value & 0x000000000000FF00) << (5 * 8)) | ((value) << (7 * 8));
}
} // namespace ConversionUtilities
} // namespace CppUtilities
#endif // CONVERSION_UTILITIES_BINARY_CONVERSION_H

4
conversion/conversionexception.cpp

@ -1,6 +1,6 @@
#include "./conversionexception.h"
namespace ConversionUtilities {
namespace CppUtilities {
/*!
* \brief Destroys the ConversionException.
@ -9,4 +9,4 @@ ConversionException::~ConversionException()
{
}
} // namespace ConversionUtilities
} // namespace CppUtilities

4
conversion/conversionexception.h

@ -6,7 +6,7 @@
#include <stdexcept>
#include <string>
namespace ConversionUtilities {
namespace CppUtilities {
class CPP_UTILITIES_EXPORT ConversionException : public std::runtime_error {
public:
@ -48,6 +48,6 @@ inline ConversionException::ConversionException(const char *what) noexcept
{
}
} // namespace ConversionUtilities
} // namespace CppUtilities
#endif // CONVERSION_UTILITIES_CONVERSIONEXCEPTION_H

4
conversion/stringbuilder.h

@ -7,7 +7,7 @@
#include <string>
#include <tuple>
namespace ConversionUtilities {
namespace CppUtilities {
/// \cond
namespace Helper {
@ -259,6 +259,6 @@ inline std::string operator+(const Tuple &lhs, IntegralType rhs)
{
return tupleToString(std::tuple_cat(lhs, std::make_tuple(rhs)));
}
} // namespace ConversionUtilities
} // namespace CppUtilities
#endif // CONVERSION_UTILITIES_STRINGBUILDER_H

11
conversion/stringconversion.cpp

@ -22,14 +22,7 @@
using namespace std;
/*!
* \namespace ConversionUtilities
* \brief Contains several functions providing conversions between different data types.
*
* binaryconversion.h declares functions which convert base data types to an array of bytes and vice versa.
* stringconversion.h declares different functions around string conversion such as converting a number to a string and vice versa.
*/
namespace ConversionUtilities {
namespace CppUtilities {
/// \cond
@ -414,4 +407,4 @@ pair<unique_ptr<std::uint8_t[]>, std::uint32_t> decodeBase64(const char *encoded
}
return make_pair(move(buffer), decodedSize);
}
} // namespace ConversionUtilities
} // namespace CppUtilities

8
conversion/stringconversion.h

@ -16,7 +16,7 @@
#include <string>
#include <vector>
namespace ConversionUtilities {
namespace CppUtilities {
/*!
* \brief The StringDataDeleter struct deletes the data of a StringData instance.
@ -298,7 +298,7 @@ template <typename CharType> constexpr CharType digitToChar(CharType digit)
* \sa stringToNumber()
*/
template <typename IntegralType, class StringType = std::string,
Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr>
CppUtilities::Traits::EnableIf<std::is_integral<IntegralType>, std::is_unsigned<IntegralType>> * = nullptr>
StringType numberToString(IntegralType number, typename StringType::value_type base = 10)
{
std::size_t resSize = 0;
@ -617,7 +617,7 @@ IntegralType bufferToNumber(const CharType *string, std::size_t size, unsigned c
template <typename T> std::string interpretIntegerAsString(T integer, int startOffset = 0)
{
char buffer[sizeof(T)];
ConversionUtilities::BE::getBytes(integer, buffer);
BE::getBytes(integer, buffer);
return std::string(buffer + startOffset, sizeof(T) - startOffset);
}
@ -625,6 +625,6 @@ CPP_UTILITIES_EXPORT std::string dataSizeToString(std::uint64_t sizeInByte, bool
CPP_UTILITIES_EXPORT std::string bitrateToString(double speedInKbitsPerSecond, bool useByteInsteadOfBits = false);
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
} // namespace CppUtilities
#endif // CONVERSION_UTILITIES_STRINGCONVERSION_H

4
io/ansiescapecodes.cpp

@ -1,5 +1,7 @@
#include "./ansiescapecodes.h"
namespace CppUtilities {
/*!
* \brief Encapsulates functions for formatted terminal output using ANSI escape codes.
*/
@ -107,3 +109,5 @@ std::ostream &operator<<(std::ostream &stream, Phrases phrase)
}
} // namespace EscapeCodes
} // namespace CppUtilities

2
io/ansiescapecodes.h

@ -7,6 +7,7 @@
#include <ostream>
#include <tuple>
namespace CppUtilities {
namespace EscapeCodes {
extern CPP_UTILITIES_EXPORT bool enabled;
@ -150,5 +151,6 @@ enum class Phrases {
CPP_UTILITIES_EXPORT std::ostream &operator<<(std::ostream &stream, Phrases phrase);
} // namespace EscapeCodes
} // namespace CppUtilities
#endif // IOUTILITIES_ANSIESCAPECODES

11
io/binaryreader.cpp

@ -7,16 +7,11 @@
#include <sstream>
using namespace std;
using namespace IoUtilities;
using namespace ConversionUtilities;
/*!
* \namespace IoUtilities
* \brief Contains utility classes helping to read and write streams.
*/
namespace CppUtilities {
/*!
* \class IoUtilities::BinaryReader
* \class BinaryReader
* \brief Reads primitive data types from a std::istream.
* \remarks Supports both, little endian and big endian.
* \sa For automatic serialization of structs, see https://github.com/Martchus/reflective-rapidjson.
@ -192,3 +187,5 @@ const std::uint32_t BinaryReader::crc32Table[] = { 0x00000000, 0x04c11db7, 0x098
0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18,
0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c,
0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 };
} // namespace CppUtilities

76
io/binaryreader.h

@ -7,7 +7,7 @@
#include <string>
#include <vector>
namespace IoUtilities {
namespace CppUtilities {
class CPP_UTILITIES_EXPORT BinaryReader {
public:
@ -242,7 +242,7 @@ inline void BinaryReader::read(std::vector<char> &buffer, std::streamsize length
inline std::int16_t BinaryReader::readInt16BE()
{
m_stream->read(m_buffer, sizeof(std::int16_t));
return ConversionUtilities::BE::toInt16(m_buffer);
return BE::toInt16(m_buffer);
}
/*!
@ -251,7 +251,7 @@ inline std::int16_t BinaryReader::readInt16BE()
inline std::uint16_t BinaryReader::readUInt16BE()
{
m_stream->read(m_buffer, sizeof(std::uint16_t));
return ConversionUtilities::BE::toUInt16(m_buffer);
return BE::toUInt16(m_buffer);
}
/*!
@ -261,7 +261,7 @@ inline std::int32_t BinaryReader::readInt24BE()
{
*m_buffer = 0;
m_stream->read(m_buffer + 1, 3);
auto val = ConversionUtilities::BE::toInt32(m_buffer);
auto val = BE::toInt32(m_buffer);
if (val >= 0x800000) {
val = -(0x1000000 - val);
}
@ -275,7 +275,7 @@ inline std::uint32_t BinaryReader::readUInt24BE()
{
*m_buffer = 0;
m_stream->read(m_buffer + 1, 3);
return ConversionUtilities::BE::toUInt32(m_buffer);
return BE::toUInt32(m_buffer);
}
/*!
@ -284,7 +284,7 @@ inline std::uint32_t BinaryReader::readUInt24BE()
inline std::int32_t BinaryReader::readInt32BE()
{
m_stream->read(m_buffer, sizeof(std::int32_t));
return ConversionUtilities::BE::toInt32(m_buffer);
return BE::toInt32(m_buffer);
}
/*!
@ -293,7 +293,7 @@ inline std::int32_t BinaryReader::readInt32BE()
inline std::uint32_t BinaryReader::readUInt32BE()
{
m_stream->read(m_buffer, sizeof(std::uint32_t));
return ConversionUtilities::BE::toUInt32(m_buffer);
return BE::toUInt32(m_buffer);
}
/*!
@ -303,7 +303,7 @@ inline std::int64_t BinaryReader::readInt40BE()
{
*m_buffer = *(m_buffer + 1) = *(m_buffer + 2) = 0;
m_stream->read(m_buffer + 3, 5);
auto val = ConversionUtilities::BE::toInt64(m_buffer);
auto val = BE::toInt64(m_buffer);
if (val >= 0x8000000000) {
val = -(0x10000000000 - val);
}
@ -317,7 +317,7 @@ inline std::uint64_t BinaryReader::readUInt40BE()
{
*m_buffer = *(m_buffer + 1) = *(m_buffer + 2) = 0;
m_stream->read(m_buffer + 3, 5);
return ConversionUtilities::BE::toUInt64(m_buffer);
return BE::toUInt64(m_buffer);
}
/*!
@ -327,7 +327,7 @@ inline std::int64_t BinaryReader::readInt56BE()
{
*m_buffer = 0;
m_stream->read(m_buffer + 1, 7);
auto val = ConversionUtilities::BE::toInt64(m_buffer);
auto val = BE::toInt64(m_buffer);
if (val >= 0x80000000000000) {
val = -(0x100000000000000 - val);
}
@ -341,7 +341,7 @@ inline std::uint64_t BinaryReader::readUInt56BE()
{
*m_buffer = 0;
m_stream->read(m_buffer + 1, 7);
return ConversionUtilities::BE::toUInt64(m_buffer);
return BE::toUInt64(m_buffer);
}
/*!
@ -350,7 +350,7 @@ inline std::uint64_t BinaryReader::readUInt56BE()
inline std::int64_t BinaryReader::readInt64BE()
{
m_stream->read(m_buffer, sizeof(std::int64_t));
return ConversionUtilities::BE::toInt64(m_buffer);
return BE::toInt64(m_buffer);
}
/*!
@ -359,7 +359,7 @@ inline std::int64_t BinaryReader::readInt64BE()
inline std::uint64_t BinaryReader::readUInt64BE()
{
m_stream->read(m_buffer, sizeof(std::uint64_t));
return ConversionUtilities::BE::toUInt64(m_buffer);
return BE::toUInt64(m_buffer);
}
/*!
@ -369,7 +369,7 @@ inline std::uint64_t BinaryReader::readUInt64BE()
inline std::uint64_t BinaryReader::readVariableLengthUIntBE()
{
bufferVariableLengthInteger();
return ConversionUtilities::BE::toUInt64(m_buffer);
return BE::toUInt64(m_buffer);
}
/*!
@ -378,7 +378,7 @@ inline std::uint64_t BinaryReader::readVariableLengthUIntBE()
inline float BinaryReader::readFloat32BE()
{
m_stream->read(m_buffer, sizeof(float));
return ConversionUtilities::BE::toFloat32(m_buffer);
return BE::toFloat32(m_buffer);
}
/*!
@ -387,7 +387,7 @@ inline float BinaryReader::readFloat32BE()
inline double BinaryReader::readFloat64BE()
{
m_stream->read(m_buffer, sizeof(double));
return ConversionUtilities::BE::toFloat64(m_buffer);
return BE::toFloat64(m_buffer);
}
/*!
@ -396,7 +396,7 @@ inline double BinaryReader::readFloat64BE()
inline std::int16_t BinaryReader::readInt16LE()
{
m_stream->read(m_buffer, sizeof(std::int16_t));
return ConversionUtilities::LE::toInt16(m_buffer);
return LE::toInt16(m_buffer);
}
/*!
@ -405,7 +405,7 @@ inline std::int16_t BinaryReader::readInt16LE()
inline std::uint16_t BinaryReader::readUInt16LE()
{
m_stream->read(m_buffer, sizeof(std::uint16_t));
return ConversionUtilities::LE::toUInt16(m_buffer);
return LE::toUInt16(m_buffer);
}
/*!
@ -415,7 +415,7 @@ inline std::int32_t BinaryReader::readInt24LE()
{
*(m_buffer + 3) = 0;
m_stream->read(m_buffer, 3);
auto val = ConversionUtilities::LE::toInt32(m_buffer);
auto val = LE::toInt32(m_buffer);
if (val >= 0x800000) {
val = -(0x1000000 - val);
}
@ -429,7 +429,7 @@ inline std::uint32_t BinaryReader::readUInt24LE()
{
*(m_buffer + 3) = 0;
m_stream->read(m_buffer, 3);
return ConversionUtilities::LE::toUInt32(m_buffer);
return LE::toUInt32(m_buffer);
}
/*!
@ -438,7 +438,7 @@ inline std::uint32_t BinaryReader::readUInt24LE()
inline std::int32_t BinaryReader::readInt32LE()
{
m_stream->read(m_buffer, sizeof(std::int32_t));
return ConversionUtilities::LE::toInt32(m_buffer);
return LE::toInt32(m_buffer);
}
/*!
@ -447,7 +447,7 @@ inline std::int32_t BinaryReader::readInt32LE()
inline std::uint32_t BinaryReader::readUInt32LE()
{
m_stream->read(m_buffer, sizeof(std::uint32_t));
return ConversionUtilities::LE::toUInt32(m_buffer);
return LE::toUInt32(m_buffer);
}
/*!
@ -457,7 +457,7 @@ inline std::int64_t BinaryReader::readInt40LE()
{
*(m_buffer + 5) = *(m_buffer + 6) = *(m_buffer + 7) = 0;
m_stream->read(m_buffer, 5);
auto val = ConversionUtilities::LE::toInt64(m_buffer);
auto val = LE::toInt64(m_buffer);
if (val >= 0x8000000000) {
val = -(0x10000000000 - val);
}
@ -471,7 +471,7 @@ inline std::uint64_t BinaryReader::readUInt40LE()
{
*(m_buffer + 5) = *(m_buffer + 6) = *(m_buffer + 7) = 0;
m_stream->read(m_buffer, 5);
return ConversionUtilities::LE::toUInt64(m_buffer);
return LE::toUInt64(m_buffer);
}
/*!
@ -481,7 +481,7 @@ inline std::int64_t BinaryReader::readInt56LE()
{
*(m_buffer + 7) = 0;
m_stream->read(m_buffer, 7);
auto val = ConversionUtilities::LE::toInt64(m_buffer);
auto val = LE::toInt64(m_buffer);
if (val >= 0x80000000000000) {
val = -(0x100000000000000 - val);
}
@ -495,7 +495,7 @@ inline std::uint64_t BinaryReader::readUInt56LE()
{
*(m_buffer + 7) = 0;
m_stream->read(m_buffer, 7);
return ConversionUtilities::LE::toUInt64(m_buffer);
return LE::toUInt64(m_buffer);
}
/*!
@ -504,7 +504,7 @@ inline std::uint64_t BinaryReader::readUInt56LE()
inline std::int64_t BinaryReader::readInt64LE()
{
m_stream->read(m_buffer, sizeof(std::int64_t));
return ConversionUtilities::LE::toInt64(m_buffer);
return LE::toInt64(m_buffer);
}
/*!
@ -513,7 +513,7 @@ inline std::int64_t BinaryReader::readInt64LE()
inline std::uint64_t BinaryReader::readUInt64LE()
{
m_stream->read(m_buffer, sizeof(std::uint64_t));
return ConversionUtilities::LE::toUInt64(m_buffer);
return LE::toUInt64(m_buffer);
}
/*!
@ -523,7 +523,7 @@ inline std::uint64_t BinaryReader::readUInt64LE()
inline std::uint64_t BinaryReader::readVariableLengthUIntLE()
{
bufferVariableLengthInteger();
return ConversionUtilities::LE::toUInt64(m_buffer);
return LE::toUInt64(m_buffer);
}
/*!
@ -532,7 +532,7 @@ inline std::uint64_t BinaryReader::readVariableLengthUIntLE()
inline float BinaryReader::readFloat32LE()
{
m_stream->read(m_buffer, sizeof(float));
return ConversionUtilities::LE::toFloat32(m_buffer);
return LE::toFloat32(m_buffer);
}
/*!
@ -541,7 +541,7 @@ inline float BinaryReader::readFloat32LE()
inline double BinaryReader::readFloat64LE()
{
m_stream->read(m_buffer, sizeof(double));
return ConversionUtilities::LE::toFloat64(m_buffer);
return LE::toFloat64(m_buffer);
}
/*!
@ -588,7 +588,7 @@ inline std::string BinaryReader::readLengthPrefixedString()
*/
inline std::uint32_t BinaryReader::readSynchsafeUInt32BE()
{
return ConversionUtilities::toNormalInt(readUInt32BE());
return toNormalInt(readUInt32BE());
}
/*!
@ -596,7 +596,7 @@ inline std::uint32_t BinaryReader::readSynchsafeUInt32BE()
*/
inline float BinaryReader::readFixed8BE()
{
return ConversionUtilities::toFloat32(readUInt16BE());
return toFloat32(readUInt16BE());
}
/*!
@ -604,7 +604,7 @@ inline float BinaryReader::readFixed8BE()
*/
inline float BinaryReader::readFixed16BE()
{
return ConversionUtilities::toFloat32(readUInt32BE());
return toFloat32(readUInt32BE());
}
/*!
@ -614,7 +614,7 @@ inline float BinaryReader::readFixed16BE()
*/
inline std::uint32_t BinaryReader::readSynchsafeUInt32LE()
{
return ConversionUtilities::toNormalInt(readUInt32LE());
return toNormalInt(readUInt32LE());
}
/*!
@ -622,7 +622,7 @@ inline std::uint32_t BinaryReader::readSynchsafeUInt32LE()
*/
inline float BinaryReader::readFixed8LE()
{
return ConversionUtilities::toFloat32(readUInt16LE());
return toFloat32(readUInt16LE());
}
/*!
@ -630,7 +630,7 @@ inline float BinaryReader::readFixed8LE()
*/
inline float BinaryReader::readFixed16LE()
{
return ConversionUtilities::toFloat32(readUInt32LE());
return toFloat32(readUInt32LE());
}
/*!
@ -732,6 +732,6 @@ inline void BinaryReader::read(double &one64BitFloat)
{
one64BitFloat = readFloat64BE();
}
} // namespace IoUtilities
} // namespace CppUtilities
#endif // IOUTILITIES_BINERYREADER_H

8
io/binarywriter.cpp

@ -6,11 +6,11 @@
#include <memory>
using namespace std;
using namespace IoUtilities;
using namespace ConversionUtilities;
namespace CppUtilities {
/*!
* \class IoUtilities::BinaryWriter
* \class BinaryWriter
* \brief Writes primitive data types to a std::ostream.
* \remarks Supports both, little endian and big endian.
* \sa For automatic deserialization of structs, see https://github.com/Martchus/reflective-rapidjson.
@ -59,3 +59,5 @@ void BinaryWriter::writeVariableLengthInteger(std::uint64_t value, void (*getByt
}
m_stream->write(m_buffer + 8 - prefixLength, prefixLength);
}
} // namespace CppUtilities

76
io/binarywriter.h

@ -9,7 +9,7 @@
#include <string>
#include <vector>
namespace IoUtilities {
namespace CppUtilities {
class CPP_UTILITIES_EXPORT BinaryWriter {
public:
@ -248,7 +248,7 @@ inline void BinaryWriter::writeBool(bool value)
*/
inline void BinaryWriter::writeInt16BE(std::int16_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::int16_t));
}
@ -257,7 +257,7 @@ inline void BinaryWriter::writeInt16BE(std::int16_t value)
*/
inline void BinaryWriter::writeUInt16BE(std::uint16_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::uint16_t));
}
@ -267,7 +267,7 @@ inline void BinaryWriter::writeUInt16BE(std::uint16_t value)
*/
inline void BinaryWriter::writeInt24BE(std::int32_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 1, 3);
}
@ -278,7 +278,7 @@ inline void BinaryWriter::writeInt24BE(std::int32_t value)
inline void BinaryWriter::writeUInt24BE(std::uint32_t value)
{
// discard most significant byte
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 1, 3);
}
@ -287,7 +287,7 @@ inline void BinaryWriter::writeUInt24BE(std::uint32_t value)
*/
inline void BinaryWriter::writeInt32BE(std::int32_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::int32_t));
}
@ -296,7 +296,7 @@ inline void BinaryWriter::writeInt32BE(std::int32_t value)
*/
inline void BinaryWriter::writeUInt32BE(std::uint32_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::uint32_t));
}
@ -306,7 +306,7 @@ inline void BinaryWriter::writeUInt32BE(std::uint32_t value)
*/
inline void BinaryWriter::writeInt40BE(std::int64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 3, 5);
}
@ -316,7 +316,7 @@ inline void BinaryWriter::writeInt40BE(std::int64_t value)
*/
inline void BinaryWriter::writeUInt40BE(std::uint64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 3, 5);
}
@ -326,7 +326,7 @@ inline void BinaryWriter::writeUInt40BE(std::uint64_t value)
*/
inline void BinaryWriter::writeInt56BE(std::int64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 1, 7);
}
@ -336,7 +336,7 @@ inline void BinaryWriter::writeInt56BE(std::int64_t value)
*/
inline void BinaryWriter::writeUInt56BE(std::uint64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer + 1, 7);
}
@ -345,7 +345,7 @@ inline void BinaryWriter::writeUInt56BE(std::uint64_t value)
*/
inline void BinaryWriter::writeInt64BE(std::int64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::int64_t));
}
@ -354,7 +354,7 @@ inline void BinaryWriter::writeInt64BE(std::int64_t value)
*/
inline void BinaryWriter::writeUInt64BE(std::uint64_t value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::uint64_t));
}
@ -364,7 +364,7 @@ inline void BinaryWriter::writeUInt64BE(std::uint64_t value)
*/
inline void BinaryWriter::writeVariableLengthUIntBE(std::uint64_t value)
{
writeVariableLengthInteger(value, static_cast<void (*)(std::uint64_t, char *)>(&ConversionUtilities::BE::getBytes));
writeVariableLengthInteger(value, static_cast<void (*)(std::uint64_t, char *)>(&BE::getBytes));
}
/*!
@ -372,7 +372,7 @@ inline void BinaryWriter::writeVariableLengthUIntBE(std::uint64_t value)
*/
inline void BinaryWriter::writeFloat32BE(float value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(float));
}
@ -381,7 +381,7 @@ inline void BinaryWriter::writeFloat32BE(float value)
*/
inline void BinaryWriter::writeFloat64BE(double value)
{
ConversionUtilities::BE::getBytes(value, m_buffer);
BE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(double));
}
@ -390,7 +390,7 @@ inline void BinaryWriter::writeFloat64BE(double value)
*/
inline void BinaryWriter::writeInt16LE(std::int16_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::int16_t));
}
@ -399,7 +399,7 @@ inline void BinaryWriter::writeInt16LE(std::int16_t value)
*/
inline void BinaryWriter::writeUInt16LE(std::uint16_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::uint16_t));
}
@ -410,7 +410,7 @@ inline void BinaryWriter::writeUInt16LE(std::uint16_t value)
inline void BinaryWriter::writeInt24LE(std::int32_t value)
{
// discard most significant byte
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, 3);
}
@ -421,7 +421,7 @@ inline void BinaryWriter::writeInt24LE(std::int32_t value)
inline void BinaryWriter::writeUInt24LE(std::uint32_t value)
{
// discard most significant byte
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, 3);
}
@ -430,7 +430,7 @@ inline void BinaryWriter::writeUInt24LE(std::uint32_t value)
*/
inline void BinaryWriter::writeInt32LE(std::int32_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::int32_t));
}
@ -439,7 +439,7 @@ inline void BinaryWriter::writeInt32LE(std::int32_t value)
*/
inline void BinaryWriter::writeUInt32LE(std::uint32_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::uint32_t));
}
@ -449,7 +449,7 @@ inline void BinaryWriter::writeUInt32LE(std::uint32_t value)
*/
inline void BinaryWriter::writeInt40LE(std::int64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, 5);
}
@ -459,7 +459,7 @@ inline void BinaryWriter::writeInt40LE(std::int64_t value)
*/
inline void BinaryWriter::writeUInt40LE(std::uint64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, 5);
}
@ -469,7 +469,7 @@ inline void BinaryWriter::writeUInt40LE(std::uint64_t value)
*/
inline void BinaryWriter::writeInt56LE(std::int64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, 7);
}
@ -479,7 +479,7 @@ inline void BinaryWriter::writeInt56LE(std::int64_t value)
*/
inline void BinaryWriter::writeUInt56LE(std::uint64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, 7);
}
@ -488,7 +488,7 @@ inline void BinaryWriter::writeUInt56LE(std::uint64_t value)
*/
inline void BinaryWriter::writeInt64LE(std::int64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::int64_t));
}
@ -497,7 +497,7 @@ inline void BinaryWriter::writeInt64LE(std::int64_t value)
*/
inline void BinaryWriter::writeUInt64LE(std::uint64_t value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(std::uint64_t));
}
@ -507,7 +507,7 @@ inline void BinaryWriter::writeUInt64LE(std::uint64_t value)
*/
inline void BinaryWriter::writeVariableLengthUIntLE(std::uint64_t value)
{
writeVariableLengthInteger(value, static_cast<void (*)(std::uint64_t, char *)>(&ConversionUtilities::LE::getBytes));
writeVariableLengthInteger(value, static_cast<void (*)(std::uint64_t, char *)>(&LE::getBytes));
}
/*!
@ -515,7 +515,7 @@ inline void BinaryWriter::writeVariableLengthUIntLE(std::uint64_t value)
*/
inline void BinaryWriter::writeFloat32LE(float value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(float));
}
@ -524,7 +524,7 @@ inline void BinaryWriter::writeFloat32LE(float value)
*/
inline void BinaryWriter::writeFloat64LE(double value)
{
ConversionUtilities::LE::getBytes(value, m_buffer);
LE::getBytes(value, m_buffer);
m_stream->write(m_buffer, sizeof(double));
}
@ -577,7 +577,7 @@ inline void BinaryWriter::writeLengthPrefixedCString(const char *value, std::siz
*/
inline void BinaryWriter::writeSynchsafeUInt32BE(std::uint32_t valueToConvertAndWrite)
{
writeUInt32BE(ConversionUtilities::toSynchsafeInt(valueToConvertAndWrite));
writeUInt32BE(toSynchsafeInt(valueToConvertAndWrite));
}
/*!
@ -585,7 +585,7 @@ inline void BinaryWriter::writeSynchsafeUInt32BE(std::uint32_t valueToConvertAnd
*/
inline void BinaryWriter::writeFixed8BE(float valueToConvertAndWrite)
{
writeUInt16BE(ConversionUtilities::toFixed8(valueToConvertAndWrite));
writeUInt16BE(toFixed8(valueToConvertAndWrite));
}
/*!
@ -593,7 +593,7 @@ inline void BinaryWriter::writeFixed8BE(float valueToConvertAndWrite)
*/
inline void BinaryWriter::writeFixed16BE(float valueToConvertAndWrite)
{
writeUInt32BE(ConversionUtilities::toFixed16(valueToConvertAndWrite));
writeUInt32BE(toFixed16(valueToConvertAndWrite));
}
/*!