-
Notifications
You must be signed in to change notification settings - Fork 0
/
example3.cpp
59 lines (51 loc) · 1.35 KB
/
example3.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "ThorSerialize/Serialize.h"
#include "ThorSerialize/Serialize.tpp"
#include "ThorSerialize/Traits.h"
#include "ThorSerialize/JsonThor.h"
#include <string>
#include <sstream>
#include <iostream>
struct Vehicle
{
Vehicle(){}
Vehicle(int speed)
: speed(speed)
{}
virtual ~Vehicle() {}
int speed;
ThorsAnvil_PolyMorphicSerializer(Vehicle);
};
struct Car: public Vehicle
{
Car(){}
Car(int speed, std::string const& make)
: Vehicle(speed)
, make(make)
{}
std::string make;
ThorsAnvil_PolyMorphicSerializer(Car);
};
struct Bike: public Vehicle
{
Bike(){}
Bike(int speed, int stroke)
: Vehicle(speed)
, stroke(stroke)
{}
int stroke;
ThorsAnvil_PolyMorphicSerializer(Bike);
};
ThorsAnvil_MakeTrait(Vehicle, speed);
ThorsAnvil_ExpandTrait(Vehicle, Car, make);
ThorsAnvil_ExpandTrait(Vehicle, Bike, stroke);
int main()
{
Vehicle* init = new Bike(15, 2);
std::stringstream stream;
stream << ThorsAnvil::Serialize::jsonExporter(init);
std::cout << ThorsAnvil::Serialize::jsonExporter(init) << "\n\n";
Vehicle* result = nullptr;
std::cout << ThorsAnvil::Serialize::jsonExporter(result) << "\n\n";
stream >> ThorsAnvil::Serialize::jsonImporter(result);
std::cout << ThorsAnvil::Serialize::jsonExporter(result) << "\n\n";
}