Reflection for RapidJSON 0.0.17
Reflection for serializing/deserializing with RapidJSON
Loading...
Searching...
No Matches
structs.h
Go to the documentation of this file.
1#ifndef REFLECTIVE_RAPIDJSON_TESTS_STRUCTS_H
2#define REFLECTIVE_RAPIDJSON_TESTS_STRUCTS_H
3
4#include <c++utilities/chrono/datetime.h>
5#include <c++utilities/chrono/timespan.h>
6
7// including this header should *not* cause the code generator to generate code for the
8// contained structs as well (to prevent violating the one definition rule)
9#include "./morestructs.h"
10
11#include "../../lib/binary/reflector-chronoutilities.h"
12#include "../../lib/binary/serializable.h"
13#include "../../lib/json/reflector-chronoutilities.h"
14#include "../../lib/json/serializable.h"
15
16#include <deque>
17#include <list>
18#include <string>
19#include <vector>
20
21using namespace std;
22using namespace ReflectiveRapidJSON;
23
28struct TestStruct : public JsonSerializable<TestStruct>, public BinarySerializable<TestStruct> {
29 int someInt = 0;
30 size_t someSize = 1;
31 string someString = "foo";
32 string yetAnotherString = "bar";
33 static constexpr const char *staticMember = "static members are just ignored";
35
36private:
37 string privateString = "not going to be serialized";
38};
39
40// forward declarations shouldn't cause the generator to emit the code multiple times
41struct TestStruct;
42struct TestStruct;
43struct TestStruct;
44
46
51struct NestedTestStruct : public JsonSerializable<NestedTestStruct> {
53
54 friend class JsonGeneratorTests;
55
56 list<vector<TestStruct>> nested;
57 unique_ptr<TestStruct> ptr;
58
59private:
60 deque<double> deq;
61};
62
67struct AnotherTestStruct : public JsonSerializable<AnotherTestStruct>, public BinarySerializable<AnotherTestStruct> {
68 vector<string> arrayOfStrings{ "a", "b", "cd" };
69};
70
75struct DerivedTestStruct : public TestStruct, public JsonSerializable<DerivedTestStruct>, public BinarySerializable<DerivedTestStruct> {
76 bool someBool = true;
77};
78
83 int ignored = 25;
84};
85
91 public AnotherTestStruct,
92 public NonSerializable,
93 public JsonSerializable<MultipleDerivedTestStruct> {
94 bool someBool = false;
95};
96
101struct StructWithCustomTypes : public JsonSerializable<StructWithCustomTypes> {
102 CppUtilities::DateTime dt = CppUtilities::DateTime::fromDateAndTime(2017, 4, 2, 15, 31, 21, 165.125);
103 CppUtilities::TimeSpan ts = CppUtilities::TimeSpan::fromHours(3.25) + CppUtilities::TimeSpan::fromSeconds(19.125);
104};
105
112 std::string butSerializableAnyways = "useful to adapt 3rd party structs";
113};
114
122 vector<NotJsonSerializable> asArrayElement;
123 tuple<int, NotJsonSerializable> asTupleElement;
124};
125
126// make "NotJsonSerializable" and "NestedNotJsonSerializable" serializable
129
136 std::string codeIsGenerated = "for this despite missing REFLECTIVE_RAPIDJSON_ADAPT_JSON_SERIALIZABLE";
137};
138
146
147//REFLECTIVE_RAPIDJSON_ADAPT_JSON_SERIALIZABLE(NotJsonSerializable);
148
149#endif // REFLECTIVE_RAPIDJSON_TESTS_STRUCTS_H
The JsonGeneratorTests class tests the overall functionality of the code generator (CLI and generator...
The AnotherTestStruct struct inherits from JsonSerializable and should hence have functional fromJson...
Definition structs.h:67
vector< string > arrayOfStrings
Definition structs.h:68
The DerivedTestStruct struct inherits from JsonSerializable and should hence have functional fromJson...
Definition structs.h:75
The MultipleDerivedTestStruct struct inherits from JsonSerializable and should hence have functional ...
Definition structs.h:93
The NestedNotJsonSerializable struct is used to test (de)serialization for 3rd party structs (which d...
Definition structs.h:120
NotJsonSerializable asMember
Definition structs.h:121
tuple< int, NotJsonSerializable > asTupleElement
Definition structs.h:123
vector< NotJsonSerializable > asArrayElement
Definition structs.h:122
The NestedTestStruct struct inherits from JsonSerializable and should hence have functional fromJson(...
Definition structs.h:51
unique_ptr< TestStruct > ptr
Definition structs.h:57
REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS(NestedTestStruct)
friend class JsonGeneratorTests
Definition structs.h:54
list< vector< TestStruct > > nested
Definition structs.h:56
The NonSerializable struct should be ignored when used as base class because it isn't serializable.
Definition structs.h:82
The NotJsonSerializable struct is used to test (de)serialization for 3rd party structs (which do not ...
Definition structs.h:111
std::string butSerializableAnyways
Definition structs.h:112
The OtherNotJsonSerializable struct is used to test whether code for (de)serialization is generated f...
Definition structs.h:135
std::string codeIsGenerated
Definition structs.h:136
The ReallyNotJsonSerializable struct is used to tests (de)serialization for 3rd party structs (which ...
Definition structs.h:143
std::string notSerializable
Definition structs.h:144
The StructWithCustomTypes struct inherits from JsonSerializable and should hence have functional from...
Definition structs.h:101
CppUtilities::DateTime dt
Definition structs.h:102
CppUtilities::TimeSpan ts
Definition structs.h:103
The TestStruct struct inherits from JsonSerializable and should hence have functional fromJson() and ...
Definition structs.h:28
static int anotherStaticMember
Definition structs.h:34
size_t someSize
Definition structs.h:30
string yetAnotherString
Definition structs.h:32
int someInt
Definition structs.h:29
static constexpr const char * staticMember
Definition structs.h:33
string someString
Definition structs.h:31
REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE(NotJsonSerializable)