Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [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 ErrorType : uint32_t |
| 13 | { |
| 14 | propertyConflict |
| 15 | }; |
| 16 | |
| 17 | namespace utils |
| 18 | { |
| 19 | |
Krzysztof Grobelny | 62c08e9 | 2022-09-16 10:28:53 +0200 | [diff] [blame] | 20 | template <> |
| 21 | struct EnumTraits<ErrorType> |
| 22 | { |
| 23 | static constexpr auto propertyName = ConstexprString{"ErrorType"}; |
| 24 | }; |
| 25 | |
Patrick Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame^] | 26 | constexpr auto convDataErrorType = std::array{ |
| 27 | std::make_pair<std::string_view, ErrorType>("PropertyConflict", |
| 28 | ErrorType::propertyConflict)}; |
Krzysztof Grobelny | 973b4bb | 2022-04-25 17:07:27 +0200 | [diff] [blame] | 29 | |
| 30 | inline ErrorType toErrorType(std::underlying_type_t<ErrorType> value) |
| 31 | { |
| 32 | return toEnum<ErrorType, minEnumValue(convDataErrorType), |
| 33 | maxEnumValue(convDataErrorType)>(value); |
| 34 | } |
| 35 | |
| 36 | inline ErrorType toErrorType(const std::string& value) |
| 37 | { |
| 38 | return toEnum(convDataErrorType, value); |
| 39 | } |
| 40 | |
| 41 | inline std::string enumToString(ErrorType value) |
| 42 | { |
| 43 | return std::string(enumToString(convDataErrorType, value)); |
| 44 | } |
| 45 | |
| 46 | } // namespace utils |