-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_CSV.cpp
79 lines (69 loc) · 1.92 KB
/
write_CSV.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
//
// Created by shaqfa on 13/02/19.
//
#include "write_CSV.h"
csv_dump::csv_dump(std::string& file_name): fname(file_name) {
file_name+=".csv";
new_file.open(file_name);
}
csv_dump::~csv_dump() {new_file.close();}
template <class T>
void csv_dump::dump(T& dumped_value) {
new_file << dumped_value<<"\n";
}
template <class T>
void csv_dump::dump(std::vector<T>& dumped_vector) {
for(auto&& v: dumped_vector)
new_file << v <<"\n";
}
void csv_dump::dump(RealVec& dumped_vector) {
for(auto&& v: dumped_vector)
new_file << v <<"\n";
}
void csv_dump::dump(UIntVec& dumped_vector) {
for(auto&& v: dumped_vector)
new_file << v <<"\n";
}
template<typename T>
void csv_dump::dump(std::vector<std::vector<T>>& dumped_matrix) {
UInt Id_cols = 0, Id_rows = 0;
for (auto& row : dumped_matrix) {
Id_cols = 0;
for (auto col : row){
new_file << col;
if (Id_cols < (dumped_matrix[0].size() - 1))
new_file <<",";
Id_cols++;
}
if (Id_rows < (dumped_matrix.size() - 1))
new_file << std::endl;
}
}
void csv_dump::dump(RealMat& dumped_matrix) {
UInt Id_cols = 0, Id_rows = 0;
for (auto& row : dumped_matrix) {
Id_cols = 0;
for (auto col : row){
new_file << col;
if (Id_cols < (dumped_matrix[0].size() - 1))
new_file <<",";
Id_cols++;
}
if (Id_rows < (dumped_matrix.size() - 1))
new_file << std::endl;
}
}
void csv_dump::dump(UIntMat& dumped_matrix) {
UInt Id_cols = 0, Id_rows = 0;
for (auto& row : dumped_matrix) {
Id_cols = 0;
for (auto col : row){
new_file << col;
if (Id_cols < (dumped_matrix[0].size() - 1))
new_file <<",";
Id_cols++;
}
if (Id_rows < (dumped_matrix.size() - 1))
new_file << std::endl;
}
}