1/*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16// Autogenerated file -- DO NOT EDIT!
17% component = Messages.component.upcase
18#ifndef PANDA_<%= component %>_MESSAGES_GEN_H_
19#define PANDA_<%= component %>_MESSAGES_GEN_H_
20
21#include "utils/logger.h"
22#include <string_view>
23
24namespace <%= Messages.namespace %> {
25%   msg_nums = Messages.messages.map(&:number)
26%   msg_first = msg_nums.min
27%   msg_last = msg_nums.max
28    enum class <%= Messages.enum_name %> : size_t {
29        FIRST = <%= msg_first %>,
30% Messages.messages.each do |msg|
31        <%= msg.name %> = <%= msg.number %>,
32% end
33        LAST = <%= msg_last %>,
34        __UNDEFINED__
35    };
36}  // namespace <%= Messages.namespace %>
37
38% Messages.messages.each do |msg|
39// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
40#define <%= msg.macro_name %>(<%= msg.args %>) \
41% level = msg.level.upcase
42% if level != 'DEBUG'
43    LOG(<%= level %>, <%= component %>) << <%= msg.stream_ops(true) %>; \
44% end
45% if msg.message  # may be nil if short message is enough
46    LOG(DEBUG, <%= component %>) << <%= msg.stream_ops(false) %>;
47% end
48
49% end
50
51namespace <%= Messages.namespace %> {
52
53inline std::string_view <%= Messages.enum_name %>ToString(<%= Messages.enum_name %> num) {
54% Messages.messages.each do |msg|
55    if (num == <%= Messages.enum_name %>::<%= msg.name %>) { return "<%= msg.name %>"; }
56% end
57    return "<unknown>";
58}
59
60inline bool <%= Messages.enum_name %>IsValid(<%= Messages.enum_name %> num) {
61    switch(num) {
62% Messages.messages.each do |msg|
63        case <%= Messages.enum_name %>::<%= msg.name %>: return true;
64% end
65        default: return false;
66    }
67}
68
69inline <%= Messages.enum_name %> StringTo<%= Messages.enum_name %>(std::string_view str) {
70% Messages.messages.each do |msg|
71    if (str == "<%= msg.name %>") { return <%= Messages.enum_name %>::<%= msg.name %>; }
72% end
73    if (str == "FIRST") { return <%= Messages.enum_name %>::FIRST; }
74    if (str == "LAST") { return <%= Messages.enum_name %>::LAST; }
75    return <%= Messages.enum_name %>::__UNDEFINED__;
76}
77
78}  // namespace <%= Messages.namespace %>
79
80#endif  // PANDA_<%= component %>_MESSAGES_GEN_H_
81