-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdump_types.mako.hpp
123 lines (109 loc) · 3.79 KB
/
dump_types.mako.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
## This file is a template. The comment below is emitted
## into the rendered file; feel free to edit this file.
// !!! WARNING: This is a GENERATED Code..Please do NOT Edit !!!
#pragma once
#include <optional>
#include <ranges>
#include <string>
#include <unordered_map>
#include <vector>
namespace phosphor
{
namespace dump
{
// Overall dump category for example BMC dump
using DUMP_CATEGORY = std::string;
// Dump type
using DUMP_TYPE = std::string;
// Dump collection indicator
using DUMP_COLLECTION_TYPE = std::string;
using ErrorType = std::string;
using Error = std::string;
using ErrorList = std::vector<Error>;
using ErrorMap = std::unordered_map<ErrorType, ErrorList>;
// Dump types
<% enum_values = set() %>
enum class DumpTypes {
% for item in DUMP_TYPE_TABLE:
% for key, values in item.items():
% if values[0].upper() not in enum_values:
${values[0].upper()},
<% enum_values.add(values[0].upper()) %>
% endif
% endfor
% endfor
% for key in ERROR_TYPE_DICT:
% if key.upper() not in enum_values:
${key.upper()},
<% enum_values.add(key.upper()) %>
% endif
% endfor
};
// A table of dump types
using DUMP_TYPE_TABLE =
std::unordered_map<DUMP_TYPE, std::pair<DumpTypes, DUMP_CATEGORY>>;
// Mapping between dump type and dump collection type string
using DUMP_TYPE_TO_STRING_MAP =
std::unordered_map<DumpTypes, DUMP_COLLECTION_TYPE>;
/**
* @brief Converts a DumpTypes enum value to dump name.
*
* @param[in] dumpType The DumpTypes value to be converted.
* @return Name of the dump as string, std::nullopt if not found.
*/
std::optional<std::string> dumpTypeToString(const DumpTypes& dumpType);
/**
* @brief Converts dump name to its corresponding DumpTypes enum value.
*
* @param[in] str The string to be converted to a DumpTypes value.
* @return The DumpTypes value that corresponds to the name or std::nullopt if
* not found.
*/
std::optional<DumpTypes> stringToDumpType(const std::string& str);
/**
* @brief Validates dump type and returns corresponding collection type
*
* This function checks the provided dump type against the specified category.
* If the dump type is empty, it defaults to "user". If the dump type does not
* exist or does not match with the specified category, it logs an error and
* throws an InvalidArgument exception.
*
* @param[in] type - The dump type to be validated.
* @param[in] category - The category to match against the dump type.
*
* @return The corresponding dump collection type if the dump type and category
* match an entry in the dumpTypeTable. If the type is empty or does not match
* any entry, it returns "user".
*
* @throws InvalidArgument - Thrown if the type does not match the specified
* category or does not exist in the table.
*/
DumpTypes validateDumpType(const std::string& type,
const std::string& category);
/**
* @brief Checks if the provided error type is valid.
*
* This function verifies the validity of the error type by checking if it
* exists in the error map.
*
* @param[in] errorType - The string representation of the error type to
* validate.
*
* @return True if the error type exists in the error map, False otherwise.
*/
bool isErrorTypeValid(const std::string& errorType);
/**
* @brief Finds the error type based on the provided error string.
*
* This function searches the error map for the provided error string.
* If it finds the string in the list of errors for a specific error type,
* it returns that error type.
*
* @param[in] errString - The string representation of the error to search for.
*
* @return An optional containing the error type if found. If the error string
* is not found in the map, returns an empty optional.
*/
std::optional<ErrorType> findErrorType(const std::string& errString);
} // namespace dump
} // namespace phosphor