-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapping.cpp
40 lines (36 loc) · 972 Bytes
/
Mapping.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
#include "Mapping.h"
#include <stdexcept>
#include <iostream>
Mapping::Mapping(const std::string& map) {
if(map.length() != 26) {
throw std::runtime_error("map not 26 long");
}
int i = 0;
for(auto character : map) {
alphabetMap[i] = character;
++i;
}
}
Mapping::Mapping(const std::string& map, const bool reverse) {
std::string base = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int i = 0;
if(!reverse)
Mapping(map);
else {
if(map.length() != 26) {
throw std::runtime_error("map not 26 long");
}
for(char character : map) {
alphabetMap[character % 'A'] = base[i];
++i;
}
}
}
char Mapping::operator[](const char input) {
int index = input % 'A';
if(index >= 0 && index <= 25) {
// std::cout << alphabetMap[index] << std::endl;
return alphabetMap[index];
}
throw std::runtime_error("illegal input character");
}