eis/eqpalg/utility/bound_checker.h
Huamonarch b9cf5f4e9e refactor: 提取 BoundChecker 上下限检测组件
从 ExpBase 提取 detect_up_down() 逻辑和哨兵值处理至独立的 BoundChecker 类。
将 DetectMode 从 struct 升级为 enum class。
2026-05-15 14:09:56 +08:00

57 lines
1.4 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// eqpalg/utility/bound_checker.h
#pragma once
#include <string>
/**
* @brief 检测模式:双侧、仅左侧、仅右侧
*/
enum class DetectMode {
Default = 0, // 双侧检测 (value < down || value > up)
OnlyLeft = 1, // 仅检测左边界 (value < down)
OnlyRight = 2, // 仅检测右边界 (value > up)
ErrorMode = 3 // 错误模式
};
/**
* @brief 上下限检测器
*
* 从 ExpBase 提取,封装哨兵值 -32768/32767 的处理逻辑。
*/
class BoundChecker {
public:
BoundChecker() = default;
/**
* @brief 设置上下限,自动推导检测模式
* @param down 下限(-32768 表示无下限)
* @param up 上限32767/32768 表示无上限)
*/
void setLimits(double down, double up);
/**
* @brief 手动设置检测模式(覆盖自动推导)
*/
void setDetectMode(DetectMode mode) { detect_mode_ = mode; }
/**
* @brief 判断 value 是否超出限值
*/
bool isOutOfBounds(double value) const;
// 访问器
double limitDown() const { return limit_down_; }
double limitUp() const { return limit_up_; }
DetectMode detectMode() const { return detect_mode_; }
/**
* @brief 是否已配置有效限值
*/
bool isValid() const { return detect_mode_ != DetectMode::ErrorMode; }
private:
double limit_down_ = -32768;
double limit_up_ = -32768;
DetectMode detect_mode_ = DetectMode::Default;
};