Adapt to c++utilities v5

This commit is contained in:
Martchus 2019-03-13 19:10:29 +01:00
parent 9b80d662bb
commit dd174920fe
6 changed files with 26 additions and 21 deletions

View File

@ -47,7 +47,8 @@ else()
endif()
# find c++utilities
find_package(c++utilities 4.17.0 REQUIRED)
set(CONFIGURATION_PACKAGE_SUFFIX "" CACHE STRING "sets the suffix for find_package() calls to packages configured via c++utilities")
find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.0.0 REQUIRED)
# use the source directory of c++utilities for includes rather than the location where headers are going to be installed
# note: this enables the tests to find the header files for c++utilities in case it is built within the same project

View File

@ -9,7 +9,6 @@
#include <c++utilities/application/failure.h>
#include <c++utilities/conversion/stringconversion.h>
#include <c++utilities/io/ansiescapecodes.h>
#include <c++utilities/io/catchiofailure.h>
#include <c++utilities/io/misc.h>
#include <cstring>
@ -123,9 +122,8 @@ int main(int argc, char *argv[])
return -2;
}
} catch (...) {
catchIoFailure();
const char *errorMessage;
} catch (const std::ios_base::failure &failure) {
const char *errorMessage = failure.what();
if (os) {
errorMessage = os->fail() || os->bad() ? "An IO error occured when writing to the output stream." : "An IO error occured.";
} else {

View File

@ -10,7 +10,6 @@
#include "../traits.h"
#include <c++utilities/conversion/conversionexception.h>
#include <c++utilities/conversion/types.h>
#include <c++utilities/io/binaryreader.h>
#include <c++utilities/io/binarywriter.h>
@ -39,7 +38,8 @@ namespace BinaryReflector {
// define traits to distinguish between "built-in" types like int, std::string, std::vector, ... and custom structs/classes
template <typename Type>
using IsBuiltInType = Traits::Any<Traits::IsAnyOf<Type, char, byte, bool, std::string, int16, uint16, int32, uint32, int64, uint64, float32, float64>,
using IsBuiltInType = Traits::Any<Traits::IsAnyOf<Type, char, std::uint8_t, bool, std::string, std::int16_t, std::uint16_t, std::int32_t,
std::uint32_t, std::int64_t, std::uint64_t, float, double>,
Traits::IsIteratable<Type>, Traits::IsSpecializingAnyOf<Type, std::pair, std::unique_ptr, std::shared_ptr>, std::is_enum<Type>>;
template <typename Type> using IsCustomType = Traits::Not<IsBuiltInType<Type>>;
@ -66,7 +66,7 @@ public:
template <typename Type, Traits::EnableIf<std::is_enum<Type>> * = nullptr> void read(Type &customType);
template <typename Type, Traits::EnableIf<IsCustomType<Type>> * = nullptr> void read(Type &customType);
std::unordered_map<uint64, std::any> m_pointer;
std::unordered_map<std::uint64_t, std::any> m_pointer;
};
class BinarySerializer : public IoUtilities::BinaryWriter {
@ -81,7 +81,7 @@ public:
template <typename Type, Traits::EnableIf<std::is_enum<Type>> * = nullptr> void write(const Type &customType);
template <typename Type, Traits::EnableIf<IsCustomType<Type>> * = nullptr> void write(const Type &customType);
std::unordered_map<uint64, bool> m_pointer;
std::unordered_map<std::uint64_t, bool> m_pointer;
};
inline BinaryDeserializer::BinaryDeserializer(std::istream *stream)
@ -202,7 +202,7 @@ template <typename Type, Traits::EnableIf<Traits::IsSpecializingAnyOf<Type, std:
const auto id = reinterpret_cast<std::uintptr_t>(pointer.get());
const auto bigId = id >= 0x80000000000000;
auto &alreadyWritten = m_pointer[id];
byte mode = alreadyWritten ? 2 : 1;
std::uint8_t mode = alreadyWritten ? 2 : 1;
if (bigId) {
mode = mode | 0x4; // "flag" 3rd bit to indicate big ID
}

View File

@ -6,11 +6,11 @@
* \brief Contains helper for error handling when deserializing JSON files.
*/
#include <c++utilities/conversion/types.h>
#include <c++utilities/misc/traits.h>
#include <rapidjson/rapidjson.h>
#include <cstdint>
#include <limits>
#include <list>
#include <string>
@ -21,7 +21,7 @@ namespace ReflectiveRapidJSON {
/*!
* \brief The JsonDeserializationErrorKind enum specifies which kind of error happend when populating variables from parsing results.
*/
enum class JsonDeserializationErrorKind : byte {
enum class JsonDeserializationErrorKind : std::uint8_t {
TypeMismatch, /**< The expected type does not match the type actually present in the JSON document. */
ArraySizeMismatch, /**< The expected array size does not match the actual size of the JSON array. A fixed size is expected when deserializing an std::tuple. */
ConversionError, /**< The expected type matches the type present in the JSON document, but further conversion of the value failed. */
@ -32,7 +32,7 @@ enum class JsonDeserializationErrorKind : byte {
* \brief The JsonType enum specifies the JSON data type.
* \remarks This is currently only used for error handling to propagate expected and actual types in case of a mismatch.
*/
enum class JsonType : byte {
enum class JsonType : std::uint8_t {
Null,
Number,
Bool,
@ -164,7 +164,13 @@ struct JsonDeserializationErrors : public std::vector<JsonDeserializationError>
/// \brief The index in the array which is currently processed.
std::size_t currentIndex;
/// \brief The list of fatal error types in form of flags.
enum class ThrowOn : byte { None = 0, TypeMismatch = 0x1, ArraySizeMismatch = 0x2, ConversionError = 0x4, UnexpectedDuplicate = 0x8 } throwOn;
enum class ThrowOn : std::uint8_t {
None = 0,
TypeMismatch = 0x1,
ArraySizeMismatch = 0x2,
ConversionError = 0x4,
UnexpectedDuplicate = 0x8
} throwOn;
private:
void throwMaybe(ThrowOn on) const;
@ -186,7 +192,7 @@ inline JsonDeserializationErrors::JsonDeserializationErrors()
*/
constexpr JsonDeserializationErrors::ThrowOn operator|(JsonDeserializationErrors::ThrowOn lhs, JsonDeserializationErrors::ThrowOn rhs)
{
return static_cast<JsonDeserializationErrors::ThrowOn>(static_cast<byte>(lhs) | static_cast<byte>(rhs));
return static_cast<JsonDeserializationErrors::ThrowOn>(static_cast<std::uint8_t>(lhs) | static_cast<std::uint8_t>(rhs));
}
/*!
@ -196,7 +202,7 @@ constexpr JsonDeserializationErrors::ThrowOn operator|(JsonDeserializationErrors
*/
inline void JsonDeserializationErrors::throwMaybe(ThrowOn on) const
{
if (static_cast<byte>(throwOn) & static_cast<byte>(on)) {
if (static_cast<std::uint8_t>(throwOn) & static_cast<std::uint8_t>(on)) {
throw back();
}
}

View File

@ -9,8 +9,6 @@
#include "../traits.h"
#include <c++utilities/conversion/types.h>
#include <rapidjson/document.h>
#include <rapidjson/rapidjson.h>
#include <rapidjson/stringbuffer.h>
@ -153,7 +151,8 @@ inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_
template <typename Type, Traits::EnableIfAny<std::is_enum<Type>> * = nullptr>
inline void push(Type reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
{
value.Set(static_cast<Traits::Conditional<std::is_unsigned<typename std::underlying_type<Type>::type>, uint64, int64>>(reflectable), allocator);
value.Set(static_cast<Traits::Conditional<std::is_unsigned<typename std::underlying_type<Type>::type>, std::uint64_t, std::int64_t>>(reflectable),
allocator);
}
/*!
@ -459,7 +458,7 @@ template <typename Type, Traits::EnableIfAny<std::is_enum<Type>> * = nullptr>
inline void pull(
Type &reflectable, const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
{
using ExpectedType = Traits::Conditional<std::is_unsigned<typename std::underlying_type<Type>::type>, uint64, int64>;
using ExpectedType = Traits::Conditional<std::is_unsigned<typename std::underlying_type<Type>::type>, std::uint64_t, std::int64_t>;
if (!value.Is<ExpectedType>()) {
if (errors) {
errors->reportTypeMismatch<ExpectedType>(value.GetType());

View File

@ -11,6 +11,7 @@ using TestUtilities::operator<<; // must be visible prior to the call site
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cstdint>
#include <iostream>
#include <limits>
#include <map>
@ -38,7 +39,7 @@ enum SomeEnum {
SomeEnumItem3,
};
enum class SomeEnumClass : uint16 {
enum class SomeEnumClass : std::uint16_t {
Item1,
Item2,
Item3,