-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreflector.cpp
66 lines (62 loc) · 1.64 KB
/
reflector.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
#include"reflector.h"
#include<fstream>
#include<iostream>
#include"common.h"
#include"errors.h"
using namespace std;
Reflector::Reflector(){}
Reflector::~Reflector(){}
void Reflector::inputMap(const char* filename){
if(!checkNumeric(filename)){
cerr<<"Non-numeric character in reflector file "<<filename<<endl;
exit(NON_NUMERIC_CHARACTER);
}
ifstream in;
in.open(filename);
int count = 0;
int a,b;
in>>a;
if(in.eof()) {
cerr<<"Insufficient number of mappings in reflector file "<<filename<<endl;
exit(INCORRECT_NUMBER_OF_REFLECTOR_PARAMETERS);
}
in>>b;
if(in.eof()){
cerr<<"Incorrect (odd) number of mappings in reflector file "<<filename<<endl;
exit(INCORRECT_NUMBER_OF_REFLECTOR_PARAMETERS);
}
while(!in.eof()){
count++;
if(count > 13) {
cerr<<"Incorrect number of reflector parameters"<<endl;
exit(INCORRECT_NUMBER_OF_REFLECTOR_PARAMETERS);
}
if(map1.count(a)||a == b||map2.count(b)){
cerr<<"Invalid reflector mapping"<<endl;
exit(INVALID_REFLECTOR_MAPPING);
}
if(a<0||a>25||b<0||b>25){
cerr<<"Invalid index error in reflector"<<endl;
exit(INVALID_INDEX);
}
//cout<<"debug "<<a<<b<<endl;
map1.insert({a,b});
map2.insert({b,a});
in>>a;
if(in.eof()) break;
in>>b;
if(in.eof()) {
cerr<<"Incorrect (odd) number of parameters in reflector file "<<filename<<endl;
exit(INCORRECT_NUMBER_OF_REFLECTOR_PARAMETERS);
}
}
if(count < 13) {
cerr<<"Insufficient number of mappings in reflector file: "<<filename<<endl;
exit(INCORRECT_NUMBER_OF_REFLECTOR_PARAMETERS);
}
in.close();
}
int Reflector::getOutput(int input){
if(map1.count(input)) return map1[input];
return map2[input];
}