Reflection for RapidJSON
0.0.17
Reflection for serializing/deserializing with RapidJSON
Toggle main menu visibility
Loading...
Searching...
No Matches
tests
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
21
using namespace
std;
22
using namespace
ReflectiveRapidJSON
;
23
28
struct
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"
;
34
static
int
anotherStaticMember
;
35
36
private
:
37
string
privateString =
"not going to be serialized"
;
38
};
39
40
// forward declarations shouldn't cause the generator to emit the code multiple times
41
struct
TestStruct
;
42
struct
TestStruct
;
43
struct
TestStruct
;
44
45
class
JsonGeneratorTests
;
46
51
struct
NestedTestStruct
:
public
JsonSerializable<NestedTestStruct> {
52
REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS
(
NestedTestStruct
);
53
54
friend
class
JsonGeneratorTests
;
55
56
list<vector<TestStruct>>
nested
;
57
unique_ptr<TestStruct>
ptr
;
58
59
private
:
60
deque<double> deq;
61
};
62
67
struct
AnotherTestStruct
:
public
JsonSerializable<AnotherTestStruct>,
public
BinarySerializable<AnotherTestStruct> {
68
vector<string>
arrayOfStrings
{
"a"
,
"b"
,
"cd"
};
69
};
70
75
struct
DerivedTestStruct
:
public
TestStruct
,
public
JsonSerializable<DerivedTestStruct>,
public
BinarySerializable<DerivedTestStruct> {
76
bool
someBool
=
true
;
77
};
78
82
struct
NonSerializable
{
83
int
ignored
= 25;
84
};
85
90
struct
MultipleDerivedTestStruct
:
public
TestStruct
,
91
public
AnotherTestStruct
,
92
public
NonSerializable
,
93
public
JsonSerializable<MultipleDerivedTestStruct> {
94
bool
someBool
=
false
;
95
};
96
101
struct
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
111
struct
NotJsonSerializable
{
112
std::string
butSerializableAnyways
=
"useful to adapt 3rd party structs"
;
113
};
114
120
struct
NestedNotJsonSerializable
{
121
NotJsonSerializable
asMember
;
122
vector<NotJsonSerializable>
asArrayElement
;
123
tuple<int, NotJsonSerializable>
asTupleElement
;
124
};
125
126
// make "NotJsonSerializable" and "NestedNotJsonSerializable" serializable
127
REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE
(
NotJsonSerializable
);
128
REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE
(
NestedNotJsonSerializable
);
129
135
struct
OtherNotJsonSerializable
{
136
std::string
codeIsGenerated
=
"for this despite missing REFLECTIVE_RAPIDJSON_ADAPT_JSON_SERIALIZABLE"
;
137
};
138
143
struct
ReallyNotJsonSerializable
{
144
std::string
notSerializable
;
145
};
146
147
//REFLECTIVE_RAPIDJSON_ADAPT_JSON_SERIALIZABLE(NotJsonSerializable);
148
149
#endif
// REFLECTIVE_RAPIDJSON_TESTS_STRUCTS_H
JsonGeneratorTests
The JsonGeneratorTests class tests the overall functionality of the code generator (CLI and generator...
Definition
jsongenerator.cpp:26
morestructs.h
ReflectiveRapidJSON
Definition
codegenerator.h:15
AnotherTestStruct
The AnotherTestStruct struct inherits from JsonSerializable and should hence have functional fromJson...
Definition
structs.h:67
AnotherTestStruct::arrayOfStrings
vector< string > arrayOfStrings
Definition
structs.h:68
DerivedTestStruct
The DerivedTestStruct struct inherits from JsonSerializable and should hence have functional fromJson...
Definition
structs.h:75
DerivedTestStruct::someBool
bool someBool
Definition
structs.h:76
MultipleDerivedTestStruct
The MultipleDerivedTestStruct struct inherits from JsonSerializable and should hence have functional ...
Definition
structs.h:93
MultipleDerivedTestStruct::someBool
bool someBool
Definition
structs.h:94
NestedNotJsonSerializable
The NestedNotJsonSerializable struct is used to test (de)serialization for 3rd party structs (which d...
Definition
structs.h:120
NestedNotJsonSerializable::asMember
NotJsonSerializable asMember
Definition
structs.h:121
NestedNotJsonSerializable::asTupleElement
tuple< int, NotJsonSerializable > asTupleElement
Definition
structs.h:123
NestedNotJsonSerializable::asArrayElement
vector< NotJsonSerializable > asArrayElement
Definition
structs.h:122
NestedTestStruct
The NestedTestStruct struct inherits from JsonSerializable and should hence have functional fromJson(...
Definition
structs.h:51
NestedTestStruct::ptr
unique_ptr< TestStruct > ptr
Definition
structs.h:57
NestedTestStruct::REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS
REFLECTIVE_RAPIDJSON_ENABLE_PRIVATE_MEMBERS(NestedTestStruct)
NestedTestStruct::JsonGeneratorTests
friend class JsonGeneratorTests
Definition
structs.h:54
NestedTestStruct::nested
list< vector< TestStruct > > nested
Definition
structs.h:56
NonSerializable
The NonSerializable struct should be ignored when used as base class because it isn't serializable.
Definition
structs.h:82
NonSerializable::ignored
int ignored
Definition
structs.h:83
NotJsonSerializable
The NotJsonSerializable struct is used to test (de)serialization for 3rd party structs (which do not ...
Definition
structs.h:111
NotJsonSerializable::butSerializableAnyways
std::string butSerializableAnyways
Definition
structs.h:112
OtherNotJsonSerializable
The OtherNotJsonSerializable struct is used to test whether code for (de)serialization is generated f...
Definition
structs.h:135
OtherNotJsonSerializable::codeIsGenerated
std::string codeIsGenerated
Definition
structs.h:136
ReallyNotJsonSerializable
The ReallyNotJsonSerializable struct is used to tests (de)serialization for 3rd party structs (which ...
Definition
structs.h:143
ReallyNotJsonSerializable::notSerializable
std::string notSerializable
Definition
structs.h:144
StructWithCustomTypes
The StructWithCustomTypes struct inherits from JsonSerializable and should hence have functional from...
Definition
structs.h:101
StructWithCustomTypes::dt
CppUtilities::DateTime dt
Definition
structs.h:102
StructWithCustomTypes::ts
CppUtilities::TimeSpan ts
Definition
structs.h:103
TestStruct
The TestStruct struct inherits from JsonSerializable and should hence have functional fromJson() and ...
Definition
structs.h:28
TestStruct::anotherStaticMember
static int anotherStaticMember
Definition
structs.h:34
TestStruct::someSize
size_t someSize
Definition
structs.h:30
TestStruct::yetAnotherString
string yetAnotherString
Definition
structs.h:32
TestStruct::someInt
int someInt
Definition
structs.h:29
TestStruct::staticMember
static constexpr const char * staticMember
Definition
structs.h:33
TestStruct::someString
string someString
Definition
structs.h:31
REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE
REFLECTIVE_RAPIDJSON_MAKE_JSON_SERIALIZABLE(NotJsonSerializable)
Generated on
for Reflection for RapidJSON by
1.18.0