#pragma once /** * @file HoldTime.h * @brief hold(n,T)变量类 * n——tag点序号(整型),T——保持时间(浮点),单位分钟 * @author your name (you@domain.com) * @version 0.1 * @date 2023-12-22 * * Copyright: Baosight Co. Ltd. * DO NOT COPY/USE WITHOUT PERMISSION * */ #include #include #include #include #include #include class HoldTime { public: std::string tagi; std::string var_name; public: /** * @brief Construct a new Hold Time object * @param time 保持的时间 * @param tagi 需要监控的变量tag * @param var_name hold变量名 */ HoldTime(double time, std::string tagi, std::string var_name); ~HoldTime(); /** * @brief static函数 检测表达式是否存在hold变量 * @param exp_str 表达式 * @return std::tuple * bool——true为存在,false为不存在 */ static std::tuple find_hold( std::string exp_str); /** * @brief 寻找包含hold变量的所有的子串 * @param str 表达式 * @param sub_str 子串集合 * @return std::vector */ static std::vector find_substr(std::string str, std::string sub_str); public: /** * @brief 刷新hold类的保持属性 * @param tag_value 最新的tag值 * @return true * @return false */ bool update_value(double tag_value); /** * @brief 重载bool运算符,返回保持状态量 */ inline operator bool(void) const { return value; } /** * @brief 获取返回状态量函数 * @return true * @return false */ inline bool get_value(void) const { return value; } private: double last_value; ///<上次tag数据值 double hold_time; ///<保持时间 bool value; ///<保持状态量 std::chrono::system_clock::time_point last_time; ///<上次为保持时间点 private: /** * @brief static函数 从源字符串中查找子字符串 * @param str 查找的源字符串 * @param sub_str 查找的目标子字符串 * @return std::pair * <存在子字符串的部分,剩下的部分> */ static std::pair find_str(std::string str, std::string sub_str); };