Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "utils/conversion.hpp" |
| 4 | |
| 5 | #include <sdbusplus/exception.hpp> |
| 6 | |
| 7 | #include <array> |
| 8 | #include <cstdint> |
| 9 | #include <string_view> |
| 10 | #include <type_traits> |
| 11 | |
| 12 | enum class ReportingType : uint32_t |
| 13 | { |
| 14 | periodic, |
| 15 | onRequest, |
| 16 | onChange |
| 17 | }; |
| 18 | |
| 19 | namespace utils |
| 20 | { |
| 21 | |
| 22 | template <> |
| 23 | struct EnumTraits<ReportingType> |
| 24 | { |
Krzysztof Grobelny | 62c08e9 | 2022-09-16 10:28:53 +0200 | [diff] [blame] | 25 | static constexpr auto propertyName = ConstexprString{"ReportingType"}; |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 26 | }; |
| 27 | |
| 28 | constexpr std::array<std::pair<std::string_view, ReportingType>, 3> |
| 29 | convDataReportingType = {{std::make_pair<std::string_view, ReportingType>( |
| 30 | "Periodic", ReportingType::periodic), |
| 31 | std::make_pair<std::string_view, ReportingType>( |
| 32 | "OnRequest", ReportingType::onRequest), |
| 33 | std::make_pair<std::string_view, ReportingType>( |
| 34 | "OnChange", ReportingType::onChange)}}; |
| 35 | |
| 36 | inline ReportingType |
| 37 | toReportingType(std::underlying_type_t<ReportingType> value) |
| 38 | { |
| 39 | return toEnum<ReportingType, minEnumValue(convDataReportingType), |
| 40 | maxEnumValue(convDataReportingType)>(value); |
| 41 | } |
| 42 | |
| 43 | inline ReportingType toReportingType(const std::string& value) |
| 44 | { |
| 45 | return toEnum(convDataReportingType, value); |
| 46 | } |
| 47 | |
| 48 | inline std::string enumToString(ReportingType value) |
| 49 | { |
| 50 | return std::string(enumToString(convDataReportingType, value)); |
| 51 | } |
| 52 | |
| 53 | } // namespace utils |