-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProject.cpp
107 lines (88 loc) · 2.22 KB
/
Project.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
#include "classes.hpp"
using namespace std;
Project::Project(ProjectHandler* projectHandler, double projectIndex, double sciGrade):
projectHandler(projectHandler),
projectIndex(projectIndex),
sciGrade(sciGrade),
remainingExec(1.0),
numSchedBlocks(0U)
{
}
Project::~Project(){
while (!schedBlocks.empty()) {
SchedBlock* oldSchedBlock = schedBlocks.front();
schedBlocks.pop_front();
delete oldSchedBlock;
}
}
unsigned int Project::getIndex(){
return this->projectIndex;
}
double Project::getSciGrade(){
return this->sciGrade;
}
double Project::getRemainingExec(){
return this->remainingExec;
}
list<SchedBlock*> Project::getSchedBlocks(){
return this->schedBlocks;
}
ProjectHandler* Project::getProjectHandler(){
return this->projectHandler;
}
list<SchedBlock*> Project::getPendingSchedBlocks(){
list<SchedBlock*> p;
for( list<SchedBlock *>::iterator it = schedBlocks.begin();
it != schedBlocks.end();
it++)
{
if(!(*it)->isExecuted())
{
p.push_back(*it);
}
}
return p;
}
SchedBlock* Project::getSchedBlock(unsigned int schedBlockIndex){
list<SchedBlock*> p;
for( list<SchedBlock *>::iterator it = schedBlocks.begin();
it != schedBlocks.end();
it++)
{
if(!(*it)->getIndex() == schedBlockIndex)
{
return *it;
}
}
return (SchedBlock*)NULL;
}
void Project::addSchedBlock(
unsigned int schedBlockIndex,
int seqBlockIndex,
time_t execTime,
double obsFrequency,
double RA, double Dec, double LTSr, double LTSs)
{
SchedBlock* newSchedBlock = new SchedBlock(
this,
schedBlockIndex,seqBlockIndex,execTime,obsFrequency,
RA,Dec,LTSr,LTSs);
newSchedBlock->registerObserver(this);
schedBlocks.push_back(newSchedBlock);
numSchedBlocks++;
}
void Project::notify(Observable* o)
{
// Notification by SchedBlock
SchedBlock* schedBlockSubject = dynamic_cast<SchedBlock*>(o);
if (schedBlockSubject != NULL) {
// cout << "-- Project received SchedBlock notification." << endl;
double newRemainingExec = double(getPendingSchedBlocks().size()) / double(numSchedBlocks);
if (newRemainingExec != this->remainingExec) {
this->remainingExec = newRemainingExec;
this->notifyObservers();
}
return;
}
cerr << "ERROR: Project received notification from unknown subject." << endl;
}