Commit 873d8373 authored by Zhiping Jiang (蒋志平)'s avatar Zhiping Jiang (蒋志平) 💬

Template-lize the CSVFileWriter

parent e00113ef
......@@ -7,24 +7,3 @@
//
#include "jzplib_utilities.h"
#include <iomanip>
#include <fstream>
void CSVFileWriter::addCSVLine(std::vector<float> slot) {
slots.push_back(slot);
}
void CSVFileWriter::writeToFile(const std::string & filePath) {
std::ofstream textFile(filePath);
int i = 0, j =0 ;
for (i= 0; i< slots.size(); i++) {
for (j = 0; j < slots[i].size()-1; j++) {
textFile<<std::setprecision(10) <<slots[i][j]<<delimeter;
}
textFile<<std::setprecision(10) <<slots[i][j]<<std::endl;
}
textFile.flush();
textFile.close();
}
......@@ -9,17 +9,34 @@
#ifndef jzplib_utilities_h
#define jzplib_utilities_h
#include <string>
#include <vector>
#include <string>
#include <fstream>
#include <iomanip>
class CSVFileWriter {
template<typename _Tp> class CSVFileWriter {
public:
std::string delimeter = " ";
void addCSVLine(std::vector<float> slot);
void writeToFile(const std::string & filePath);
void addCSVLine(std::vector<_Tp> slot) {
slots.push_back(slot);
}
void writeToFile(const std::string & filePath) {
std::ofstream textFile(filePath);
int i = 0, j =0 ;
for (i= 0; i< slots.size(); i++) {
for (j = 0; j < slots[i].size()-1; j++) {
textFile<<std::setprecision(10) <<slots[i][j]<<delimeter;
}
textFile<<std::setprecision(10) <<slots[i][j]<<std::endl;
}
textFile.flush();
textFile.close();
};
private:
std::vector<std::vector<float>> slots;
std::vector<std::vector<_Tp>> slots;
};
#endif /* jzplib_utilities_h */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment