123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #pragma once
- #include <stdint.h>
- #include <stdlib.h>
- #define PACKED __attribute__((__packed__))
- #define WEAK __attribute__((__weak__))
- #define UNUSED_FUNCTION __attribute__((unused))
- #define OPTIMIZE(level) __attribute__((optimize(level)))
- #define NOINLINE __attribute__((noinline))
- #define FMT_PRINTF(a,b) __attribute__((format(printf, a, b)))
- #define FMT_SCANF(a,b) __attribute__((format(scanf, a, b)))
- #ifdef __has_cpp_attribute
- # if __has_cpp_attribute(fallthrough)
- # define FALLTHROUGH [[fallthrough]]
- # elif __has_cpp_attribute(gnu::fallthrough)
- # define FALLTHROUGH [[gnu::fallthrough]]
- # endif
- #endif
- #ifndef FALLTHROUGH
- # define FALLTHROUGH
- #endif
- #ifdef __GNUC__
- #define WARN_IF_UNUSED __attribute__ ((warn_unused_result))
- #else
- #define WARN_IF_UNUSED
- #endif
- #define NORETURN __attribute__ ((noreturn))
- #define ToRad(x) radians(x)
- #define ToDeg(x) degrees(x)
- #define DEFINE_BYTE_ARRAY_METHODS \
- inline uint8_t &operator[](size_t i) { return reinterpret_cast<uint8_t *>(this)[i]; } \
- inline uint8_t operator[](size_t i) const { return reinterpret_cast<const uint8_t *>(this)[i]; }
- #define BIT_IS_SET(value, bitnumber) (((value) & (1U<<(bitnumber))) != 0)
- #define LOWBYTE(i) ((uint8_t)(i))
- #define HIGHBYTE(i) ((uint8_t)(((uint16_t)(i))>>8))
- #define ARRAY_SIZE(_arr) (sizeof(_arr) / sizeof(_arr[0]))
- #define UINT16_VALUE(hbyte, lbyte) (static_cast<uint16_t>((hbyte<<8)|lbyte))
- #define _UNUSED_RESULT(uniq_, expr_) \
- do { \
- decltype(expr_) uniq_ __attribute__((unused)); \
- uniq_ = expr_; \
- } while (0)
- #define UNUSED_RESULT(expr_) _UNUSED_RESULT(__unique_name_##__COUNTER__, expr_)
- template<typename s, size_t s_size, size_t t> struct _assert_storage_size {
- static_assert(s_size == t, "wrong size");
- };
- template<typename s, size_t t> struct assert_storage_size {
- _assert_storage_size<s, sizeof(s), t> _member;
- };
- bool is_bounded_int32(int32_t value, int32_t lower_bound, int32_t upper_bound);
- bool hex_to_uint8(uint8_t a, uint8_t &res);
|