#pragma once /** * @file ExpModule.h * @brief 表达式模块 * @author your name (you@domain.com) * @version 0.1 * @date 2025-08-20 * * Copyright: Baosight Co. Ltd. * DO NOT COPY/USE WITHOUT PERMISSION * */ #include "mix_cc/ihyper_db.h" #include "mix_cc/json.h" #include "mix_cc/matheval/matheval.hpp" #include #include #include #include #include #include #include using std::map; using std::string; using std::vector; using MExp = mix_cc::matheval::Expression; using namespace std::chrono; using std::chrono::system_clock; using TimePoint = system_clock::time_point; using TimeDur = milliseconds; class ExpModule { public: ExpModule(std::map &vars_ref, vector &m_tags, bool &is_exp_alg_ref); ~ExpModule(); ExpModule() = delete; ExpModule &operator=(const ExpModule &) = delete; /** * @brief 添加表达式 * @param exp_name 表达式名称 * @param exp_str 表达式字符串 * @return int */ int add_exp(string exp_name, string exp_str); /** * @brief 更新数据,更新表达式的值 * @return int */ int update(); void fun_reset(); /** * @brief 更新数据,更新表达式的值 通过指定数据 * @param queried_data 指定数据项 * @return int */ int update(Eigen::Matrix queried_data, std::vector queried_time, int row = 0); /** * @brief 获取表达式的值 * @param exp_name 表达式名称 * @return double */ double get_value(string exp_name); /** * @brief */ void print_value(); /** * @brief Get the exp str object * @param exp_name My Param doc * @return string */ string get_exp_str(string exp_name); private: /** * @brief 表达式变量,表达式初始化 */ void init(); /** * @brief 更新数据 共享内存 */ void refresh_exp_vars_mem(); /** * @brief 更新数据 指定数据 * @param queried_data */ void refresh_exp_ihd_mem( Eigen::Matrix queried_data, std::vector queried_time, int row); private: map &mm_vars; ///< 表达式系统变量map map exp_result_; ///<表达式计算结果 map> exp_ptr_; ///表达式名称-表达式 map exp_str_; ///<表达式名称-表达式字符串 vector &m_tags; ///< 保存的tag点名 std::unique_ptr logger_; ///<日志 TimePoint now_time_; ///< 当前正在执行时的时间 /** * @brief 自定义带状态函数 * KeepT , ///< 保持时间 * KeepC, ///<出现次数 * RiseEdge, ///<上升沿出现次数 * Detect ///<为真检测次数 */ StatExp::FunVars fun_vars_; bool &is_exp_alg_; ///<是否是表达式ExpBase对象 };