-
Notifications
You must be signed in to change notification settings - Fork 0
/
house.cpp
108 lines (97 loc) · 2.34 KB
/
house.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
#include "house.h"
#include "roomfactory.h"
#include <iostream>
using namespace std;
/*!
* \brief House::_houseInstance
* Global static pointer to ensure a single instance of the class.
*/
House *House::_houseInstance = NULL;
House::House()
{
}
House::~House()
{
}
/*!
* \brief House::instance
* \return House instance
* Ensures only a single instance of House exists at any one time.
*/
House *House::instance()
{
if(!_houseInstance)
_houseInstance = new House();
return _houseInstance;
}
/*
*This method is called by "Setup Room Called 'X'" Command
*/
void House::createRoom(TYPES::ROOMS roomType, std::string roomName)
{
RoomFactory *rf = new RoomFactory;
Room *room = rf->create(roomType, roomName);
cout << "Setup " << room->getName() << endl;
_rooms.push_back(room);
}
/*
*This method is called by "Turn Room 'X' On"
*/
void House::turnRoomOn(std::string roomName)
{
for(std::vector<Room *>::iterator it = _rooms.begin(); it != _rooms.end(); ++it)
{
Room *r = *it;
if(r->getName() == roomName)
{
cout << "Turning on components in " << r->getName() << endl;
r->turnOnComponents();
}
}
}
/*
*This method is called by "Turn Room 'X' Off"
*/
void House::turnRoomOff(std::string roomName)
{
for(std::vector<Room *>::iterator it = _rooms.begin(); it != _rooms.end(); ++it)
{
Room *r = *it;
if(r->getName() == roomName)
{
cout << "Turning off components in " << r->getName() << endl;
r->turnOffComponents();
}
}
}
/*
*This method is called by "Turn House Off"
*/
void House::turnHouseOff()
{
cout << "Turning off all components!" << endl;
for(std::vector<Room *>::iterator it = _rooms.begin(); it != _rooms.end(); ++it)
{
Room *r = *it;
r->turnOffComponents();
}
}
std::vector<Component *> House::getComponents()
{
std::vector<Component *> components;
for(std::vector<Room *>::iterator it = _rooms.begin(); it != _rooms.end(); ++it)
{
Room *r = *it;
components = r->getComponents();
}
return components;
}
Room *House::getRoom(std::string roomName)
{
for(std::vector<Room *>::iterator it = _rooms.begin(); it != _rooms.end(); ++it)
{
Room *r = *it;
if(r->getName() == roomName)
return r;
}
}