Train_RFID_Linux/ai_matrix/Utils/Utils.h

72 lines
1.8 KiB
C
Raw Normal View History

//
// Created by matrixai on 4/2/24.
//
#ifndef TRAIN_RFID_LINUX_UTILS_H
#define TRAIN_RFID_LINUX_UTILS_H
#include <mutex>
#include <sstream>
#include <fstream>
#include <dirent.h>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <memory>
#include <cstring>
namespace ai_matrix
{
class Utils final
{
public:
static Utils *getins();
//计算均值
float getMean(const std::vector<float> &data);
//计算最大值
float getMax(const std::vector<float> &data);
//计算最小值
float getMin(const std::vector<float> &data);
//计算中位数
float getMedian(const std::vector<float> &data);
bool contains_vec(const std::vector<std::string> &vec, std::string x);
// //读取json格式文件内容
// bool ReadJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath);
// //json格式内容写入文件
// bool WriteJsonInfo(Json::Value &jvFileInfo, std::string &strFilePath);
private:
Utils() = default;
Utils(const Utils &) = delete;
Utils(Utils &&) = delete;
Utils &operator=(const Utils &) = delete;
Utils &operator=(Utils &&) = delete;
~Utils() = default;
//定义一个嵌套类,负责释放内存,操作系统自动完成,不用担心内存泄露
class GarbageCollector
{
public:
~GarbageCollector()
{
if (Utils::ins)
{
delete Utils::ins;
Utils::ins = nullptr;
}
}
};
static GarbageCollector gc;
static Utils *ins;
static std::mutex mx; //锁,保证线程安全
};
}
#endif //TRAIN_RFID_LINUX_UTILS_H