-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestcppreflect.cpp
65 lines (52 loc) · 1.14 KB
/
testcppreflect.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
59
60
61
62
63
#include "CppReflect.h"
using namespace std;
class Person
{
public:
REFLECTABLE( Person,
(CString) name,
(int) age,
(bool) isAdult,
(ColorRef) eyeColor
)
};
class People
{
public:
REFLECTABLE( People,
(CString) groupName,
(vector<Person>) people
)
};
void main(void)
{
People ppl;
ppl.groupName = "Group1";
Person p;
p.name = L"Roger";
p.age = 37;
p.isAdult = true;
p.eyeColor = RGB(255,0,0);
ppl.people.push_back(p);
p.name = L"Alice";
p.age = 27;
p.isAdult = true;
p.eyeColor = RGB( 0, 255, 0 );
ppl.people.push_back( p );
p.name = L"Cindy";
p.age = 17;
p.isAdult = false;
p.eyeColor = RGB( 0, 0, 255 );
ppl.people.push_back( p );
CStringW xml = ToXML( &ppl );
CStringW errors;
People ppl2;
FromXml( &ppl2, xml, errors );
CStringA xml2 = ToXML( &ppl2 );
printf( xml2 );
FILE* out = fopen( "test.xml", "wb" );
unsigned char utf8_hdr[] = { 0xEF, 0xBB, 0xBF };
fwrite( utf8_hdr, 3, 1, out );
fwrite( xml2.GetBuffer(), xml2.GetLength(), 1, out);
fclose(out);
}