-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstat_printer.hpp
62 lines (51 loc) · 1.25 KB
/
stat_printer.hpp
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
/*
* stat_printer.hpp
*
* Created on: Nov 13, 2015
* Author: Joost Huizinga
*/
#ifndef MODULES_MISC_STAT_PRINTER_HPP_
#define MODULES_MISC_STAT_PRINTER_HPP_
namespace sferes
{
namespace stat
{
class StatPrinter{
public:
void dataStart(){
index = 0;
}
template<typename DataType>
void add(bool active, std::string name, DataType value){
if(!active) return;
std::ostringstream ss;
ss << value;
std::string value_str = ss.str();
if(index >= values.size()){
headers.push_back(name);
values.push_back(value_str);
} else {
values[index] = value_str;
}
++index;
}
void dataPrint(boost::shared_ptr<std::ofstream> file_stream){
if(file_stream->tellp() == 0){
for(size_t i=0; i<headers.size(); ++i){
(*file_stream) << headers[i] << " ";
}
(*file_stream) << "\n";
}
for(size_t i=0; i<values.size(); ++i){
(*file_stream) << values[i] << " ";
}
(*file_stream) << std::endl;
}
private:
size_t index;
std::vector<std::string> headers;
std::vector<std::string> values;
};
}
}
#endif /* MODULES_MISC_STAT_PRINTER_HPP_ */