2017-10-25 18:25:34 +02:00
|
|
|
#ifndef REFLECTIVE_RAPIDJSON_TESTS_STRUCTS_H
|
|
|
|
#define REFLECTIVE_RAPIDJSON_TESTS_STRUCTS_H
|
|
|
|
|
2017-11-04 15:17:06 +01:00
|
|
|
#include <c++utilities/chrono/datetime.h>
|
|
|
|
#include <c++utilities/chrono/timespan.h>
|
|
|
|
|
2017-12-31 00:37:30 +01:00
|
|
|
// including this header should *not* cause the code generator to generate code for the
|
|
|
|
// contained structs as well (to prevent violating the one definition rule)
|
|
|
|
#include "./morestructs.h"
|
|
|
|
|
2018-06-23 17:25:30 +02:00
|
|
|
#include "../../lib/binary/reflector-chronoutilities.h"
|
|
|
|
#include "../../lib/binary/serializable.h"
|
2018-06-26 00:10:44 +02:00
|
|
|
#include "../../lib/json/reflector-chronoutilities.h"
|
|
|
|
#include "../../lib/json/serializable.h"
|
2017-11-16 01:46:20 +01:00
|
|
|
|
2017-10-27 17:53:25 +02:00
|
|
|
#include <deque>
|
|
|
|
#include <list>
|
2017-10-25 18:25:34 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace ReflectiveRapidJSON;
|
|
|
|
|
|
|
|
/*!
|
2017-10-28 16:23:39 +02:00
|
|
|
* \brief The TestStruct struct inherits from JsonSerializable and should hence have functional fromJson()
|
2017-11-06 21:25:45 +01:00
|
|
|
* and toJson() methods. This is asserted in JsonGeneratorTests::testIncludingGeneratedHeader();
|
2017-10-25 18:25:34 +02:00
|
|
|
*/
|
2018-06-23 17:25:30 +02:00
|
|
|
struct TestStruct : public JsonSerializable<TestStruct>, public BinarySerializable<TestStruct> {
|
2017-10-25 18:25:34 +02:00
|
|
|
int someInt = 0;
|
2018-02-03 16:14:20 +01:00
|
|
|
size_t someSize = 1;
|
2017-10-25 18:25:34 +02:00
|
|
|
string someString = "foo";
|
|
|
|
string yetAnotherString = "bar";
|
2017-11-13 16:29:23 +01:00
|
|
|
static constexpr const char *staticMember = "static members are just ignored";
|
|
|
|
static int anotherStaticMember;
|
2017-11-09 00:07:40 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
string privateString = "not going to be serialized";
|
2017-10-25 18:25:34 +02:00
|
|
|
};
|
|
|
|
|
2018-11-08 00:38:39 +01:00
|
|
|
// forward declarations shouldn't cause the generator to emit the code multiple times
|
|
|
|
struct TestStruct;
|
|
|
|
struct TestStruct;
|
|
|
|
struct TestStruct;
|
|
|
|
|
2017-11-09 01:03:34 +01:00
|
|
|
class JsonGeneratorTests;
|
|
|
|
|
2017-10-27 17:53:25 +02:00
|
|
|
/*!
|
2017-10-28 16:23:39 +02:00
|
|
|
* \brief The NestedTestStruct struct inherits from JsonSerializable and should hence have functional fromJson()
|
2017-11-06 21:25:45 +01:00
|
|
|
* and toJson() methods. This is asserted in JsonGeneratorTests::testNesting();
|
2017-10-27 17:53:25 +02:00
|
|
|
*/
|
2017-10-28 16:23:39 +02:00
|
|
|
struct NestedTestStruct : public JsonSerializable<NestedTestStruct> {
|
2017-11-09 01:03:34 +01:00
|
|
|
REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS(NestedTestStruct);
|
2017-11-16 01:46:20 +01:00
|
|
|
|
2017-11-09 01:03:34 +01:00
|
|
|
friend class JsonGeneratorTests;
|
|
|
|
|
2017-10-27 17:53:25 +02:00
|
|
|
list<vector<TestStruct>> nested;
|
2017-11-13 16:18:32 +01:00
|
|
|
unique_ptr<TestStruct> ptr;
|
2017-11-09 01:03:34 +01:00
|
|
|
|
|
|
|
private:
|
2017-10-27 17:53:25 +02:00
|
|
|
deque<double> deq;
|
|
|
|
};
|
|
|
|
|
2017-10-25 18:25:34 +02:00
|
|
|
/*!
|
2017-10-28 16:23:39 +02:00
|
|
|
* \brief The AnotherTestStruct struct inherits from JsonSerializable and should hence have functional fromJson()
|
2017-11-06 21:25:45 +01:00
|
|
|
* and toJson() methods. This is asserted in JsonGeneratorTests::testSingleInheritence();
|
2017-10-25 18:25:34 +02:00
|
|
|
*/
|
2018-06-23 17:25:30 +02:00
|
|
|
struct AnotherTestStruct : public JsonSerializable<AnotherTestStruct>, public BinarySerializable<AnotherTestStruct> {
|
2017-10-25 18:25:34 +02:00
|
|
|
vector<string> arrayOfStrings{ "a", "b", "cd" };
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
2017-10-28 16:23:39 +02:00
|
|
|
* \brief The DerivedTestStruct struct inherits from JsonSerializable and should hence have functional fromJson()
|
2017-11-06 21:25:45 +01:00
|
|
|
* and toJson() methods. This is asserted in JsonGeneratorTests::testInheritence();
|
2017-10-25 18:25:34 +02:00
|
|
|
*/
|
2018-06-23 17:25:30 +02:00
|
|
|
struct DerivedTestStruct : public TestStruct, public JsonSerializable<DerivedTestStruct>, public BinarySerializable<DerivedTestStruct> {
|
2017-10-25 18:25:34 +02:00
|
|
|
bool someBool = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The NonSerializable struct should be ignored when used as base class because it isn't serializable.
|
|
|
|
*/
|
|
|
|
struct NonSerializable {
|
|
|
|
int ignored = 25;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
2017-10-28 16:23:39 +02:00
|
|
|
* \brief The MultipleDerivedTestStruct struct inherits from JsonSerializable and should hence have functional fromJson()
|
2017-11-06 21:25:45 +01:00
|
|
|
* and toJson() methods. This is asserted in JsonGeneratorTests::testMultipleInheritence();
|
2017-10-25 18:25:34 +02:00
|
|
|
*/
|
|
|
|
struct MultipleDerivedTestStruct : public TestStruct,
|
|
|
|
public AnotherTestStruct,
|
|
|
|
public NonSerializable,
|
2017-10-28 16:23:39 +02:00
|
|
|
public JsonSerializable<MultipleDerivedTestStruct> {
|
2017-10-25 18:25:34 +02:00
|
|
|
bool someBool = false;
|
|
|
|
};
|
|
|
|
|
2017-11-04 15:17:06 +01:00
|
|
|
/*!
|
|
|
|
* \brief The StructWithCustomTypes struct inherits from JsonSerializable and should hence have functional fromJson()
|
2017-11-06 21:25:45 +01:00
|
|
|
* and toJson() methods. This is asserted in JsonGeneratorTests::testCustomSerialization();
|
2017-11-04 15:17:06 +01:00
|
|
|
*/
|
|
|
|
struct StructWithCustomTypes : public JsonSerializable<StructWithCustomTypes> {
|
2019-06-10 22:46:06 +02:00
|
|
|
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);
|
2017-11-04 15:17:06 +01:00
|
|
|
};
|
|
|
|
|
2017-11-06 21:25:45 +01:00
|
|
|
/*!
|
2017-11-12 00:44:47 +01:00
|
|
|
* \brief The NotJsonSerializable struct is used to test (de)serialization for 3rd party structs (which do not
|
2017-11-06 21:25:45 +01:00
|
|
|
* inherit from JsonSerializable instance). It is used in JsonGeneratorTests::test3rdPartyAdaption().
|
|
|
|
* \remarks Imagine this struct would have been defined in a 3rd party header.
|
|
|
|
*/
|
|
|
|
struct NotJsonSerializable {
|
|
|
|
std::string butSerializableAnyways = "useful to adapt 3rd party structs";
|
|
|
|
};
|
|
|
|
|
2017-11-12 00:44:47 +01:00
|
|
|
/*!
|
|
|
|
* \brief The NestedNotJsonSerializable struct is used to test (de)serialization for 3rd party structs (which do not
|
|
|
|
* inherit from JsonSerializable instance). It is used in JsonGeneratorTests::test3rdPartyAdaption().
|
|
|
|
* \remarks Imagine this struct would have been defined in a 3rd party header.
|
|
|
|
*/
|
|
|
|
struct NestedNotJsonSerializable {
|
|
|
|
NotJsonSerializable asMember;
|
|
|
|
vector<NotJsonSerializable> asArrayElement;
|
|
|
|
tuple<int, NotJsonSerializable> asTupleElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
// make "NotJsonSerializable" and "NestedNotJsonSerializable" serializable
|
2017-11-06 21:25:45 +01:00
|
|
|
REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE(NotJsonSerializable);
|
2017-11-12 00:44:47 +01:00
|
|
|
REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE(NestedNotJsonSerializable);
|
2017-11-06 21:25:45 +01:00
|
|
|
|
|
|
|
/*!
|
2021-07-03 19:50:25 +02:00
|
|
|
* \brief The OtherNotJsonSerializable struct is used to test whether code for (de)serialization is generated for classes explicitly
|
2017-11-06 21:25:45 +01:00
|
|
|
* specified via CMake macro (despite use of REFLECTIVE_RAPIDJSON_ADAPT_JSON_SERIALIZABLE or JsonSerializable is
|
|
|
|
* missing).
|
|
|
|
*/
|
|
|
|
struct OtherNotJsonSerializable {
|
|
|
|
std::string codeIsGenerated = "for this despite missing REFLECTIVE_RAPIDJSON_ADAPT_JSON_SERIALIZABLE";
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* \brief The ReallyNotJsonSerializable struct is used to tests (de)serialization for 3rd party structs (which do not
|
|
|
|
* inherit from JsonSerializable instance). It is used in JsonGeneratorTests::test3rdPartyAdaption().
|
|
|
|
*/
|
|
|
|
struct ReallyNotJsonSerializable {
|
|
|
|
std::string notSerializable;
|
|
|
|
};
|
|
|
|
|
|
|
|
//REFLECTIVE_RAPIDJSON_ADAPT_JSON_SERIALIZABLE(NotJsonSerializable);
|
|
|
|
|
2017-10-25 18:25:34 +02:00
|
|
|
#endif // REFLECTIVE_RAPIDJSON_TESTS_STRUCTS_H
|