-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathResults.h
69 lines (58 loc) · 1.45 KB
/
Results.h
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
/*
* BSD 3-Clause License
* Copyright (c) 2018, Máté Cserép & Péter Hudoba
* All rights reserved.
*
* You may obtain a copy of the License at
* https://opensource.org/licenses/BSD-3-Clause
*/
#ifndef RAILROAD_RESULTS_H
#define RAILROAD_RESULTS_H
#include <set>
#include <map>
#include <string>
#include <iostream>
namespace railroad
{
template<typename T>
class Results;
template<typename T>
std::ostream &operator<<(std::ostream &out, const Results<T> &results);
template<typename T>
class Results
{
public:
void add(const std::string &name, const std::map<std::string, T> &result)
{
for (auto const &x : result) {
names.emplace(x.first);
}
data[name] = result;
}
friend std::ostream &operator<<<T>(std::ostream &out, const Results &results);
protected:
std::set<std::string> names;
std::map<std::string, std::map<std::string, T> > data;
};
template<typename T>
std::ostream &operator<<(std::ostream &out, const Results<T> &results)
{
out << "\t";
for (auto const &name : results.names) {
out << name << "\t";
}
out << std::endl;
for (auto row : results.data) {
out << row.first << "\t";
for (std::string name : results.names) {
if (row.second.count(name) > 0) {
out << row.second[name];
}
out << "\t";
}
out << std::endl;
}
return out;
}
} // railroad
#endif //RAILROAD_RESULTS_H