Files
cavity_LIBS/Public/util.h
T
2026-11-06 14:45:09 +08:00

57 lines
1.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef UTIL_H
#define UTIL_H
#include <string>
#include <QString>
#include <vector>
#include <QImage>
#define ARM_RUN true /* shi fou zai ARM shang yun xing*/
#if (ARM_RUN)
#include <assert.h>
#define ASSERT(x) assert(x)
#else
#define ASSERT(x) _ASSERT(x)
#endif
#define EPSLON 1E-6
#define COUNT_ARRAY(Array) (sizeof(Array)/sizeof(Array[0])) /*计算数组长度*/
#define DEL_PTR_S(pData) { try { if (pData) { delete (pData); (pData) = NULL; } } catch (...) { ASSERT(false); } ASSERT(NULL ==(pData)); } /* 安全删除指针 */
#define DEL_ARRAY_S(pData) { try { if (pData) { delete[] (pData); (pData) = NULL;} } catch (...) { ASSERT(false); } ASSERT(NULL ==(pData)); } /* 安全删除数组[] */
#define STR2SZ(str) ((LPSTR)(LPCTSTR)(str)) /* CStringתΪchar* */
typedef bool (*OnReceiveDataCallBackFunc)(int nDeviceIndex, double* pSpectrum, int nLen);
using namespace std;
class QWidget;
class Util
{
public:
Util();
static void Assert(bool bExprState) { ASSERT(bExprState); } //Assert断言
static void WriteLog(std::string logInfo); //写入日志
static void MessageBox(QWidget *parentWnd, std::string msg, std::string title = "信息"); //弹出模态消息框
static QString ToQstr(std::string str); //std::string 转 QString
static std::string ToStdStr(QString str = "默认的参数:你好2 helloworld *&……%¥#@!"); //QString 转 std::string
static bool IsEqual(double a, double b); //比较两个浮点数使否相等
static void delay(int ms); //延迟指定的ms毫秒数
static QString GetId();
static std::string Dec2Hex(int num, int width);
static std::string Byte2Hex(unsigned char* bytes, int byteLength);
static QString Img2base64(QImage& image);
static qint64 generate11DigitRandomNumber();
};
#endif // UTIL_H