summaryrefslogtreecommitdiff
path: root/src/tests/archive2.cpp
blob: fddb91b0d38f21c7fbea6aead45a57ffff2c0258 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/archive.h"
#include "bu/archival.h"
#include "bu/file.h"

int giId = 0;

class A : public Bu::Archival
{
public:
	A() :
		iId( giId++ )
	{
	}

	virtual ~A()
	{
	}

	virtual void archive( Bu::Archive &ar )
	{
		ar && iId;
	}

	int iId;
};

class B : public Bu::Archival
{
public:
	B() :
		iId( giId++ ),
		a1( new A ),
		a2( new A )
	{
	}

	virtual ~B()
	{
		delete a1;
		delete a2;
	}

	virtual void archive( Bu::Archive &ar )
	{
		//ar && iId && a1 && a2;
		ar << iId << a1 << a2;
	}

	int iId;
	A *a1, *a2;
};

class C : public Bu::Archival
{
public:
	C() :
		iId( giId++ ),
		a( new A ),
		b( new B )
	{
	}

	virtual ~C()
	{
		delete a;
		delete b;
	}

	virtual void archive( Bu::Archive &ar )
	{
		//ar && iId && a && b;
		ar << iId;
		ar << a << b;
	}

	int iId;
	A *a;
	B *b;
};

void write()
{
	C *c = new C;
	
	Bu::File f( "test.archive", Bu::File::Write );
	Bu::Archive ar( f, Bu::Archive::save );
	ar << c;
}

int main()
{
	write();

}