#pragma once #include "../GlobalTypes.h" #include "Core/Base/global_include.h" #include #include #include #include extern int qInitResources_resource(); namespace asio { class io_context; } namespace YSG { struct TimerThreadPrivate; class LIB_DECL TimerThread : public QThread { Q_OBJECT public: QList mPlots; TimerThread(); ~TimerThread() override; void run() override; void post(std::function task); void postCpu(std::function task); void removePlot(Plot* plot); void shutdown(); bool isSchedulerThread() const; asio::io_context& ioContext(); private: void joinCpuPool(); void postAndWait(std::function task); void removePlotOnScheduler(Plot* plot); void shutdownOnScheduler(); void stopSchedulerOnScheduler(); std::unique_ptr d; }; class LIB_DECL Global : public QObject, public Psc::Singleton { public: int r = qInitResources_resource(); int mTimerId{}; QMap mTimerThreadMap; int mInterval = 10; void startAllTimeThread(); void timerEvent(QTimerEvent *event) override; QVector mColorMap = getTurboColorGradient(); }; } #define QLOG_POS QString(__func__) + QString(" ") + __FILE__ + QString(":") + QString::number(__LINE__) template struct has_qdebug_stream : std::false_type {}; template struct has_qdebug_stream() << std::declval() ) > > : std::true_type {}; template QString to_qstring(const T& value) { using C = std::decay_t; if constexpr (has_qdebug_stream::value) { QString s; QDebug dbg(&s); dbg << value; return s; } else { static_assert(sizeof(C) == 0, "Psc: to_qstring type error"); } return ""; } // // 通用模板 // template // QString to_qstring(const T& value) { // static_assert(std::is_arithmetic::value, "T must be an arithmetic type"); // return QString::number(value); // } // // inline QString to_qstring(const char* value) { // return value; // } // // inline QString to_qstring(const QString& value) { // return value; // } // 特化模板:处理 bool 类型 template <> inline QString to_qstring(const bool& value) { return value ? QStringLiteral("true") : QStringLiteral("false"); } #define VAR_QSTR(P) ("[" + to_qstring(#P) + "]:" + to_qstring(P) + to_qstring(", ")) #define VAR_QSTR_1(P1) VAR_QSTR(P1) #define VAR_QSTR_2(P1, P2) VAR_QSTR_1(P1) + VAR_QSTR(P2) #define VAR_QSTR_3(P1, P2, P3) VAR_QSTR_2(P1, P2) + VAR_QSTR(P3) #define VAR_QSTR_4(P1, P2, P3, P4) VAR_QSTR_3(P1, P2, P3) + VAR_QSTR(P4) #define VAR_QSTR_5(P1, P2, P3, P4, P5) VAR_QSTR_4(P1, P2, P3, P4) + VAR_QSTR(P5) #define VAR_QSTR_6(P1, P2, P3, P4, P5, P6) VAR_QSTR_5(P1, P2, P3, P4, P5) + VAR_QSTR(P6) #define VAR_QSTR_7(P1, P2, P3, P4, P5, P6, P7) VAR_QSTR_6(P1, P2, P3, P4, P5, P6) + VAR_QSTR(P7) #define VAR_QSTR_8(P1, P2, P3, P4, P5, P6, P7, P8) VAR_QSTR_7(P1, P2, P3, P4, P5, P6, P7) + VAR_QSTR(P8) #define VAR_QSTR_9(P1, P2, P3, P4, P5, P6, P7, P8, P9) VAR_QSTR_8(P1, P2, P3, P4, P5, P6, P7, P8) + VAR_QSTR(P9) #define VAR_QSTR_10(P1, P2, P3, P4, P5, P6, P7, P8, P9, P10) VAR_QSTR_9(P1, P2, P3, P4, P5, P6, P7, P8, P9) + VAR_QSTR(P10)