-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoardingStatus.cpp
More file actions
45 lines (36 loc) · 1.23 KB
/
BoardingStatus.cpp
File metadata and controls
45 lines (36 loc) · 1.23 KB
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
#include "Observer.hpp"
#include "BoardingStatus.hpp"
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const string sBoardingAlertMsg = ", \n\nBoarding is open, pls come to boarding area immediately. \n\nRegards, \nAA Airlines\n\n";
//Register the passenger in the observer list
void BoardingStatus::registerObserver(Observer *iPassenger) {
m_passengers.emplace_back(iPassenger);
}
void BoardingStatus::deregisterObserver(Observer *iPassenger) {
auto iterator = std::find(m_passengers.begin(), m_passengers.end(), iPassenger);
//De-register/Remove the observer
if (iterator != m_passengers.end()) {
m_passengers.erase(iterator);
}
}
// Notify all passengers who are Observing Boarding status update
void BoardingStatus::notifyObservers()
{
for (Observer *aPassenger : m_passengers)
{
string sAlertMessage = "Dear " + aPassenger->getPassengerName() + sBoardingAlertMsg;
aPassenger->updateStatus(sAlertMessage);
}
}
//Open/Close Boarding Gate
void BoardingStatus::setBoardingStatus(const bool& isBoardingOpen){
m_isBoardingOpen = isBoardingOpen;
//Alert passengers if boarding is open only
if(m_isBoardingOpen)
{
notifyObservers();
}
}