-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enigma.cpp
89 lines (67 loc) · 2.13 KB
/
Enigma.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
/*
* Enigma.cpp
*
* Created on: Jun 23, 2017
* Author: master
*/
#include "Enigma.h"
namespace mtm{
namespace escaperoom{
Enigma::Enigma(const std::string& name, const Difficulty& difficulty, const int& numOfElements):
//TODO what to do in case of numOfelements < 0?
name(name),
difficulty(difficulty),
numOfElements(numOfElements) { if ( numOfElements < 0 ) throw EnigmaIllegalSizeParamException();
}
Enigma::Enigma(const std::string& name, const Difficulty& difficulty, const int& numOfElements, set<string> elements) :
name(name),
difficulty(difficulty),
numOfElements(numOfElements) {
if ( (unsigned)numOfElements != elements.size() ) throw EnigmaIllegalSizeParamException();
for (set<string>::iterator it = elements.begin(); it != elements.end(); it++) {
this->elements.insert(*it);
}
}
bool Enigma::operator==(const Enigma& enigma) const {
return (this->name.compare(enigma.name) == 0) && this->difficulty == enigma.difficulty;
}
bool Enigma::operator!=(const Enigma& enigma) const {
return !(*this == enigma);
}
bool Enigma::operator<(const Enigma& enigma) const {
if (*this==enigma) return false;
return this->difficulty < enigma.difficulty;
}
bool Enigma::operator>(const Enigma& enigma) const {
return enigma.difficulty < this->difficulty;
}
//TODO different names same difficulty
bool Enigma::areEqualyComplex(const Enigma& enigma) const {
return (this->numOfElements == enigma.numOfElements) && this->difficulty == enigma.difficulty;
}
Difficulty Enigma::getDifficulty() const {
return this->difficulty;
}
string Enigma::getName() const {
return this->name;
}
std::ostream& operator<<(std::ostream& output, const Enigma& enigma) {
string name = enigma.getName();
output << name;
output << " (";
output << enigma.getDifficulty();
output << ") ";
output << enigma.numOfElements;
return output;
}
void Enigma::addElement(string element) {
this->elements.insert(element);
numOfElements++;
}
void Enigma::removeElement(const string& element) {
if ( this->elements.empty() ) throw EnigmaNoElementsException();
if ( this->elements.erase(element) < 1 ) throw EnigmaElementNotFoundException();
numOfElements--;
}
}
}