82 lines
2.1 KiB
C
82 lines
2.1 KiB
C
|
|
//
|
||
|
|
// Created by matrixai on 4/2/24.
|
||
|
|
//
|
||
|
|
|
||
|
|
#ifndef TRAIN_RFID_LINUX_FILEUTIL_H
|
||
|
|
#define TRAIN_RFID_LINUX_FILEUTIL_H
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
#include <mutex>
|
||
|
|
#include <fstream>
|
||
|
|
#include <dirent.h>
|
||
|
|
#include <sys/stat.h>
|
||
|
|
#include <unistd.h>
|
||
|
|
#include <string>
|
||
|
|
#include <vector>
|
||
|
|
#include <algorithm>
|
||
|
|
#include <set>
|
||
|
|
#include <map>
|
||
|
|
#include <memory>
|
||
|
|
#include "json/json.h"
|
||
|
|
|
||
|
|
namespace ai_matrix
|
||
|
|
{
|
||
|
|
class FileUtil final
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
static FileUtil *getins();
|
||
|
|
|
||
|
|
//创建文件夹
|
||
|
|
std::string create_dir_name(std::string root, std::string name);
|
||
|
|
std::string create_dir_date_name_time(std::string root, std::string name);
|
||
|
|
std::string create_dir_date(std::string root);
|
||
|
|
//创建文件路径
|
||
|
|
std::string create_file_path(std::string root, std::string name, std::string suffix);
|
||
|
|
//创建文件夹路径
|
||
|
|
bool createDirPath(std::string strDirPath);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 拷贝文件
|
||
|
|
* @param filePath 源文件位置
|
||
|
|
* @param savePath 将要拷贝的新位置
|
||
|
|
* @return
|
||
|
|
*/
|
||
|
|
bool copyFile(std::string filePath, std::string savePath);
|
||
|
|
|
||
|
|
//读取json格式文件内容
|
||
|
|
bool readJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath);
|
||
|
|
//json格式内容写入文件
|
||
|
|
bool writeJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath);
|
||
|
|
|
||
|
|
|
||
|
|
private:
|
||
|
|
FileUtil() = default;
|
||
|
|
FileUtil(const FileUtil &) = delete;
|
||
|
|
FileUtil(FileUtil &&) = delete;
|
||
|
|
FileUtil &operator=(const FileUtil &) = delete;
|
||
|
|
FileUtil &operator=(FileUtil &&) = delete;
|
||
|
|
~FileUtil() = default;
|
||
|
|
|
||
|
|
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
|
||
|
|
class GarbageCollector
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
~GarbageCollector()
|
||
|
|
{
|
||
|
|
if (FileUtil::ins)
|
||
|
|
{
|
||
|
|
delete FileUtil::ins;
|
||
|
|
FileUtil::ins = nullptr;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
static GarbageCollector gc;
|
||
|
|
static FileUtil *ins;
|
||
|
|
static std::mutex mx; //锁,保证线程安全
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
#endif //TRAIN_RFID_LINUX_FILEUTIL_H
|