blob: a47e8fb8fa5da3b6d986a7e378621632e1ed3082 [file] [log] [blame]
Krzysztof Grobelny51497a02021-11-09 14:56:22 +01001#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
12enum class ReportUpdates : uint32_t
13{
14 overwrite,
15 appendStopsWhenFull,
16 appendWrapsWhenFull,
17 newReport
18};
19
20namespace utils
21{
22
23template <>
24struct EnumTraits<ReportUpdates>
25{
26 [[noreturn]] static void throwConversionError()
27 {
28 throw sdbusplus::exception::SdBusError(
29 static_cast<int>(std::errc::invalid_argument),
30 "Invalid ReportUpdates");
31 }
32};
33
34constexpr std::array<std::pair<std::string_view, ReportUpdates>, 4>
35 convDataReportUpdates = {
36 {std::make_pair<std::string_view, ReportUpdates>(
37 "Overwrite", ReportUpdates::overwrite),
38 std::make_pair<std::string_view, ReportUpdates>(
39 "AppendStopsWhenFull", ReportUpdates::appendStopsWhenFull),
40 std::make_pair<std::string_view, ReportUpdates>(
41 "AppendWrapsWhenFull", ReportUpdates::appendWrapsWhenFull),
42 std::make_pair<std::string_view, ReportUpdates>(
43 "NewReport", ReportUpdates::newReport)}};
44
45inline ReportUpdates
46 toReportUpdates(std::underlying_type_t<ReportUpdates> value)
47{
48 return toEnum<ReportUpdates, minEnumValue(convDataReportUpdates),
49 maxEnumValue(convDataReportUpdates)>(value);
50}
51
52inline ReportUpdates toReportUpdates(const std::string& value)
53{
54 return toEnum(convDataReportUpdates, value);
55}
56
57inline std::string enumToString(ReportUpdates value)
58{
59 return std::string(enumToString(convDataReportUpdates, value));
60}
61
62} // namespace utils