Go to the documentation of this file. 15 #ifndef SHAKA_EMBEDDED_UTIL_MACROS_H_ 16 #define SHAKA_EMBEDDED_UTIL_MACROS_H_ 18 #include <glog/logging.h> 25 #define LOG_ONCE(severity) LOG_FIRST_N(severity, 1) 29 # define PRINTF_FORMAT(format_arg, dots_arg) \ 30 __attribute__((format(printf, format_arg, dots_arg))) 31 # define NO_SANITIZE(name) __attribute__((no_sanitize(name))) 32 # define FALL_THROUGH_INTENDED [[clang::fallthrough]] // NOLINT 33 # define BEGIN_ALLOW_COMPLEX_STATICS \ 34 _Pragma("clang diagnostic push") \ 35 _Pragma("clang diagnostic ignored \"-Wexit-time-destructors\"") \ 36 _Pragma("clang diagnostic ignored \"-Wglobal-constructors\"") 37 # define END_ALLOW_COMPLEX_STATICS _Pragma("clang diagnostic pop") 39 # define PRINTF_FORMAT(format, dots) 40 # define NO_SANITIZE(name) 41 # define FALL_THROUGH_INTENDED 42 # define BEGIN_ALLOW_COMPLEX_STATICS 43 # define END_ALLOW_COMPLEX_STATICS 47 # define MUST_USE_RESULT __attribute__((warn_unused_result)) 48 #elif defined(_MSC_VER) && _MSC_VER >= 1700 50 # define MUST_USE_RESULT _Check_return_ 52 # define MUST_USE_RESULT 60 #define DEFINE_ENUM_AND_TO_STRING_GENERIC_(Type, DEFINE_ENUM, ENUM_IMPL, \ 62 enum class Type { DEFINE_ENUM(ENUM_IMPL) }; \ 63 inline std::string to_string(Type e) noexcept { \ 66 DEFINE_ENUM(CASE_IMPL) \ 68 LOG(FATAL) << "Unknown enum value " << static_cast<int>(e); \ 71 inline std::ostream& operator<<(std::ostream& os, Type e) { \ 72 return os << to_string(e); \ 75 #define DEFINE_ENUM_IMPL_(name) name, 76 #define DEFINE_CASE_IMPL_(name) case Enum::name: return #name; 89 #define DEFINE_ENUM_AND_TO_STRING(Type, DEFINE_ENUM) \ 90 DEFINE_ENUM_AND_TO_STRING_GENERIC_(Type, DEFINE_ENUM, DEFINE_ENUM_IMPL_, \ 93 #define DEFINE_ENUM_IMPL_2_(name, str) name, 94 #define DEFINE_CASE_IMPL_2_(name, str) case Enum::name: return str; 107 #define DEFINE_ENUM_AND_TO_STRING_2(Type, DEFINE_ENUM) \ 108 DEFINE_ENUM_AND_TO_STRING_GENERIC_(Type, DEFINE_ENUM, DEFINE_ENUM_IMPL_2_, \ 111 #endif // SHAKA_EMBEDDED_UTIL_MACROS_H_