Adapt to changes in c++utilities

This commit is contained in:
Martchus 2019-06-10 22:46:06 +02:00
parent 2194000938
commit 8cac133104
18 changed files with 64 additions and 76 deletions

View File

@ -9,7 +9,7 @@
#include <iostream>
using namespace std;
using namespace ApplicationUtilities;
using namespace CppUtilities;
namespace ReflectiveRapidJSON {

View File

@ -16,10 +16,10 @@ public:
struct Options {
Options();
Options(const Options &other) = delete;
void appendTo(ApplicationUtilities::Argument *arg);
void appendTo(CppUtilities::Argument *arg);
ApplicationUtilities::ConfigValueArgument additionalClassesArg;
ApplicationUtilities::ConfigValueArgument visibilityArg;
CppUtilities::ConfigValueArgument additionalClassesArg;
CppUtilities::ConfigValueArgument visibilityArg;
};
BinarySerializationCodeGenerator(CodeFactory &factory, const Options &options);
@ -32,7 +32,7 @@ protected:
const Options &m_options;
};
inline void BinarySerializationCodeGenerator::Options::appendTo(ApplicationUtilities::Argument *arg)
inline void BinarySerializationCodeGenerator::Options::appendTo(CppUtilities::Argument *arg)
{
arg->addSubArgument(&additionalClassesArg);
arg->addSubArgument(&visibilityArg);

View File

@ -9,7 +9,7 @@
#include <iostream>
using namespace std;
using namespace ApplicationUtilities;
using namespace CppUtilities;
namespace ReflectiveRapidJSON {

View File

@ -16,10 +16,10 @@ public:
struct Options {
Options();
Options(const Options &other) = delete;
void appendTo(ApplicationUtilities::Argument *arg);
void appendTo(CppUtilities::Argument *arg);
ApplicationUtilities::ConfigValueArgument additionalClassesArg;
ApplicationUtilities::ConfigValueArgument visibilityArg;
CppUtilities::ConfigValueArgument additionalClassesArg;
CppUtilities::ConfigValueArgument visibilityArg;
};
JsonSerializationCodeGenerator(CodeFactory &factory, const Options &options);
@ -32,7 +32,7 @@ protected:
const Options &m_options;
};
inline void JsonSerializationCodeGenerator::Options::appendTo(ApplicationUtilities::Argument *arg)
inline void JsonSerializationCodeGenerator::Options::appendTo(CppUtilities::Argument *arg)
{
arg->addSubArgument(&additionalClassesArg);
arg->addSubArgument(&visibilityArg);

View File

@ -6,7 +6,6 @@
#include <c++utilities/application/argumentparser.h>
#include <c++utilities/application/commandlineutils.h>
#include <c++utilities/application/failure.h>
#include <c++utilities/conversion/stringconversion.h>
#include <c++utilities/io/ansiescapecodes.h>
#include <c++utilities/io/misc.h>
@ -17,10 +16,8 @@
#include <unordered_map>
using namespace std;
using namespace ApplicationUtilities;
using namespace ConversionUtilities;
using namespace EscapeCodes;
using namespace IoUtilities;
using namespace CppUtilities;
using namespace CppUtilities::EscapeCodes;
using namespace ReflectiveRapidJSON;
int main(int argc, char *argv[])
@ -53,7 +50,7 @@ int main(int argc, char *argv[])
parser.setMainArguments({ &generateArg, &noColorArg, &helpArg });
// parse arguments
parser.parseArgsOrExit(argc, argv);
parser.parseArgs(argc, argv, ParseArgumentBehavior::CheckConstraints | ParseArgumentBehavior::InvokeCallbacks);
if (helpArg.isPresent() || !generateArg.isPresent()) {
return 0;
}

View File

@ -19,10 +19,8 @@
#include <sstream>
using namespace CPPUNIT_NS;
using namespace IoUtilities;
using namespace TestUtilities;
using namespace TestUtilities::Literals;
using namespace ConversionUtilities;
using namespace CppUtilities;
using namespace CppUtilities::Literals;
/*!
* \brief The BinaryGeneratorTests class tests the binary generator.

View File

@ -6,10 +6,12 @@
#include <c++utilities/tests/testutils.h>
// ensure "operator<<" from TestUtilities is visible prior to the call site
using TestUtilities::operator<<;
using CppUtilities::operator<<;
#include <cppunit/extensions/HelperMacros.h>
namespace Traits = CppUtilities::Traits;
/*!
* \brief Asserts equality of two iteratables printing the differing indices.
*/
@ -22,20 +24,20 @@ inline void assertEqualityLinewise(const Iteratable &iteratable1, const Iteratab
for (auto i1 = iteratable1.cbegin(), i2 = iteratable2.cbegin(); i1 != iteratable1.cend() || i2 != iteratable2.cend(); ++currentLine) {
if (i1 != iteratable1.cend() && i2 != iteratable2.cend()) {
if (*i1 != *i2) {
differentLines.push_back(ConversionUtilities::numberToString(currentLine));
differentLines.push_back(CppUtilities::numberToString(currentLine));
}
++i1, ++i2;
} else if (i1 != iteratable1.cend()) {
differentLines.push_back(ConversionUtilities::numberToString(currentLine));
differentLines.push_back(CppUtilities::numberToString(currentLine));
++i1;
} else if (i2 != iteratable1.cend()) {
differentLines.push_back(ConversionUtilities::numberToString(currentLine));
differentLines.push_back(CppUtilities::numberToString(currentLine));
++i2;
}
}
if (!differentLines.empty()) {
CPPUNIT_ASSERT_EQUAL_MESSAGE(
"the following lines differ: " + ConversionUtilities::joinStrings(differentLines, ", "), iteratable1, iteratable2);
"the following lines differ: " + CppUtilities::joinStrings(differentLines, ", "), iteratable1, iteratable2);
}
}

View File

@ -17,10 +17,8 @@
#include <iostream>
using namespace CPPUNIT_NS;
using namespace IoUtilities;
using namespace TestUtilities;
using namespace TestUtilities::Literals;
using namespace ConversionUtilities;
using namespace CppUtilities;
using namespace CppUtilities::Literals;
/*!
* \brief The JsonGeneratorTests class tests the overall functionality of the code generator (CLI and generator itself) and JSON specific parts.

View File

@ -99,8 +99,8 @@ struct MultipleDerivedTestStruct : public TestStruct,
* and toJson() methods. This is asserted in JsonGeneratorTests::testCustomSerialization();
*/
struct StructWithCustomTypes : public JsonSerializable<StructWithCustomTypes> {
ChronoUtilities::DateTime dt = ChronoUtilities::DateTime::fromDateAndTime(2017, 4, 2, 15, 31, 21, 165.125);
ChronoUtilities::TimeSpan ts = ChronoUtilities::TimeSpan::fromHours(3.25) + ChronoUtilities::TimeSpan::fromSeconds(19.125);
CppUtilities::DateTime dt = CppUtilities::DateTime::fromDateAndTime(2017, 4, 2, 15, 31, 21, 165.125);
CppUtilities::TimeSpan ts = CppUtilities::TimeSpan::fromHours(3.25) + CppUtilities::TimeSpan::fromSeconds(19.125);
};
/*!

View File

@ -16,22 +16,22 @@
namespace ReflectiveRapidJSON {
namespace BinaryReflector {
template <> inline void readCustomType<ChronoUtilities::DateTime>(BinaryDeserializer &deserializer, ChronoUtilities::DateTime &dateTime)
template <> inline void readCustomType<CppUtilities::DateTime>(BinaryDeserializer &deserializer, CppUtilities::DateTime &dateTime)
{
deserializer.read(dateTime.ticks());
}
template <> inline void writeCustomType<ChronoUtilities::DateTime>(BinarySerializer &serializer, const ChronoUtilities::DateTime &dateTime)
template <> inline void writeCustomType<CppUtilities::DateTime>(BinarySerializer &serializer, const CppUtilities::DateTime &dateTime)
{
serializer.write(dateTime.totalTicks());
}
template <> inline void readCustomType<ChronoUtilities::TimeSpan>(BinaryDeserializer &deserializer, ChronoUtilities::TimeSpan &timeSpan)
template <> inline void readCustomType<CppUtilities::TimeSpan>(BinaryDeserializer &deserializer, CppUtilities::TimeSpan &timeSpan)
{
deserializer.read(timeSpan.ticks());
}
template <> inline void writeCustomType<ChronoUtilities::TimeSpan>(BinarySerializer &serializer, const ChronoUtilities::TimeSpan &timeSpan)
template <> inline void writeCustomType<CppUtilities::TimeSpan>(BinarySerializer &serializer, const CppUtilities::TimeSpan &timeSpan)
{
serializer.write(timeSpan.totalTicks());
}

View File

@ -49,11 +49,11 @@ class BinarySerializer;
template <typename Type, Traits::EnableIf<IsCustomType<Type>> * = nullptr> void readCustomType(BinaryDeserializer &deserializer, Type &customType);
template <typename Type, Traits::EnableIf<IsCustomType<Type>> * = nullptr> void writeCustomType(BinarySerializer &serializer, const Type &customType);
class BinaryDeserializer : public IoUtilities::BinaryReader {
class BinaryDeserializer : public CppUtilities::BinaryReader {
public:
BinaryDeserializer(std::istream *stream);
using IoUtilities::BinaryReader::read;
using CppUtilities::BinaryReader::read;
template <typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::pair>> * = nullptr> void read(Type &pair);
template <typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::unique_ptr>> * = nullptr> void read(Type &pair);
template <typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::shared_ptr>> * = nullptr> void read(Type &pair);
@ -69,11 +69,11 @@ public:
std::unordered_map<std::uint64_t, std::any> m_pointer;
};
class BinarySerializer : public IoUtilities::BinaryWriter {
class BinarySerializer : public CppUtilities::BinaryWriter {
public:
BinarySerializer(std::ostream *stream);
using IoUtilities::BinaryWriter::write;
using CppUtilities::BinaryWriter::write;
template <typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::pair>> * = nullptr> void write(const Type &pair);
template <typename Type, Traits::EnableIf<Traits::IsSpecializingAnyOf<Type, std::unique_ptr>> * = nullptr> void write(const Type &pointer);
template <typename Type, Traits::EnableIf<Traits::IsSpecializingAnyOf<Type, std::shared_ptr>> * = nullptr> void write(const Type &pointer);
@ -85,7 +85,7 @@ public:
};
inline BinaryDeserializer::BinaryDeserializer(std::istream *stream)
: IoUtilities::BinaryReader(stream)
: CppUtilities::BinaryReader(stream)
{
}
@ -125,7 +125,7 @@ template <typename Type, Traits::EnableIf<Traits::IsSpecializationOf<Type, std::
try {
pointer = std::any_cast<Type>(m_pointer[id]);
} catch (const std::bad_any_cast &) {
throw ConversionUtilities::ConversionException("Referenced pointer type does not match");
throw CppUtilities::ConversionException("Referenced pointer type does not match");
}
}
@ -174,7 +174,7 @@ template <typename Type, Traits::EnableIf<IsCustomType<Type>> *> void BinaryDese
}
inline BinarySerializer::BinarySerializer(std::ostream *stream)
: IoUtilities::BinaryWriter(stream)
: CppUtilities::BinaryWriter(stream)
{
}

View File

@ -20,16 +20,16 @@ namespace JsonReflector {
// define functions to "push" values to a RapidJSON array or object
template <>
inline void push<ChronoUtilities::DateTime>(
const ChronoUtilities::DateTime &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
inline void push<CppUtilities::DateTime>(
const CppUtilities::DateTime &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
{
const std::string str(reflectable.toIsoString());
value.SetString(str.data(), rapidJsonSize(str.size()), allocator);
}
template <>
inline void push<ChronoUtilities::TimeSpan>(
const ChronoUtilities::TimeSpan &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
inline void push<CppUtilities::TimeSpan>(
const CppUtilities::TimeSpan &reflectable, RAPIDJSON_NAMESPACE::Value &value, RAPIDJSON_NAMESPACE::Document::AllocatorType &allocator)
{
const std::string str(reflectable.toString());
value.SetString(str.data(), rapidJsonSize(str.size()), allocator);
@ -38,14 +38,14 @@ inline void push<ChronoUtilities::TimeSpan>(
// define functions to "pull" values from a RapidJSON array or object
template <>
inline void pull<ChronoUtilities::DateTime>(ChronoUtilities::DateTime &reflectable,
inline void pull<CppUtilities::DateTime>(CppUtilities::DateTime &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
{
std::string str;
pull(str, value, errors);
try {
reflectable = ChronoUtilities::DateTime::fromIsoStringGmt(str.data());
} catch (const ConversionUtilities::ConversionException &) {
reflectable = CppUtilities::DateTime::fromIsoStringGmt(str.data());
} catch (const CppUtilities::ConversionException &) {
if (errors) {
errors->reportConversionError(JsonType::String);
}
@ -53,14 +53,14 @@ inline void pull<ChronoUtilities::DateTime>(ChronoUtilities::DateTime &reflectab
}
template <>
inline void pull<ChronoUtilities::TimeSpan>(ChronoUtilities::TimeSpan &reflectable,
inline void pull<CppUtilities::TimeSpan>(CppUtilities::TimeSpan &reflectable,
const RAPIDJSON_NAMESPACE::GenericValue<RAPIDJSON_NAMESPACE::UTF8<char>> &value, JsonDeserializationErrors *errors)
{
std::string str;
pull(str, value, errors);
try {
reflectable = ChronoUtilities::TimeSpan::fromString(str.data());
} catch (const ConversionUtilities::ConversionException &) {
reflectable = CppUtilities::TimeSpan::fromString(str.data());
} catch (const CppUtilities::ConversionException &) {
if (errors) {
errors->reportConversionError(JsonType::String);
}

View File

@ -6,7 +6,7 @@
#include <c++utilities/io/misc.h>
#include <c++utilities/tests/testutils.h>
using TestUtilities::operator<<; // must be visible prior to the call site
using CppUtilities::operator<<; // must be visible prior to the call site
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
@ -21,10 +21,8 @@ using TestUtilities::operator<<; // must be visible prior to the call site
using namespace std;
using namespace CPPUNIT_NS;
using namespace RAPIDJSON_NAMESPACE;
using namespace IoUtilities;
using namespace ConversionUtilities;
using namespace TestUtilities;
using namespace TestUtilities::Literals;
using namespace CppUtilities;
using namespace CppUtilities::Literals;
using namespace ReflectiveRapidJSON;
/// \cond

View File

@ -7,7 +7,7 @@
#include <c++utilities/io/misc.h>
#include <c++utilities/tests/testutils.h>
using TestUtilities::operator<<; // must be visible prior to the call site
using CppUtilities::operator<<; // must be visible prior to the call site
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
@ -23,11 +23,8 @@ using TestUtilities::operator<<; // must be visible prior to the call site
using namespace std;
using namespace CPPUNIT_NS;
using namespace IoUtilities;
using namespace ChronoUtilities;
using namespace ConversionUtilities;
using namespace TestUtilities;
using namespace TestUtilities::Literals;
using namespace CppUtilities;
using namespace CppUtilities::Literals;
using namespace ReflectiveRapidJSON;
/// \cond
@ -318,7 +315,7 @@ void BinaryReflectorTests::testSharedPointer(uintptr_t fakePointer)
BinaryReflector::BinaryDeserializer deserializer(&stream);
shared_ptr<int> readPtr;
deserializer.m_pointer[fakePointer] = "foo";
CPPUNIT_ASSERT_THROW(deserializer.read(readPtr), ConversionUtilities::ConversionException);
CPPUNIT_ASSERT_THROW(deserializer.read(readPtr), CppUtilities::ConversionException);
CPPUNIT_ASSERT(readPtr == nullptr);
// deserialize the shared pointer assuming it has already been read and the type matches

View File

@ -6,7 +6,7 @@
#include <c++utilities/io/misc.h>
#include <c++utilities/tests/testutils.h>
using TestUtilities::operator<<; // must be visible prior to the call site
using CppUtilities::operator<<; // must be visible prior to the call site
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
@ -21,10 +21,8 @@ using TestUtilities::operator<<; // must be visible prior to the call site
using namespace std;
using namespace CPPUNIT_NS;
using namespace RAPIDJSON_NAMESPACE;
using namespace IoUtilities;
using namespace ConversionUtilities;
using namespace TestUtilities;
using namespace TestUtilities::Literals;
using namespace CppUtilities;
using namespace CppUtilities::Literals;
using namespace ReflectiveRapidJSON;
/// \cond

View File

@ -17,8 +17,8 @@
using namespace std;
using namespace CPPUNIT_NS;
using namespace RAPIDJSON_NAMESPACE;
using namespace ChronoUtilities;
using namespace TestUtilities::Literals;
using namespace CppUtilities;
using namespace CppUtilities::Literals;
using namespace ReflectiveRapidJSON;
/*!

View File

@ -6,7 +6,7 @@
#include <c++utilities/io/misc.h>
#include <c++utilities/tests/testutils.h>
using TestUtilities::operator<<; // must be visible prior to the call site
using CppUtilities::operator<<; // must be visible prior to the call site
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
@ -24,10 +24,8 @@ using TestUtilities::operator<<; // must be visible prior to the call site
using namespace std;
using namespace CPPUNIT_NS;
using namespace RAPIDJSON_NAMESPACE;
using namespace IoUtilities;
using namespace ConversionUtilities;
using namespace TestUtilities;
using namespace TestUtilities::Literals;
using namespace CppUtilities;
using namespace CppUtilities::Literals;
using namespace ReflectiveRapidJSON;
/// \cond

View File

@ -11,6 +11,8 @@
namespace ReflectiveRapidJSON {
namespace Traits = ::CppUtilities::Traits;
// define structs and macros to allow treating custom data types as std::map, std::set, ...
/// \brief \brief The TreatAsMapOrHash class allows treating custom classes as std::map or std::unordered_map.
template <typename T> struct TreatAsMapOrHash : public Traits::Bool<false> {