forked from Loki-Astari/ThorsAnvil
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample1.cpp
More file actions
44 lines (39 loc) · 1.04 KB
/
example1.cpp
File metadata and controls
44 lines (39 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "ThorSerialize/Traits.h"
#include "ThorSerialize/JsonThor.h"
namespace X
{
struct Shirt
{
int red;
int green;
int blue;
};
class TeamMember
{
std::string name;
int score;
int damage;
Shirt team;
public:
TeamMember(std::string const& name, int score, int damage, Shirt const& team)
: name(name)
, score(score)
, damage(damage)
, team(team)
{}
// Define the trait as a friend to get accesses to private
// Members.
friend class ThorsAnvil::Serialize::Traits<TeamMember>;
};
}
// Declare the traits.
// Specifying what members need to be serialized.
ThorsAnvil_MakeTrait(X::Shirt, red, green, blue);
ThorsAnvil_MakeTrait(X::TeamMember, name, score, damage, team);
int main()
{
using ThorsAnvil::Serialize::jsonExporter;
X::TeamMember mark("mark", 10, 5, X::Shirt{255,0,0});
// Use the export function to serialize
std::cout << jsonExporter(mark) << "\n";
}