/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ // Autogenerated file -- DO NOT EDIT! % component = Messages.component.upcase #ifndef PANDA_<%= component %>_MESSAGES_GEN_H_ #define PANDA_<%= component %>_MESSAGES_GEN_H_ #include "utils/logger.h" namespace <%= Messages.namespace %> { % msg_nums = Messages.messages.map(&:number) % msg_first = msg_nums.min % msg_last = msg_nums.max enum class <%= Messages.enum_name %> : size_t { FIRST = <%= msg_first %>, % Messages.messages.each do |msg| <%= msg.name %> = <%= msg.number %>, % end LAST = <%= msg_last %>, __UNDEFINED__ }; } // namespace <%= Messages.namespace %> % Messages.messages.each do |msg| // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define <%= msg.macro_name %>(<%= msg.args %>) \ % level = msg.level.upcase % if level != 'DEBUG' LOG(<%= level %>, <%= component %>) << <%= msg.stream_ops(true) %>; \ % end % if msg.message # may be nil if short message is enough LOG(DEBUG, <%= component %>) << <%= msg.stream_ops(false) %>; % end % end namespace <%= Messages.namespace %> { template Str <%= Messages.enum_name %>ToString (<%= Messages.enum_name %> num) { % Messages.messages.each do |msg| static const char <%= msg.name %>_str[] = "<%= msg.name %>"; % end static const char UNKNOWN[] = ""; % Messages.messages.each do |msg| if (num == <%= Messages.enum_name %>::<%= msg.name %>) { return Str{<%= msg.name %>_str}; } % end return {UNKNOWN}; } template bool <%= Messages.enum_name %>IsValid (<%= Messages.enum_name %> num) { switch(num) { % Messages.messages.each do |msg| case <%= Messages.enum_name %>::<%= msg.name %>: return true; % end default: return false; } return false; } template <%= Messages.enum_name %> StringTo<%= Messages.enum_name %>(const Str& str) { static const char FIRST_str[] = "FIRST"; static const char LAST_str[] = "LAST"; % Messages.messages.each do |msg| static const char <%= msg.name %>_str[] = "<%= msg.name %>"; % end % Messages.messages.each do |msg| if (str == Str{<%= msg.name %>_str}) { return <%= Messages.enum_name %>::<%= msg.name %>; } % end if (str == Str{FIRST_str}) { return <%= Messages.enum_name %>::FIRST; } if (str == Str{LAST_str}) { return <%= Messages.enum_name %>::LAST; } return <%= Messages.enum_name %>::__UNDEFINED__; } } // namespace <%= Messages.namespace %> #endif // PANDA_<%= component %>_MESSAGES_GEN_H_