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