Commit 130f0b45 authored by xueyimeng's avatar xueyimeng

完善代码

parent 71d1ea27
//
// Created by xueyimeng on 21-9-17.
//
#include "Reporter.h"
#include <fstream>
FileReporter::~FileReporter() {
if(fs.is_open()) {
fs.close();
}
}
FileReporter::FileReporter(const std::string& result_pathname) {
this->result_pathname = result_pathname;
if(!fs.is_open()) {
fs.open(result_pathname.c_str());
}
}
void FileReporter::report(const std::string& message) {
if(fs.is_open()) {
mutex.lock();
fs << message << std::endl;
mutex.unlock();
}
}
\ No newline at end of file
...@@ -25,11 +25,27 @@ class FileReporter : public Reporter { ...@@ -25,11 +25,27 @@ class FileReporter : public Reporter {
protected: protected:
FileReporter() {} FileReporter() {}
public: public:
FileReporter(const std::string& reporter); FileReporter(const std::string& reporter) {
virtual ~FileReporter(); this->result_pathname = reporter;
if(!fs.is_open()) {
fs.open(result_pathname.c_str());
}
}
virtual ~FileReporter() {
if(fs.is_open()) {
fs.close();
}
}
public: public:
virtual void report(const std::string& message); virtual void report(const std::string& message) {
if(fs.is_open()) {
mutex.lock();
fs << message << std::endl;
mutex.unlock();
}
}
private: private:
......
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