-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGatePairDose.cpp
213 lines (175 loc) · 7.65 KB
/
GatePairDose.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
//---------------------------------------------------------------------------
#include "GatePairDose.h"
#include "LogFrame.h"
//-------------------------------------------Class:Object----------------------------------------------
/*Constructor*/
GatePairDose::GatePairDose(){
this->dosePair = NULL;
this->angle.clear();
vector<IObserver*>::iterator iterat = this->ObserverList.begin();
for (; iterat != this->ObserverList.end();){
/*Note: as the vector<IObserver*> ObserverList stored the point/reference of each Observer,
so while realease the space of vector<IObserver*> ObserverList,don not use the operation "delete (*iterat)"
to clean each point's space here,in this case the point's space should be realeased at the location
where point's space is allocated. If had used the operation "delete (*iterat)", the point's space
while be clean while the vector space is released,NOTE,while you want to release the point's space
at where the point's space is allocated ,you would get an unreacherable error(multi released).
To solved this issue,there are two ways: First,use the function "TryToDelete<class T>()" which is encapsulate by us and
could avoid the program shut down while meet an unreacherable error(multi released); Second, as mentioned before,don not
use the operation "delete (*iterat)" to clean each point's space here,in this case the point's space should
be realeased at the location where point's space is allocated or use our implemented function "TryToDelete<class T>()"
, we should hanve a convention about it.*/
iterat = this->ObserverList.erase(iterat);
}
}
/*Destructor*/
GatePairDose::~GatePairDose(){
TryToDelete<DosePair>(this->dosePair);
this->dosePair = NULL;
this->angle.clear();
vector<IObserver*>::iterator iterat = this->ObserverList.begin();
for (; iterat != this->ObserverList.end();){
/*Note: as the vector<IObserver*> ObserverList stored the point/reference of each Observer,
so while realease the space of vector<IObserver*> ObserverList,don not use the operation "delete (*iterat)"
to clean each point's space here,in this case the point's space should be realeased at the location
where point's space is allocated. If had used the operation "delete (*iterat)", the point's space
while be clean while the vector space is released,NOTE,while you want to release the point's space
at where the point's space is allocated ,you would get an unreacherable error(multi released).
To solved this issue,there are two ways: First,use the function "TryToDelete<class T>()" which is encapsulate by us and
could avoid the program shut down while meet an unreacherable error(multi released); Second, as mentioned before,don not
use the operation "delete (*iterat)" to clean each point's space here,in this case the point's space should
be realeased at the location where point's space is allocated or use our implemented function "TryToDelete<class T>()"
, we should hanve a convention about it.*/
iterat = this->ObserverList.erase(iterat);
}
vector<IObserver*>().swap(this->ObserverList);
}
/*Copy Constructor*/
GatePairDose::GatePairDose(const GatePairDose& r){
vector<IObserver*>().swap(this->ObserverList);
this->dosePair = NULL;
this->angle.clear();
if(NULL != &r){
this->angle = r.angle;
this->ObserverList = vector<IObserver*>(r.ObserverList);
TryToDelete<DosePair>(this->dosePair);
if(NULL != r.dosePair){
this->dosePair = new DosePair();
*this->dosePair = *r.dosePair;
}else{
this->dosePair = NULL;
}
}
}
/*Overload operator = */
GatePairDose GatePairDose::operator = (const GatePairDose& r){
TryToDelete<DosePair>(this->dosePair);
if(NULL == &r){
vector<IObserver*>().swap(this->ObserverList);
this->dosePair = NULL;
this->angle.clear();
}else{
this->angle = r.angle;
this->ObserverList = vector<IObserver*>(r.ObserverList);
if(NULL != r.dosePair){
this->dosePair = new DosePair();
*this->dosePair = *r.dosePair;
}else{
this->dosePair = NULL;
}
}
return *this;
}
/*---Observer model functions--------------------------*/
void GatePairDose::Notify(Message_Notify message){
vector<IObserver*>::iterator iterat = ObserverList.begin();
for (; iterat != ObserverList.end();){
//(*iterat)->update(message);
if (SEHNotify((*iterat), message)){
iterat++;
}
else{
iterat = ObserverList.erase(iterat);
}
}
}
bool GatePairDose::SEHNotify(IObserver* observer, Message_Notify message){
__try{
observer->update(message);
return true;
}
__except (EXCEPTION_EXECUTE_HANDLER){
RunningLog::writeLog("The Observer is cleaned,the visiting is unreachable,Please allocate and assign a new Observer");
return false;
}
return true;
}
void GatePairDose::AddObserver(IObserver *pObserver){
vector<IObserver*>::iterator iterat = ObserverList.begin();
for (; iterat != ObserverList.end(); iterat++){
if (pObserver->identify == (*iterat)->identify){
return;
}
}
ObserverList.push_back(pObserver);
}
void GatePairDose::DeleteObserver(IObserver *pObserver){
vector<IObserver*>::iterator iterat = ObserverList.begin();
for (; iterat != ObserverList.end();){
if (pObserver->identify == (*iterat)->identify){
/*Note: as the vector<IObserver*> ObserverList stored the point/reference of each Observer,
so while realease the space of vector<IObserver*> ObserverList,don not use the operation "delete (*iterat)"
to clean each point's space here,in this case the point's space should be realeased at the location
where point's space is allocated. If had used the operation "delete (*iterat)", the point's space
while be clean while the vector space is released,NOTE,while you want to release the point's space
at where the point's space is allocated ,you would get an unreacherable error(multi released).
To solved this issue,there are two ways: First,use the function "TryToDelete<class T>()" which is encapsulate by us and
could avoid the program shut down while meet an unreacherable error(multi released); Second, as mentioned before,don not
use the operation "delete (*iterat)" to clean each point's space here,in this case the point's space should
be realeased at the location where point's space is allocated or use our implemented function "TryToDelete<class T>()"
, we should hanve a convention about it.*/
iterat = ObserverList.erase(iterat);
}
else{
iterat++;
}
}
}
/*------------------other functions--------------------------*/
DosePair* GatePairDose::getDosePair(){
return this->dosePair;
}
void GatePairDose::setDosePair(DosePair& dosePair){
TryToDelete<DosePair>(this->dosePair);
if(NULL == &dosePair){
this->dosePair = NULL;
}else{
this->dosePair = new DosePair();
*this->dosePair = dosePair;
}
}
DosePair GatePairDose::copyDosePair(){
DosePair result;
if(NULL != this->dosePair){
result = *this->dosePair;
}
return result;
}
void GatePairDose::allocateDosePair(){
TryToDelete<DosePair>(this->dosePair);
this->dosePair = new DosePair();
}
void GatePairDose::cleanDosePair(){
TryToDelete<DosePair>(this->dosePair);
this->dosePair = NULL;
}
//-----------------------Angle---------------------------------------------
string* GatePairDose::getAngle(){
return &this->angle;
}
string GatePairDose::copyAngle(){
return this->angle;
}
void GatePairDose::setAngle(string _angle){
this->angle = _angle;
}