-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTaskManager.cpp
82 lines (71 loc) · 1.95 KB
/
TaskManager.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
//Sina Lahsaee
//129948162
//File includes
#include "TaskManager.h"
#include "ItemManager.h"
#include "Task.h"
#include "Item.h"
//Library decleration
#include <algorithm>
using namespace std;
//vailating each task against one another and if an unvalidated task exists. it outputs it.
void TaskManager::validate(std::ostream &os)
{
bool yes = true, no = true;
vector<Task>::iterator temp, solid;
//Bubblesort with iterators. To compare task by task
for (temp = begin(); temp != end(); temp++)
{
no = true;
for (solid = begin(); solid != end(); solid++)
{
if (temp->validate(*solid))
{
no = false;
}
}
yes = !no;
}
//the if statement below prints out the error incase tasks are left unvalidated
if (yes == false)
{
os << "*** Certain Tasks need to be validated ***" << endl;
}
}
void TaskManager::validate(const ItemManager &itemManager, std::ostream &os)
{
vector<Item>::const_iterator tempI;
for (tempI = itemManager.begin(); tempI != itemManager.end(); tempI++)
{
const auto& rands = *tempI;
//checks to see if task assigned is inside the container. lambda function that translates to bool (returns a bool)
auto fill = [&](const Task& a)->bool
{
if (a.getName() == rands.getFiller())
{
return true;
}
else return false;
};
//checks to see if the task assigned is inside the container using the remover function
auto rem = [&](const Task& a)->bool
{
if (a.getName() == rands.getRemover())
{
return true;
}
else return false;
};
//the following two if statements will insert a message into the OS stream saying that task is unavailable
if (find_if(begin(), end(), fill) == this->end()) os << rands.getFiller() << " is unavailable" << endl;
if (find_if(begin(), end(), rem) == this->end()) os << rands.getRemover() << " is unavailable" << endl;
}
}
//displays the taskmanager object
void TaskManager::display(std::ostream &os) const
{
for (auto& temp : *this)
{
temp.display(os);
};
}