-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpy.cpp
62 lines (49 loc) · 1.13 KB
/
Spy.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
#include "Spy.h"
#include <stdexcept>
using std::cout;
bool Spy::verbose = false;
int Spy::constructorBombValue = -4242;
int Spy::affectationBombValue = -2424;
Spy::Spy() : _i(-42) {
if(verbose) cout << "DC ";
}
Spy::Spy(int i) : _i(i) {
if(verbose) cout << "IC(" << _i << ") ";
}
Spy::Spy(const Spy& I) : _i(I._i) {
if(_i == constructorBombValue) throw std::exception();
if(verbose) cout << "CC(" << _i << ") ";
}
Spy::Spy(Spy&& I) {
_i = I._i;
if(verbose) cout << "MC(" << _i << ") ";
I._i = 42;
}
Spy::~Spy() {
if(verbose) cout << "D(" << _i << ") ";
}
Spy& Spy::operator=(const Spy& I) {
if(I._i == affectationBombValue) throw std::exception();
_i = I._i;
if(verbose) cout << "=C(" << _i << ") ";
return *this;
}
Spy& Spy::operator=(Spy&& I) {
_i = I._i;
if(verbose) cout << "=M(" << _i << ") ";
I._i = 43;
return *this;
}
using std::ostream;
ostream& operator<<(ostream& os, const Spy& I) {
os << I._i;
return os;
}
ostream& operator<<(ostream& os, const Movable& m) {
os << m.spy;
return os;
}
ostream& operator<<(ostream& os, const Unmovable& m) {
os << m.spy;
return os;
}