Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "utils/conversion.hpp" |
| 4 | |
| 5 | #include <array> |
| 6 | #include <cstdint> |
| 7 | #include <string_view> |
| 8 | |
| 9 | enum class OperationType : uint32_t |
| 10 | { |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 11 | max, |
| 12 | min, |
| 13 | avg, |
| 14 | sum |
| 15 | }; |
| 16 | |
| 17 | namespace utils |
| 18 | { |
| 19 | |
Krzysztof Grobelny | 60fee07 | 2022-01-13 16:25:04 +0100 | [diff] [blame] | 20 | constexpr std::array<std::pair<std::string_view, OperationType>, 4> |
| 21 | convDataOperationType = {{std::make_pair<std::string_view, OperationType>( |
| 22 | "Maximum", OperationType::max), |
| 23 | std::make_pair<std::string_view, OperationType>( |
| 24 | "Minimum", OperationType::min), |
| 25 | std::make_pair<std::string_view, OperationType>( |
| 26 | "Average", OperationType::avg), |
| 27 | std::make_pair<std::string_view, OperationType>( |
| 28 | "Summation", OperationType::sum)}}; |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 29 | |
| 30 | inline OperationType |
| 31 | toOperationType(std::underlying_type_t<OperationType> value) |
| 32 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 33 | return toEnum<OperationType, minEnumValue(convDataOperationType), |
| 34 | maxEnumValue(convDataOperationType)>(value); |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 37 | inline OperationType toOperationType(const std::string& value) |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 38 | { |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 39 | return toEnum(convDataOperationType, value); |
Krzysztof Grobelny | e8fc575 | 2021-02-05 14:30:45 +0000 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | inline std::string enumToString(OperationType value) |
| 43 | { |
| 44 | return std::string(enumToString(convDataOperationType, value)); |
| 45 | } |
| 46 | |
| 47 | } // namespace utils |