-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLocation.cpp.orig
110 lines (96 loc) · 3.01 KB
/
Location.cpp.orig
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
#include "Location.h"
#include <iostream>
#include <string>
#include <vector>
#include <memory>
Location::Location(){
}
Location::Location(std::string name)
: name{name}
{
std::cout <<"location created"<<std::endl;
}
Location::Location(std::string nam, std::vector<std::shared_ptr<Component>> &components)
: name{nam}
{
this->components = components;
}
std::string Location::getName() const{
return this->name;
}
/*
* Louise changes the method below to add a component instead of sensor.
* Adding a component allows us to build a tree structure. Location shouldn't care if more
* locations or sensors are added, thus we need to generalize to component
*/
void Location::add(std::shared_ptr<Component> component) {
components.push_back(component);
}
void Location::testSensorAction(){
for(long unsigned int i=0; i<this->Components.size(); i++){
Components.at(i)->testSensorAction();
}
}
std::vector<std::shared_ptr<Location>> Location::getLocations() {
std::vector<std::shared_ptr<Location>> locations;
for(long unsigned int i=0; i<this->components.size(); i++){
std::vector<std::shared_ptr<Location>> Mylocation = components.at(i)->getLocations();
locations.insert(locations.end(), Mylocation.begin(), Mylocation.end());
}
locations.push_back(shared_from_this());
return locations;
}
/*
void Location::trigger(bool trigger_variable){
for(long unsigned int i=0; i < components.size(); i++){
(components[i])->trigger(trigger_variable);
};
}
<<<<<<< HEAD
void Location::activate(bool activation){
for(long unsigned int i=0; i < components.size(); i++){
(components[i])->activate(activation);
};
}
*/
=======
>>>>>>> 975c562e404ac42c025e77b999340887d08efe98
std::vector<std::shared_ptr<Sensor>> Location::getSensors(){
std::vector<std::shared_ptr<Sensor>> sensorList;
for(long unsigned int i=0; i<this->components.size(); i++){
std::vector<std::shared_ptr<Sensor>> Mysensor = components.at(i)->getSensors();
sensorList.insert(sensorList.end(), Mysensor.begin(), Mysensor.end());
}
return sensorList;
}
void Location::printSensors(){
std::vector<std::shared_ptr<Sensor>> sensorList = this->getSensors();
for(auto & s : sensorList){
std::cout << s << std::endl;
}
}
void Location::printLocations(){
std::vector<std::shared_ptr<Location>> locationList = this->getLocations();
for(auto & s : locationList){
std::cout << s << std::endl;
}
}
void Location::operator++(){
<<<<<<< HEAD
for(int i=0; i < (int)components.size(); i++){
(components.at(i))->operator++();
=======
for(int i=0; i < (int)this->Components.size(); i++){
auto instance = Components.at(i);
++*instance;
std::cout<<"component has been activated from "<< this->name<<std::endl;
>>>>>>> 975c562e404ac42c025e77b999340887d08efe98
}
return;
}
void Location::operator--(){
for(int i=0; i < (int)components.size(); i++){
(components.at(i))->operator--();
}
return;
}