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 {
11     max,
12     min,
13     avg,
14     sum
15 };
16 
17 namespace utils
18 {
19 
20 template <>
21 struct EnumTraits<OperationType>
22 {
23     static constexpr auto propertyName = ConstexprString{"OperationType"};
24 };
25 
26 constexpr std::array<std::pair<std::string_view, OperationType>, 4>
27     convDataOperationType = {
28         {std::make_pair<std::string_view, OperationType>(
29              "xyz.openbmc_project.Telemetry.Report.OperationType.Maximum",
30              OperationType::max),
31          std::make_pair<std::string_view, OperationType>(
32              "xyz.openbmc_project.Telemetry.Report.OperationType.Minimum",
33              OperationType::min),
34          std::make_pair<std::string_view, OperationType>(
35              "xyz.openbmc_project.Telemetry.Report.OperationType.Average",
36              OperationType::avg),
37          std::make_pair<std::string_view, OperationType>(
38              "xyz.openbmc_project.Telemetry.Report.OperationType.Summation",
39              OperationType::sum)}};
40 
41 inline OperationType
toOperationType(std::underlying_type_t<OperationType> value)42     toOperationType(std::underlying_type_t<OperationType> value)
43 {
44     return toEnum<OperationType, minEnumValue(convDataOperationType),
45                   maxEnumValue(convDataOperationType)>(value);
46 }
47 
toOperationType(const std::string & value)48 inline OperationType toOperationType(const std::string& value)
49 {
50     return toEnum(convDataOperationType, value);
51 }
52 
enumToString(OperationType value)53 inline std::string enumToString(OperationType value)
54 {
55     return std::string(enumToString(convDataOperationType, value));
56 }
57 
58 } // namespace utils
59