-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChainOfResponsibilityPattern.h
More file actions
93 lines (89 loc) · 2.21 KB
/
ChainOfResponsibilityPattern.h
File metadata and controls
93 lines (89 loc) · 2.21 KB
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
#ifndef CHAINOFRESPONSIBILITYPATTERN_H_INCLUDED
#define CHAINOFRESPONSIBILITYPATTERN_H_INCLUDED
#include <iostream>
enum ErrorStates {
ANALYZE = 0,
FIX,
VERIFY,
CLOSE
};
class ErrorReport {
protected:
ErrorStates state;
public:
ErrorReport(ErrorStates state) {
this->state = state;
}
void SetState(ErrorStates state) {
this->state = state;
}
ErrorStates GetState() {
return state;
}
};
class Error {
protected:
ErrorStates state;
Error *successor;
public:
Error(ErrorStates state) {
this->state = state;
successor = NULL;
}
void SetSuccessor(Error *successor) {
this->successor = successor;
}
virtual void ProcessError(ErrorReport &report) = 0;
};
class AnalyzeError : public Error {
protected:
public:
AnalyzeError():Error(ANALYZE) {}
void ProcessError(ErrorReport &report) {
if (report.GetState() == ANALYZE)
std::cout<<"Handled the error in analyze\n";
else {
std::cout<<"Analyze:Passing on to the successor\n";
successor->ProcessError(report);
}
}
};
class FixError : public Error {
protected:
public:
FixError():Error(FIX) {}
void ProcessError(ErrorReport &report) {
if (report.GetState() == FIX)
std::cout<<"Handled the error in fix\n";
else {
std::cout<<"Fix:Passing on to the successor\n";
successor->ProcessError(report);
}
}
};
class VerifyError : public Error {
protected:
public:
VerifyError():Error(VERIFY) {}
void ProcessError(ErrorReport &report) {
if (report.GetState() == VERIFY)
std::cout<<"Handled the error in verify\n";
else {
std::cout<<"Verify:Passing on to the successor\n";
successor->ProcessError(report);
}
}
};
class CloseError : public Error {
protected:
public:
CloseError():Error(CLOSE) {}
void ProcessError(ErrorReport &report) {
if (report.GetState() == CLOSE)
std::cout<<"Handled the error in close\n";
else {
std::cout<<"Close:Ignoring this error. Ending process chain\n";
}
}
};
#endif // CHAINOFRESPONSIBILITYPATTERN_H_INCLUDED