5 |
* Author: Nicola Mori |
* Author: Nicola Mori |
6 |
*/ |
*/ |
7 |
|
|
8 |
/*! @file SmartCollection.cpp The SmartCollection class implementation file */ |
/*! @file SmartCollection.cpp The SmartBlindCollection class implementation file */ |
9 |
|
|
10 |
#include "SmartBlindCollection.h" |
#include "SmartBlindCollection.h" |
11 |
|
|
12 |
void SmartBlindCollection::AddAction(CollectionAction& action) { |
int SmartBlindCollection::ApplyCut(PamLevel2 *event) { |
|
_actions.push_back(&action); |
|
|
} |
|
|
|
|
|
CollectionAction *SmartBlindCollection::GetAction(unsigned int iAction) { |
|
|
if (_actions.size() == 0) |
|
|
return NULL; |
|
|
if (iAction < 0 || iAction > _actions.size() - 1) |
|
|
return NULL; |
|
|
else |
|
|
return _actions[iAction]; |
|
|
} |
|
13 |
|
|
14 |
void SmartBlindCollection::Setup(PamLevel2 *events){ |
_nEv++; |
15 |
BlindCutCollection::Setup(events); |
if (_cuts.size() == 0) { |
16 |
|
_nGood++; |
17 |
for (unsigned int i = 0; i < _actions.size(); i++){ |
OnGood(event); |
18 |
_actions[i]->Setup(events); |
return CUTOK; |
19 |
} |
} |
|
} |
|
|
|
|
|
void SmartBlindCollection::Finalize(){ |
|
|
BlindCutCollection::Finalize(); |
|
20 |
|
|
21 |
for (unsigned int i = 0; i < _actions.size(); i++){ |
unsigned int firstFailed = _cuts.size(); |
22 |
_actions[i]->Finalize(); |
for (unsigned int icut = 0; icut < _cuts.size(); icut++) { |
23 |
|
if (_cuts[icut]->ApplyCut(event) != CUTOK && firstFailed == _cuts.size()) { |
24 |
|
firstFailed = icut; |
25 |
|
} |
26 |
} |
} |
|
} |
|
|
|
|
|
void SmartBlindCollection::OnGood(PamLevel2 *event){ |
|
|
BlindCutCollection::OnGood(event); |
|
27 |
|
|
28 |
for (unsigned int i = 0; i < _actions.size(); i++){ |
//Do actions |
29 |
_actions[i]->OnGood(event); |
if (_actions.size() > 0) { |
30 |
|
for (unsigned int i = 0; i < _actions.size(); i++) { |
31 |
|
if (_actionsPositions[i] < (int)firstFailed) |
32 |
|
_actions[i]->OnGood(event); |
33 |
|
else |
34 |
|
_actions[i]->OnBad(event, firstFailed); |
35 |
|
} |
36 |
} |
} |
|
} |
|
37 |
|
|
38 |
void SmartBlindCollection::OnBad(PamLevel2 *event, int selectionResult){ |
if (firstFailed == _cuts.size()) { |
39 |
BlindCutCollection::OnBad(event, selectionResult); |
_nGood++; |
40 |
|
OnGood(event); |
41 |
for (unsigned int i = 0; i < _actions.size(); i++){ |
return CUTOK; |
42 |
_actions[i]->OnBad(event, selectionResult); |
} |
43 |
|
else { |
44 |
|
OnBad(event, firstFailed); |
45 |
|
return firstFailed; |
46 |
} |
} |
47 |
|
|
48 |
} |
} |