#ifndef BLUE_CORE_MISC_H_ #define BLUE_CORE_MISC_H_ #include #include #ifndef _Nonnull #define _Nonnull #endif #define B_NPOS ((size_t)-1) #define b_min(type, x, y) (z__b_min_##type(x, y)) #define b_max(type, x, y) (z__b_max_##type(x, y)) #define b_unbox(type, box, member) \ ((type *_Nonnull)((box) ? (uintptr_t)(box) - (offsetof(type, member)) : 0)) #define z__b_merge_(a, b) a##b #define z__b_label_(a) z__b_merge_(__unique_name_, a) #define z__b_unique_name() z__b_label_(__LINE__) #define z__b_numargs(arg_type, ...) \ (sizeof((arg_type[]) {__VA_ARGS__}) / sizeof(arg_type)) #ifdef _MSC_VER #ifdef BLUELIB_STATIC #define BLUE_API extern #else #ifdef BLUELIB_EXPORT #define BLUE_API extern __declspec(dllexport) #else #define BLUE_API extern __declspec(dllimport) #endif #endif #else #define BLUE_API extern #endif static inline char z__b_min_char(char x, char y) { return x < y ? x : y; } static inline unsigned char z__b_min_uchar(unsigned char x, unsigned char y) { return x < y ? x : y; } static inline int z__b_min_int(int x, int y) { return x < y ? x : y; } static inline unsigned int z__b_min_uint(unsigned int x, unsigned int y) { return x < y ? x : y; } static inline long z__b_min_long(long x, long y) { return x < y ? x : y; } static inline unsigned int z__b_min_ulong(unsigned long x, unsigned long y) { return x < y ? x : y; } static inline long long z__b_min_longlong(long long x, long long y) { return x < y ? x : y; } static inline unsigned long long z__b_min_ulonglong( unsigned long long x, unsigned long long y) { return x < y ? x : y; } static inline size_t z__b_min_size_t(size_t x, size_t y) { return x < y ? x : y; } static inline char z__b_max_char(char x, char y) { return x > y ? x : y; } static inline unsigned char z__b_max_uchar(unsigned char x, unsigned char y) { return x > y ? x : y; } static inline int z__b_max_int(int x, int y) { return x > y ? x : y; } static inline unsigned int z__b_max_uint(unsigned int x, unsigned int y) { return x > y ? x : y; } static inline long z__b_max_long(long x, long y) { return x > y ? x : y; } static inline unsigned int z__b_max_ulong(unsigned long x, unsigned long y) { return x > y ? x : y; } static inline long long z__b_max_longlong(long long x, long long y) { return x > y ? x : y; } static inline unsigned long long z__b_max_ulonglong( unsigned long long x, unsigned long long y) { return x > y ? x : y; } static inline size_t z__b_max_size_t(size_t x, size_t y) { return x > y ? x : y; } BLUE_API size_t b_int_length(intptr_t v); BLUE_API size_t b_uint_length(uintptr_t v); #endif // BLUE_CORE_MISC_H_