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 {
protected:
FileReporter() {}
public:
FileReporter(const std::string& reporter);
virtual ~FileReporter();
FileReporter(const std::string& reporter) {
this->result_pathname = reporter;
if(!fs.is_open()) {
fs.open(result_pathname.c_str());
}
}
virtual ~FileReporter() {
if(fs.is_open()) {
fs.close();
}
}
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:
......
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