• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2021 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
23namespace <%= Messages.namespace %> {
24%   msg_nums = Messages.messages.map(&:number)
25%   msg_first = msg_nums.min
26%   msg_last = msg_nums.max
27    enum class <%= Messages.enum_name %> : size_t {
28        FIRST = <%= msg_first %>,
29% Messages.messages.each do |msg|
30        <%= msg.name %> = <%= msg.number %>,
31% end
32        LAST = <%= msg_last %>,
33        __UNDEFINED__
34    };
35}  // namespace <%= Messages.namespace %>
36
37% Messages.messages.each do |msg|
38// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
39#define <%= msg.macro_name %>(<%= msg.args %>) \
40% level = msg.level.upcase
41% if level != 'DEBUG'
42    LOG(<%= level %>, <%= component %>) << <%= msg.stream_ops(true) %>; \
43% end
44% if msg.message  # may be nil if short message is enough
45    LOG(DEBUG, <%= component %>) << <%= msg.stream_ops(false) %>;
46% end
47
48% end
49
50namespace <%= Messages.namespace %> {
51
52template<typename Str>
53Str <%= Messages.enum_name %>ToString (<%= Messages.enum_name %> num) {
54% Messages.messages.each do |msg|
55    static const char <%= msg.name %>_str[] = "<%= msg.name %>";
56% end
57    static const char UNKNOWN[] = "<unknown>";
58% Messages.messages.each do |msg|
59    if (num == <%= Messages.enum_name %>::<%= msg.name %>) { return Str{<%= msg.name %>_str}; }
60% end
61    return {UNKNOWN};
62}
63
64template<typename...>
65bool <%= Messages.enum_name %>IsValid (<%= Messages.enum_name %> num) {
66    switch(num) {
67% Messages.messages.each do |msg|
68        case <%= Messages.enum_name %>::<%= msg.name %>: return true;
69% end
70        default: return false;
71    }
72    return false;
73}
74
75template<typename Str>
76<%= Messages.enum_name %> StringTo<%= Messages.enum_name %>(const Str& str) {
77    static const char FIRST_str[] = "FIRST";
78    static const char LAST_str[] = "LAST";
79% Messages.messages.each do |msg|
80    static const char <%= msg.name %>_str[] = "<%= msg.name %>";
81% end
82% Messages.messages.each do |msg|
83    if (str == Str{<%= msg.name %>_str}) { return <%= Messages.enum_name %>::<%= msg.name %>; }
84% end
85    if (str == Str{FIRST_str}) { return <%= Messages.enum_name %>::FIRST; }
86    if (str == Str{LAST_str}) { return <%= Messages.enum_name %>::LAST; }
87    return <%= Messages.enum_name %>::__UNDEFINED__;
88}
89
90}  // namespace <%= Messages.namespace %>
91
92#endif  // PANDA_<%= component %>_MESSAGES_GEN_H_
93