forked from PFCCLab/PaddleCppAPITest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_manager.h
More file actions
47 lines (40 loc) · 1.04 KB
/
file_manager.h
File metadata and controls
47 lines (40 loc) · 1.04 KB
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
#pragma once
#include <fstream>
#include <functional>
#include <mutex>
#include <shared_mutex>
#include <string>
namespace paddle_api_test {
class FileManerger {
public:
FileManerger() = default;
explicit FileManerger(const std::string& first) : file_name_(first) {}
void setFileName(const std::string& value);
void createFile();
void openAppend();
void writeString(const std::string& str);
FileManerger& operator<<(const std::string& str);
void saveFile();
// 捕获标准输出到文件
void captureStdout(std::function<void()> func);
private:
mutable std::shared_mutex mutex_;
std::string basic_path_ = "/tmp/paddle_cpp_api_test/";
std::string file_name_ = "";
std::ofstream file_stream_;
};
class ThreadSafeParam {
private:
std::string param_;
mutable std::mutex mutex_;
public:
void set(const std::string& value) {
std::lock_guard<std::mutex> lock(mutex_);
param_ = value;
}
std::string get() const {
std::lock_guard<std::mutex> lock(mutex_);
return param_;
}
};
} // namespace paddle_api_test