5 changed files with 87 additions and 19 deletions
-
3.vscode/settings.json
-
20appdep/iflytop/core/components/zcsv/zstream_csv_writer.cpp
-
34appdep/iflytop/core/components/zcsv/zstream_csv_writer.hpp
-
35appsrc/service/disinfection_logs_service.cpp
-
14appsrc/service/disinfection_logs_service.hpp
@ -0,0 +1,20 @@ |
|||
#include "zstream_csv_writer.hpp"
|
|||
|
|||
using namespace std; |
|||
using namespace iflytop; |
|||
|
|||
void ZStreamCSVWriter::addColumn(string key) { columns.push_back(key); } |
|||
void ZStreamCSVWriter::setValue(string key, string value) { //
|
|||
onelineDataCache[key] = value; |
|||
} |
|||
void ZStreamCSVWriter::addNewLine() { |
|||
outfile << endl; |
|||
for (auto& col : columns) { |
|||
if (onelineDataCache.find(col) == onelineDataCache.end()) { |
|||
outfile << ","; |
|||
} else { |
|||
outfile << onelineDataCache[col] << ","; |
|||
} |
|||
} |
|||
onelineDataCache.clear(); |
|||
} |
@ -0,0 +1,34 @@ |
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <fstream> // 引入文件流库
|
|||
#include <functional>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
|
|||
class ZStreamCSVWriter { |
|||
private: |
|||
list<string> columns; |
|||
map<string, string> onelineDataCache; |
|||
|
|||
ofstream outfile; |
|||
|
|||
public: |
|||
ZStreamCSVWriter(string filename) : outfile(filename) {}; |
|||
|
|||
void addColumn(string key); |
|||
void storageColumns(); |
|||
|
|||
void setValue(string key, string value); |
|||
void addNewLine(); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue