-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cc
87 lines (83 loc) · 2.13 KB
/
main.cc
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
#include <iostream>
#include <memory>
#include <string>
#include <time.h>
#include "includes/reedmuller.h"
using namespace std;
CACHE getCacheType(char c){
switch (c) {
case 'p':
return CACHE::PARTIAL;
break;
case 'f':
return CACHE::FULL;
break;
default:
break;
}
return CACHE::NONE;
};
string getCacheName(char c){
switch (c) {
case 'p':
return "partial";
break;
case 'f':
return "full";
break;
default:
break;
}
return "none";
};
int main() {
int lines, m, r;
char e,c;
clock_t t,now;
string s, result;
cin >> lines;
for (int i=0; i<lines; i++) {
cin >> r >> m >> e >> c >> s;
BITSET data(s);
now = clock();
unique_ptr<RM> cube(new RM(r,m,getCacheType(c)));// Initialization
t = clock()-now;
// Return code info
cout<< "Initialization in:"<<((double)t)/CLOCKS_PER_SEC<<" sec."<< endl;
cout<< "Cached:"<<getCacheName(c)<<endl;
cout<<"Meassage length(k):"<<cube->messageLength<<endl;
cout<<"Block length(n):"<<cube->blockLength<<endl;
cout<<"Rate(k/n):"<<cube->dataRate<<endl;
cout<<"Bit error tolerance:"<<cube->errBitTol<<" bit(s)"<<endl;
// encoding or decoding
switch (e){
case 'e':
{
now = clock();
// Encoding
BITSET encoded = cube->encode(data);
t=clock()-now;
cout<<"message:"<<s<<endl;
cout<<"encoded:"<<encoded<<endl;
cout<<"encoded in:"<<((double)t)/CLOCKS_PER_SEC<<" sec."<< endl;
cout<<"--------------------------------"<<endl;
break;
}
case 'd':
{
now = clock();
// Decoding
BITSET decoded = cube->decode(data);
t=clock()-now;
cout<<"received_code:"<<s<<endl;
cout<<"______decoded:"<<decoded<<endl;
cout<<"decoded in:"<<((double)t)/CLOCKS_PER_SEC<<" sec."<< endl;
cout<<"--------------------------------"<<endl;
break;
}
default:
continue;
};
}
return 0;
}