Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "utils/conversion.hpp" |
| 4 | |
| 5 | #include <array> |
| 6 | #include <cstdint> |
| 7 | #include <string_view> |
| 8 | #include <type_traits> |
| 9 | |
| 10 | enum class ReportAction : uint32_t |
| 11 | { |
| 12 | emitsReadingsUpdate, |
| 13 | logToMetricReportsCollection |
| 14 | }; |
| 15 | |
| 16 | namespace utils |
| 17 | { |
| 18 | |
| 19 | constexpr std::array<std::pair<std::string_view, ReportAction>, 2> |
| 20 | convDataReportAction = { |
| 21 | {std::make_pair<std::string_view, ReportAction>( |
| 22 | "EmitsReadingsUpdate", ReportAction::emitsReadingsUpdate), |
| 23 | std::make_pair<std::string_view, ReportAction>( |
| 24 | "LogToMetricReportsCollection", |
| 25 | ReportAction::logToMetricReportsCollection)}}; |
| 26 | |
| 27 | inline ReportAction toReportAction(std::underlying_type_t<ReportAction> value) |
| 28 | { |
| 29 | return toEnum<ReportAction, minEnumValue(convDataReportAction), |
| 30 | maxEnumValue(convDataReportAction)>(value); |
| 31 | } |
| 32 | |
| 33 | inline ReportAction toReportAction(const std::string& value) |
| 34 | { |
| 35 | return toEnum(convDataReportAction, value); |
| 36 | } |
| 37 | |
| 38 | inline std::string enumToString(ReportAction value) |
| 39 | { |
| 40 | return std::string(enumToString(convDataReportAction, value)); |
| 41 | } |
| 42 | |
| 43 | } // namespace utils |