#pragma once #if defined(XNCORE_LIBRARY) # define XNCORE_EXPORT __attribute__((visibility("default"))) #else # define XNCORE_EXPORT __attribute__((visibility("default"))) #endif #define FORCEINLINE __attribute__((always_inline)) #ifdef __linux__ # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include # include #endif #include #include #include #include #include #include #include #include #include #define FAST_DDS_MACRO eprosima::fastdds::dds using XN_JSON = nlohmann::json; /** * @brief 默认基频定义,单位 Hz */ #define BASE_RUN_FREQ 100.0 /** * @brief 默认基础运行间隔定义 单位纳秒 */ #define BASE_RUN_INTER (1.0E9 / BASE_RUN_FREQ) //模型周期性回调函数类型别名 using XNCallBack = std::function; //DDS回调函数类型别名 using XNDDSCallBack = std::function; //事件回调函数类型别名 using XNEventCallback = std::function; /** * @brief 纳秒睡眠相关时间结构体 * @details 用于线程睡眠时间控制 */ struct PERIOD_INFO { /** * @brief 系统提供的时间记录结构体,精确到纳秒 */ timespec next_period; /** * @brief 睡眠时长,单位纳秒 */ long period_ns; }; /** * @brief 系统时间点类型别名 */ using XNTimePoint = std::chrono::system_clock::time_point; /** * @brief 系统运行状态枚举类 */ enum class RunStatus { /** * @brief 未开始 */ NotStart = 0, /** * @brief 运行中 */ Runing, /** * @brief 暂停 */ Suspend, /** * @brief 中止 */ Aborted, /** * @brief 结束 */ Finished }; /** * @brief 仿真控制命令枚举类 */ enum class SimControlCmd { /** * @brief 开始 */ Start, /** * @brief 继续 */ Continue, /** * @brief 暂停 */ Suspend, /** * @brief 中止 */ Abort }; /** * @brief 运行频率族枚举类 */ enum class FreqLevel { /** * @brief 基础频率 */ BaseFreq = 0, // 120/100/60 Hz /** * @brief 半频 */ HalfFreq, // 60/50/30 Hz /** * @brief 四分之一频 */ QuarterFreq, // 30/25/15 Hz /** * @brief 八分之一频 */ EighthFreq, // 15/12.5/7.5 Hz /** * @brief 十六分之一频 */ SixteenthFreq, // 7.5/6.25/3.75 Hz /** * @brief 三十二分之一频 */ ThirtyTwothFreq, // 3.75/3.125/1.875 Hz }; /** * @brief 框架对象状态枚举 */ enum class XNFrameObjectStatus { /** * @brief 未初始化 */ NotReady = 0, /** * @brief 已初始化 */ Initialized, /** * @brief 已准备好 */ Ready, /** * @brief 未知 */ Unknown }; template FORCEINLINE ToType XNStaticCastHelper(const FromType &from) { return std::static_pointer_cast(from); } template FORCEINLINE ToType XNCastHelper(const FromType &from) { return std::dynamic_pointer_cast(from); } #define XN_CAST(from, to) XNStaticCastHelper(from) #define XN_THISPTR std::static_pointer_cast(shared_from_this()) #define XNCLASS_PTR_DECLARE(a) \ using a##Ptr = std::shared_ptr; \ using a##WPtr = std::weak_ptr; \ using a##UPtr = std::unique_ptr; \ using a##ConsPtr = std::shared_ptr; #define XNSTRUCT_PTR_DECLARE(a) \ using a##Ptr = std::shared_ptr; \ using a##WPtr = std::weak_ptr; \ using a##UPtr = std::unique_ptr; \ using a##ConsPtr = std::shared_ptr; #define XN_NOCOPYABLE(Class) \ public: \ using NoCopyable = Class; \ \ private: \ Class(const Class &) = delete; \ Class &operator=(const Class &) = delete; #define XN_DECLARE_PRIVATE(Class) \ XN_NOCOPYABLE(Class) \ protected: \ friend class Class##Private; \ inline Class##Private *GetPP() const \ { \ return reinterpret_cast(_Private_Ptr); \ } \ using PrivateType = Class##Private; #define T_D() PrivateType *const d = GetPP() struct XNNullClass { }; #define XN_METATYPE_P(cls) \ public: \ using ThisType = cls; \ using SuperType = XNNullClass; #define XN_METATYPE(cls, sup) \ public: \ using ThisType = cls; \ using SuperType = sup; #define XN_UNUSED(x) (void)x namespace XNSim { template constexpr typename std::underlying_type::type enumValue(T e) { return static_cast::type>(e); } /** * @brief 将ISO格式的时间字符串转换为系统时间点 * @param timeStr ISO格式的时间字符串 (YYYY-MM-DDTHH:mm:ss) * @return 系统时间点 */ extern "C" XNTimePoint XNCORE_EXPORT parseISOTime(const std::string &timeStr); extern "C" std::vector XNCORE_EXPORT split(const std::string &str, const std::string &delim); extern "C" std::string XNCORE_EXPORT getFileNameWithoutExt(const std::string &path); extern "C" int XNCORE_EXPORT safe_stoi(const std::string &str, int defaultValue = 0); inline std::string getStringFromSqlite3(sqlite3_stmt *stmt, int column) { const char *text = reinterpret_cast(sqlite3_column_text(stmt, column)); if (text == nullptr) { return ""; } return std::string(text); } } // namespace XNSim