Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "interfaces/json_storage.hpp" |
Krzysztof Grobelny | dcc4e19 | 2021-03-08 09:09:34 +0000 | [diff] [blame] | 4 | #include "types/trigger_types.hpp" |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 5 | |
| 6 | namespace utils |
| 7 | { |
| 8 | |
| 9 | class ToLabeledThresholdParamConversion |
| 10 | { |
| 11 | public: |
| 12 | LabeledTriggerThresholdParams operator()(const std::monostate& arg) const; |
| 13 | LabeledTriggerThresholdParams |
| 14 | operator()(const std::vector<numeric::ThresholdParam>& arg) const; |
| 15 | LabeledTriggerThresholdParams |
| 16 | operator()(const std::vector<discrete::ThresholdParam>& arg) const; |
| 17 | }; |
| 18 | |
| 19 | class FromLabeledThresholdParamConversion |
| 20 | { |
| 21 | public: |
| 22 | TriggerThresholdParams operator()( |
| 23 | const std::vector<numeric::LabeledThresholdParam>& arg) const; |
| 24 | TriggerThresholdParams operator()( |
| 25 | const std::vector<discrete::LabeledThresholdParam>& arg) const; |
| 26 | }; |
| 27 | |
| 28 | SensorsInfo fromLabeledSensorsInfo(const std::vector<LabeledSensorInfo>& infos); |
| 29 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 30 | TriggerThresholdParams |
| 31 | fromLabeledThresholdParam(const std::vector<LabeledThresholdParam>& params); |
| 32 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 33 | nlohmann::json labeledThresholdParamsToJson( |
| 34 | const LabeledTriggerThresholdParams& labeledThresholdParams); |
| 35 | |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 36 | template <typename T> |
| 37 | struct is_variant : std::false_type |
| 38 | {}; |
| 39 | |
| 40 | template <typename... Args> |
| 41 | struct is_variant<std::variant<Args...>> : std::true_type |
| 42 | {}; |
| 43 | |
| 44 | template <typename T> |
| 45 | inline constexpr bool is_variant_v = is_variant<T>::value; |
| 46 | |
| 47 | template <typename AlternativeT, typename VariantT> |
Szymon Dompke | 7e114c0 | 2022-10-13 18:15:23 +0200 | [diff] [blame] | 48 | requires is_variant_v<VariantT> bool |
| 49 | isFirstElementOfType(const std::vector<VariantT>& collection) |
Szymon Dompke | 94f71c5 | 2021-12-10 07:16:33 +0100 | [diff] [blame] | 50 | { |
| 51 | if (collection.empty()) |
| 52 | { |
| 53 | return false; |
| 54 | } |
| 55 | return std::holds_alternative<AlternativeT>(*collection.begin()); |
| 56 | } |
| 57 | |
Szymon Dompke | aa57236 | 2022-03-23 16:31:24 +0100 | [diff] [blame] | 58 | double stodStrict(const std::string& str); |
| 59 | |
Cezary Zwolak | 4416fce | 2021-03-17 03:21:06 +0100 | [diff] [blame] | 60 | } // namespace utils |