// // Created by matrixai on 4/2/24. // #ifndef TRAIN_RFID_LINUX_UTILS_H #define TRAIN_RFID_LINUX_UTILS_H #include #include #include #include #include #include #include #include #include #include #include namespace ai_matrix { class Utils final { public: static Utils *getins(); //计算均值 float getMean(const std::vector &data); //计算最大值 float getMax(const std::vector &data); //计算最小值 float getMin(const std::vector &data); //计算中位数 float getMedian(const std::vector &data); bool contains_vec(const std::vector &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