M1M3 Support System
Loading...
Searching...
No Matches
Range.h
1/*
2 * This file is part of LSST M1M3 support system package.
3 *
4 * Developed for the Vera C. Rubin Telescope and Site System.
5 * This product includes software developed by the LSST Project
6 * (https://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef RANGE_H_
25#define RANGE_H_
26
27#include <LimitTrigger.h>
28
29#include <spdlog/fmt/fmt.h>
30#include <spdlog/spdlog.h>
31
32namespace LSST {
33namespace M1M3 {
34namespace SS {
35
39class Range {
40public:
51 template <typename T>
52 static bool InRange(T min, T max, T value) {
53 return value >= min && value <= max;
54 }
55
56 template <typename T>
57 static T CoerceIntoRange(T min, T max, T value) {
58 return (value < min) ? min : (value > max) ? max : value;
59 }
60
61 template <typename T>
62 static bool InRangeAndCoerce(T min, T max, T value, T *output) {
63 if (Range::InRange(min, max, value)) {
64 (*output) = value;
65 return true;
66 } else {
67 (*output) = Range::CoerceIntoRange(min, max, value);
68 return false;
69 }
70 }
71
86 template <typename T, typename... TArgs>
87 static bool InRangeTrigger(T min, T max, T value, LimitTrigger<TArgs...> &limitTrigger, TArgs... lArgs) {
88 bool inRange = InRange(min, max, value);
89 if (inRange == false) {
90 limitTrigger.check(lArgs...);
91 } else {
92 limitTrigger.reset();
93 }
94 return inRange;
95 }
96};
97
98} // namespace SS
99} // namespace M1M3
100} // namespace LSST
101#endif /* RANGE_H_ */
Abstract interface class for limiting some action to predefined execution.
Definition LimitTrigger.h:66
void check(TcheckArgs... args)
Should be called from code when out of bounds conditions for triggering is detected.
Definition LimitTrigger.h:77
virtual void reset()=0
Pure virtual placeholder to reset any internal variables.
Utility range checking functions.
Definition Range.h:39
static bool InRange(T min, T max, T value)
Template function to check if a value is inside a given range.
Definition Range.h:52
static bool InRangeTrigger(T min, T max, T value, LimitTrigger< TArgs... > &limitTrigger, TArgs... lArgs)
Tests if value is in given range.
Definition Range.h:87