-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPassagier.cpp
98 lines (83 loc) · 3.79 KB
/
Passagier.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
#include "Passagier.h"
#include "DesignByContract.h"
#include <iostream>
Passagier::Passagier() {
initCheck = this;
ENSURE(properlyInitialized(), "constructor must end in properlyInitialized state");
}
Passagier::Passagier(std::string naam, std::string beginStation, std::string eindStation, int hoeveelheid) :
naam(naam),
beginStation(beginStation),
eindStation(eindStation),
hoeveelheid(hoeveelheid)
{
REQUIRE(naam != "", "naam must not be empty");
REQUIRE(beginStation != "", "beginStation must not be empty");
REQUIRE(eindStation != "", "eindStation must not be empty");
REQUIRE(hoeveelheid >= 0 , "hoeveelheid must be bigger or equal to zero");
initCheck = this;
ENSURE(properlyInitialized(), "constructor must end in properlyInitialized state");
}
Passagier::~Passagier() {
}
bool Passagier::properlyInitialized() const{
return initCheck == this;
}
std::string Passagier::getNaam() const {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling getNaam");
return naam;
}
std::string Passagier::getBeginStation() const {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling getBeginStation");
return beginStation;
}
std::string Passagier::getEindStation() const {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling getEindStation");
return eindStation;
}
int Passagier::getHoeveelheid() const {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling getHoeveelheid");
return hoeveelheid;
}
void Passagier::setNaam(const std::string& newNaam) {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling setNaam");
REQUIRE(newNaam != "" , "newNaam must not be empty");
naam = newNaam;
ENSURE(getNaam() == newNaam, "setNaam post condition failure");
}
void Passagier::setBeginStation(const std::string& newBeginStation) {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling setBeginStation");
REQUIRE(newBeginStation != "" , "newBeginStation must not be empty");
beginStation = newBeginStation;
ENSURE(getBeginStation() == newBeginStation, "setBeginStation post condition failure");
}
void Passagier::setEindStation(const std::string& newEindStation) {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling setEindStation");
REQUIRE(newEindStation != "" , "newEindStation must not be empty");
eindStation = newEindStation;
ENSURE(getEindStation() == newEindStation, "setEindStation post condition failure");
}
void Passagier::setHoeveelheid(const int newHoeveelheid) {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling setHoeveelheid");
REQUIRE(newHoeveelheid >= 0 , "newHoeveelheid must be bigger or equal to zero");
hoeveelheid = newHoeveelheid;
ENSURE(getHoeveelheid() == newHoeveelheid, "setHoeveelheid post condition failure");
}
void Passagier::moveToBeginStation(MetroNet& metronet) const {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling moveToBeginStation");
REQUIRE(metronet.properlyInitialized(), "MetroNet wasn't initialized when calling Passagier::moveToBeginStation");
REQUIRE(metronet.getStation(beginStation) != nullptr, "beginStation is not a station of MetroNet");
Station* station = metronet.getStation(beginStation);
station->addPassagier(naam);
ENSURE(station->isInStation(naam), "moveToBeginStation post condition failure");
ENSURE(metronet.isConsistent(), "Passagier::moveToBeginStation made MetroNet inconsistent");
}
bool Passagier::isAangekomen() const {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling isAangekomen");
return aangekomen;
}
void Passagier::markAangekomen() {
REQUIRE(properlyInitialized(), "Passagier wasn't initialized when calling markAangekomen");
aangekomen = true;
ENSURE(isAangekomen() == true, "markAangekomen post condition failure");
}