Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 3 | #include "utils/conversion.hpp" |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 4 | |
| 5 | #include <string> |
| 6 | #include <tuple> |
| 7 | #include <utility> |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 8 | #include <variant> |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
| 11 | namespace discrete |
| 12 | { |
| 13 | |
| 14 | enum class Severity |
| 15 | { |
| 16 | ok = 0, |
| 17 | warning, |
| 18 | critical |
| 19 | }; |
| 20 | |
Wludzik, Jozef | 9f14591 | 2021-02-11 08:54:10 +0100 | [diff] [blame] | 21 | namespace details |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 22 | { |
Wludzik, Jozef | 9f14591 | 2021-02-11 08:54:10 +0100 | [diff] [blame] | 23 | constexpr std::array<std::pair<std::string_view, Severity>, 3> |
| 24 | convDataSeverity = {std::make_pair("Ok", Severity::ok), |
| 25 | std::make_pair("Warning", Severity::warning), |
| 26 | std::make_pair("Critical", Severity::critical)}; |
| 27 | |
| 28 | } // namespace details |
| 29 | |
| 30 | inline Severity stringToSeverity(const std::string& str) |
| 31 | { |
| 32 | return utils::stringToEnum(details::convDataSeverity, str); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 33 | } |
| 34 | |
Wludzik, Jozef | 9f14591 | 2021-02-11 08:54:10 +0100 | [diff] [blame] | 35 | inline std::string severityToString(Severity v) |
| 36 | { |
| 37 | return std::string(utils::enumToString(details::convDataSeverity, v)); |
| 38 | } |
| 39 | |
Szymon Dompke | f763c9e | 2021-03-12 09:19:22 +0100 | [diff] [blame^] | 40 | using ThresholdParam = std::tuple<std::string, std::string, uint64_t, double>; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 41 | } // namespace discrete |
| 42 | |
| 43 | namespace numeric |
| 44 | { |
| 45 | |
| 46 | enum class Type |
| 47 | { |
| 48 | lowerCritical = 0, |
| 49 | lowerWarning, |
| 50 | upperWarning, |
| 51 | upperCritical |
| 52 | }; |
| 53 | |
| 54 | enum class Direction |
| 55 | { |
| 56 | either = 0, |
| 57 | decreasing, |
| 58 | increasing |
| 59 | }; |
| 60 | |
Wludzik, Jozef | 9f14591 | 2021-02-11 08:54:10 +0100 | [diff] [blame] | 61 | namespace details |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 62 | { |
Wludzik, Jozef | 9f14591 | 2021-02-11 08:54:10 +0100 | [diff] [blame] | 63 | |
| 64 | constexpr std::array<std::pair<std::string_view, Type>, 4> convDataType = { |
| 65 | std::make_pair("LowerCritical", Type::lowerCritical), |
| 66 | std::make_pair("LowerWarning", Type::lowerWarning), |
| 67 | std::make_pair("UpperWarning", Type::upperWarning), |
| 68 | std::make_pair("UpperCritical", Type::upperCritical)}; |
| 69 | |
| 70 | constexpr std::array<std::pair<std::string_view, Direction>, 3> |
| 71 | convDataDirection = {std::make_pair("Either", Direction::either), |
| 72 | std::make_pair("Decreasing", Direction::decreasing), |
| 73 | std::make_pair("Increasing", Direction::increasing)}; |
| 74 | |
| 75 | } // namespace details |
| 76 | |
| 77 | inline Type stringToType(const std::string& str) |
| 78 | { |
| 79 | return utils::stringToEnum(details::convDataType, str); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Wludzik, Jozef | 9f14591 | 2021-02-11 08:54:10 +0100 | [diff] [blame] | 82 | inline std::string typeToString(Type v) |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 83 | { |
Wludzik, Jozef | 9f14591 | 2021-02-11 08:54:10 +0100 | [diff] [blame] | 84 | return std::string(utils::enumToString(details::convDataType, v)); |
Wludzik, Jozef | d960e1f | 2021-01-08 09:25:59 +0100 | [diff] [blame] | 85 | } |
| 86 | |
Wludzik, Jozef | 9f14591 | 2021-02-11 08:54:10 +0100 | [diff] [blame] | 87 | inline Direction stringToDirection(const std::string& str) |
| 88 | { |
| 89 | return utils::stringToEnum(details::convDataDirection, str); |
| 90 | } |
| 91 | |
| 92 | inline std::string directionToString(Direction v) |
| 93 | { |
| 94 | return std::string(utils::enumToString(details::convDataDirection, v)); |
| 95 | } |
| 96 | |
| 97 | using ThresholdParam = std::tuple<std::string, uint64_t, std::string, double>; |
Wludzik, Jozef | 76833cb | 2020-12-21 14:42:41 +0100 | [diff] [blame] | 98 | } // namespace numeric |
| 99 | |
| 100 | using TriggerThresholdParams = |
| 101 | std::variant<std::vector<numeric::ThresholdParam>, |
| 102 | std::vector<discrete::ThresholdParam>>; |