aboutsummaryrefslogtreecommitdiff
path: root/src/tests/sharedcore.cpp
blob: bdfde4c9bfc322dfa3b823fa199c11e5db44975f (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
#include "bu/sharedcore.h"
#include "bu/sio.h"

using namespace Bu;

struct ShintCore
{
	int val;
};
class Shint : public Bu::SharedCore<struct ShintCore>
{
public:
	Shint()
	{
		data->val = 0;
	}

	Shint( int val )
	{
		data->val = val;
	}

	int getVal()
	{
		return data->val;
	}

	void setValBad( int val )
	{
		data->val = val;
	}
	
	void setVal( int val )
	{
		_hardCopy();
		data->val = val;
	}

	bool operator==( const Shint &rhs )
	{
		if( data == rhs.data )
		{
			sio << "Same pointer (" << Fmt::ptr() << data << ")" << sio.nl;
			return true;
		}
		if( data->val == rhs.data->val )
		{
			sio << "Same value " << data->val << " ("
				<< Fmt::ptr() << data << " vs "
				<< Fmt::ptr() << rhs.data << ")"
				<< sio.nl;
			return true;
		}
		sio << "Different" << sio.nl;
		return false;
	}
};

#define line( x ) sio << __FILE__ ": " << __LINE__ << ": " << #x << sio.nl; x

int main()
{
	line( Shint a; )
	line( Shint b( 5 ); )

	line( a == b; )

	line( b = a; )
	line( a == b; )

	line( b.setValBad( 12 ); )
	sio << a.getVal() << " != " << b.getVal() << sio.nl;
	line( a == b; )

	line( a.setVal( 3 ); )
	sio << a.getVal() << " != " << b.getVal() << sio.nl;
	line( a == b; )

	line( a.setVal( b.getVal() ); )
	line( a == b; )
}