12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- //
- #pragma once
- #include <assert.h>
- #include <vector>
- #include <functional>
- //-----------------------------------------------------------------------------
- // TmplMould
- //-----------------------------------------------------------------------------
- namespace DIOS::Dev::Detail
- {
- template <typename T>
- class TmplMould
- {
- public:
- TmplMould (T init, T min, T max, T accuracy)
- {
- m_Value = init;
- m_LimitMin = min;
- m_LimitMax = max;
- m_Accuracy = accuracy;
- assert (m_LimitMin < m_LimitMax);
- }
- public:
- bool CanInc () const; // 能加 1 吗
- bool CanDec () const; // 能减 1 吗
- bool Verify (T value) const; // 值在界限内吗
- bool Inc (); // 加 1
- bool Dec (); // 减 1
- bool Update (T value); // 更新为指定值
- bool UpdateLimitMax(T value); // 更新为指定值
- bool UpdateLimitMin(T value); // 更新为指定值
- T Get () const; // 获得当前值
- T GetLimitMax() const;
- T GetLimitMin() const;
- bool ToNext (const std::vector <typename T> & ar);
- bool ToPrev (const std::vector <typename T> & ar);
- bool ToUpdate (T value, const std::vector <typename T> & ar);
- //change by wxx for 万东:丰富基类方法(要求ar按从小到大排列) 20230803
- bool CanToNext(T & value, const std::vector <typename T>& ar);
- bool CanToPrev(T & value, const std::vector <typename T>& ar);
- bool CanToUpdate(T & value, const std::vector <typename T>& ar);
- protected:
- T m_LimitMin;
- T m_LimitMax;
- T m_Accuracy;
- T m_Value;
- };
- template <typename T>
- class TmplMouldWithWarn : public TmplMould <T>
- {
- protected:
- T m_WarningMin;
- T m_WarningMax;
- T m_CalibWarningMin;
- T m_CalibWarningMax;
- T m_ErrorMin;
- T m_ErrorMax;
- public:
- std::function <void ()> m_OnWarningMin;
- std::function <void ()> m_OnWarningMax;
- std::function <void ()> m_OnCalibWarningMin;
- std::function <void ()> m_OnCalibWarningMax;
- std::function <void ()> m_OnErrorMin;
- std::function <void ()> m_OnErrorMax;
- public:
- using super = TmplMould;
- TmplMouldWithWarn(T init, T min, T WarnMin, T WarnMax, T CalibWarnMin, T CalibWarnMax, T max, T accuracy)
- :super(init, min, max, accuracy)
- {
- m_WarningMin = WarnMin;
- m_WarningMax = WarnMax;
- m_CalibWarningMin = CalibWarnMin;
- m_CalibWarningMax = CalibWarnMax;
- m_ErrorMin = min;
- m_ErrorMax = max;
- assert(m_CalibWarningMin < m_CalibWarningMax);
- assert(m_ErrorMin < m_ErrorMax);
- assert(m_ErrorMin < m_ErrorMax);
- }
- };
- }
|