-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest_simple.cpp
113 lines (96 loc) · 2.89 KB
/
test_simple.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include <fstream>
#include <iostream>
#include <vector>
#include "templateio.hpp"
#include "parser_simple.hpp"
#include "profile.hpp"
using namespace std;
//----------------------------------------------------------------------------
struct csv_parser : private parser {
csv_parser(istream &in) : parser(in) {}
bool separator(string *s = nullptr) {
accept(is_char(','), s) && space();
return true;
}
bool parse_int(vector<int> &ts) {
string n;
if (number(&n) && separator()) {
ts.push_back(stoi(n));
return true;
}
return false;
}
bool many_ints(vector<int> &ts) {
if (parse_int(ts)) {
while (parse_int(ts));
return true;
}
return false;
}
bool parse_line(vector<vector<int>> &ts) {
vector<int> t {};
if (many_ints(t)) {
space();
ts.push_back(move(t));
return true;
}
return false;
}
bool parse_csv(vector<vector<int>> &result) {
profile<csv_parser> p;
if (parse_line(result)) {
while (parse_line(result));
return true;
}
return false;
}
int operator() () {
vector<vector<int>> a;
if (parse_csv(a)) {
cout << "OK" << endl;
} else {
cout << "FAIL" << endl;
}
int sum = 0;
for (int i = 0; i < a.size(); ++i) {
for (int j = 0; j < a[i].size(); ++j) {
sum += a[i][j];
}
}
sum /= a.size();
cerr << sum << endl;
return get_count();
}
};
//----------------------------------------------------------------------------
int main(int const argc, char const *argv[]) {
if (argc < 1) {
cerr << "no input files" << endl;
} else {
for (int i = 1; i < argc; ++i) {
try {
fstream in(argv[i], ios_base::in);
cout << argv[i] << endl;
if (in.is_open()) {
csv_parser csv(in);
profile<csv_parser>::reset();
int const chars_read = csv();
double const mb_per_s = static_cast<double>(chars_read) / static_cast<double>(profile<csv_parser>::report());
cout << "parsed: " << mb_per_s << "MB/s" << endl;
}
} catch (parse_error& e) {
cerr << argv[i] << ": " << e.what()
<< " " << e.exp
<< " found ";
if (is_print(e.sym)) {
cerr << "'" << static_cast<char>(e.sym) << "'";
} else {
cerr << "0x" << hex << e.sym;
}
cerr << " at line " << e.row
<< ", column " << e.col << endl;
return 2;
}
}
}
}