20 #ifndef OBJFW_MACROS_H
21 #define OBJFW_MACROS_H
23 #include "objfw-defs.h"
25 #ifndef __STDC_LIMIT_MACROS
26 # define __STDC_LIMIT_MACROS
28 #ifndef __STDC_CONSTANT_MACROS
29 # define __STDC_CONSTANT_MACROS
46 #ifdef OF_OBJFW_RUNTIME
47 # ifdef OF_COMPILING_OBJFW
50 # include <ObjFWRT/ObjFWRT.h>
53 #ifdef OF_APPLE_RUNTIME
54 # include <objc/objc.h>
55 # include <objc/runtime.h>
56 # include <objc/message.h>
60 # define restrict __restrict__
61 #elif __STDC_VERSION__ < 199901L
65 #if __STDC_VERSION__ >= 201112L && !defined(static_assert)
67 # define static_assert _Static_assert
70 #if defined(OF_HAVE__THREAD_LOCAL)
71 # define OF_HAVE_COMPILER_TLS
72 # ifdef OF_HAVE_THREADS_H
77 # define thread_local _Thread_local
80 # define thread_local _Thread_local
82 #elif defined(OF_HAVE___THREAD)
83 # define OF_HAVE_COMPILER_TLS
84 # define thread_local __thread
91 #if defined(OF_HAVE_COMPILER_TLS) && defined(OF_IOS) && defined(OF_X86)
92 # undef OF_HAVE_COMPILER_TLS
96 # define OF_INLINE inline __attribute__((__always_inline__))
97 # define OF_LIKELY(cond) (__builtin_expect(!!(cond), 1))
98 # define OF_UNLIKELY(cond) (__builtin_expect(!!(cond), 0))
99 # define OF_CONST_FUNC __attribute__((__const__))
100 # define OF_NO_RETURN_FUNC __attribute__((__noreturn__))
101 # define OF_WEAK_REF(sym) __attribute__((__weakref__(sym)))
102 # if defined(OF_ELF) || defined(OF_MACHO)
103 # define OF_VISIBILITY_HIDDEN __attribute__((__visibility__("hidden")))
104 # define OF_VISIBILITY_INTERNAL __attribute__((__visibility__("internal")))
106 # define OF_VISIBILITY_HIDDEN
107 # define OF_VISIBILITY_INTERNAL
109 # define OF_MALLOC_FUNC __attribute__((__malloc__))
111 # define OF_INLINE inline
112 # define OF_LIKELY(cond) (cond)
113 # define OF_UNLIKELY(cond) (cond)
114 # define OF_CONST_FUNC
115 # define OF_NO_RETURN_FUNC
116 # define OF_WEAK_REF(sym)
117 # define OF_VISIBILITY_HIDDEN
118 # define OF_VISIBILITY_INTERNAL
119 # define OF_MALLOC_FUNC
122 #if __STDC_VERSION__ >= 201112L
123 # define OF_ALIGN(size) _Alignas(size)
124 # define OF_ALIGNOF(type) _Alignof(type)
125 # define OF_ALIGNAS(type) _Alignas(type)
127 # define OF_ALIGN(size) __attribute__((__aligned__(size)))
128 # define OF_ALIGNOF(type) __alignof__(type)
129 # define OF_ALIGNAS(type) OF_ALIGN(OF_ALIGNOF(type))
132 #ifdef __BIGGEST_ALIGNMENT__
133 # define OF_BIGGEST_ALIGNMENT __BIGGEST_ALIGNMENT__
136 # define OF_BIGGEST_ALIGNMENT 16
142 #if (defined(OF_AMD64) || defined(OF_X86)) && OF_BIGGEST_ALIGNMENT < 16
143 # undef OF_BIGGEST_ALIGNMENT
144 # define OF_BIGGEST_ALIGNMENT 16
147 #define OF_PREPROCESSOR_CONCAT2(a, b) a##b
148 #define OF_PREPROCESSOR_CONCAT(a, b) OF_PREPROCESSOR_CONCAT2(a, b)
149 #define OF_PREPROCESSOR_STRINGIFY2(x) #x
150 #define OF_PREPROCESSOR_STRINGIFY(x) OF_PREPROCESSOR_STRINGIFY2(x)
152 #if __OBJFW_RUNTIME_ABI__ || (defined(OF_APPLE_RUNTIME) && defined(__OBJC2__))
153 # define OF_HAVE_NONFRAGILE_IVARS
156 #ifdef OF_HAVE_NONFRAGILE_IVARS
157 # define OF_RESERVE_IVARS(cls, num)
159 # define OF_RESERVE_IVARS(cls, num) \
161 void *OF_PREPROCESSOR_CONCAT(_reserved_, cls)[num];
165 # define OF_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
167 # define OF_GCC_VERSION 0
170 #define OF_STRINGIFY(s) OF_STRINGIFY2(s)
171 #define OF_STRINGIFY2(s) #s
173 #ifndef __has_feature
174 # define __has_feature(x) 0
177 #ifndef __has_attribute
178 # define __has_attribute(x) 0
181 #if __has_feature(objc_bool)
183 # define YES __objc_yes
185 # define NO __objc_no
188 # define true ((bool)1)
190 # define false ((bool)0)
194 #if !__has_feature(objc_instancetype)
195 # define instancetype id
198 #if __has_feature(blocks)
199 # define OF_HAVE_BLOCKS
202 #if __has_feature(objc_arc)
203 # define OF_RETURNS_RETAINED __attribute__((__ns_returns_retained__))
204 # define OF_RETURNS_NOT_RETAINED __attribute__((__ns_returns_not_retained__))
205 # define OF_RETURNS_INNER_POINTER \
206 __attribute__((__objc_returns_inner_pointer__))
207 # define OF_CONSUMED __attribute__((__ns_consumed__))
208 # define OF_WEAK_UNAVAILABLE __attribute__((__objc_arc_weak_unavailable__))
210 # define OF_RETURNS_RETAINED
211 # define OF_RETURNS_NOT_RETAINED
212 # define OF_RETURNS_INNER_POINTER
214 # define OF_WEAK_UNAVAILABLE
219 # undef __unsafe_unretained
221 # undef __autoreleasing
222 # define __unsafe_unretained
224 # define __autoreleasing
227 #if __has_feature(objc_generics)
228 # define OF_HAVE_GENERICS
229 # define OF_GENERIC(...) <__VA_ARGS__>
231 # define OF_GENERIC(...)
234 #if __has_feature(nullability)
235 # define OF_ASSUME_NONNULL_BEGIN _Pragma("clang assume_nonnull begin")
236 # define OF_ASSUME_NONNULL_END _Pragma("clang assume_nonnull end")
237 # define OF_NULLABLE_PROPERTY(...) (__VA_ARGS__, nullable)
238 # define OF_NULL_RESETTABLE_PROPERTY(...) (__VA_ARGS__, null_resettable)
240 # define OF_ASSUME_NONNULL_BEGIN
241 # define OF_ASSUME_NONNULL_END
244 # define _Null_unspecified
245 # define OF_NULLABLE_PROPERTY
246 # define OF_NULL_RESETTABLE_PROPERTY
249 # define null_unspecified
252 #if __has_feature(objc_kindof)
253 # define OF_KINDOF(class_) __kindof class_
255 # define OF_KINDOF(class_) id
258 #if __has_feature(objc_class_property)
259 # define OF_HAVE_CLASS_PROPERTIES
262 #if defined(__clang__) || OF_GCC_VERSION >= 405
263 # define OF_UNREACHABLE __builtin_unreachable();
265 # define OF_UNREACHABLE abort();
268 #if defined(__clang__) || OF_GCC_VERSION >= 406
269 # define OF_SENTINEL __attribute__((__sentinel__))
270 # define OF_NO_RETURN __attribute__((__noreturn__))
273 # define OF_NO_RETURN
277 # define OF_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
279 # define OF_WARN_UNUSED_RESULT
282 #if __has_attribute(__unavailable__)
283 # define OF_UNAVAILABLE __attribute__((__unavailable__))
285 # define OF_UNAVAILABLE
288 #if __has_attribute(__objc_requires_super__)
289 # define OF_REQUIRES_SUPER __attribute__((__objc_requires_super__))
291 # define OF_REQUIRES_SUPER
294 #if __has_attribute(__objc_root_class__)
295 # define OF_ROOT_CLASS __attribute__((__objc_root_class__))
297 # define OF_ROOT_CLASS
300 #if __has_attribute(__objc_subclassing_restricted__)
301 # define OF_SUBCLASSING_RESTRICTED \
302 __attribute__((__objc_subclassing_restricted__))
304 # define OF_SUBCLASSING_RESTRICTED
307 #if __has_attribute(__objc_method_family__)
308 # define OF_METHOD_FAMILY(f) __attribute__((__objc_method_family__(f)))
310 # define OF_METHOD_FAMILY(f)
313 #if __has_attribute(__objc_designated_initializer__)
314 # define OF_DESIGNATED_INITIALIZER \
315 __attribute__((__objc_designated_initializer__))
317 # define OF_DESIGNATED_INITIALIZER
320 #if defined(__clang__) || OF_GCC_VERSION >= 405
321 # define OF_DEPRECATED(project, major, minor, msg) \
322 __attribute__((__deprecated__("Deprecated in " #project " " \
323 #major "." #minor ": " msg)))
324 #elif defined(__GNUC__)
325 # define OF_DEPRECATED(project, major, minor, msg) \
326 __attribute__((__deprecated__))
328 # define OF_DEPRECATED(project, major, minor, msg)
331 #if __has_attribute(__objc_boxable__)
332 # define OF_BOXABLE __attribute__((__objc_boxable__))
337 #if __has_attribute(__swift_name__)
338 # define OF_SWIFT_NAME(name) __attribute__((__swift_name__(name)))
340 # define OF_SWIFT_NAME(name)
343 #if defined(OF_APPLE_RUNTIME) || (defined(OF_OBJFW_RUNTIME) && \
344 defined(__clang_major__) && __clang_major__ >= 21)
345 # if __has_attribute(__objc_direct__)
346 # define OF_DIRECT __attribute__((__objc_direct__))
347 # define OF_DIRECT_PROPERTY(...) (__VA_ARGS__, direct)
349 # if __has_attribute(__objc_direct_members__)
350 # define OF_DIRECT_MEMBERS __attribute__((__objc_direct_members__))
356 #ifndef OF_DIRECT_PROPERTY
357 # define OF_DIRECT_PROPERTY
359 #ifndef OF_DIRECT_MEMBERS
360 # define OF_DIRECT_MEMBERS
363 #ifdef OF_APPLE_RUNTIME
364 # if defined(OF_AMD64) || defined(OF_X86) || defined(OF_ARM64) || \
365 defined(OF_ARM) || defined(OF_POWERPC)
366 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
367 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
371 # if defined(OF_AMD64) || defined(OF_X86) || \
372 defined(OF_ARM64) || defined(OF_ARM) || \
373 defined(OF_POWERPC) || defined(OF_POWERPC64) || \
374 defined(OF_MIPS64_N64) || defined(OF_MIPS) || \
375 defined(OF_SPARC64) || defined(OF_SPARC) || \
376 defined(OF_RISCV64) || defined(OF_LOONGARCH64)
377 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
378 # if __OBJFW_RUNTIME_ABI__ >= 800
379 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
382 # elif defined(OF_MACH_O)
383 # if defined(OF_AMD64)
384 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
385 # if __OBJFW_RUNTIME_ABI__ >= 800
386 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
389 # elif defined(OF_WINDOWS)
390 # if defined(OF_AMD64) || defined(OF_X86) || defined(OF_ARM64)
391 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR
392 # if __OBJFW_RUNTIME_ABI__ >= 800
393 # define OF_HAVE_FORWARDING_TARGET_FOR_SELECTOR_STRET
399 #define OFMaxRetainCount UINT_MAX
401 #ifdef OBJC_COMPILING_RUNTIME
402 # define OFEnsure(cond) \
404 if OF_UNLIKELY (!(cond)) \
405 objc_error("ObjFWRT @ " __FILE__ ":" \
406 OF_STRINGIFY(__LINE__), \
407 "Failed to ensure condition:\n" #cond); \
418 # define OFEnsure(cond) \
420 if OF_UNLIKELY (!(cond)) { \
421 OFLog(@"Failed to ensure condition in " \
422 @__FILE__ ":%d: " @#cond, __LINE__); \
429 # define OFAssert(...) OFEnsure(__VA_ARGS__)
431 # define OFAssert(...)
434 #define OF_UNRECOGNIZED_SELECTOR OFMethodNotFound(self, _cmd);
435 #if __has_feature(objc_arc)
436 # define OF_INVALID_INIT_METHOD OFMethodNotFound(self, _cmd);
438 # define OF_INVALID_INIT_METHOD \
440 OFMethodNotFound(self, _cmd); \
442 objc_release(self); \
449 # define OF_DEALLOC_UNSUPPORTED \
450 [self doesNotRecognizeSelector: _cmd]; \
454 _Pragma("clang diagnostic push"); \
455 _Pragma("clang diagnostic ignored \"-Wunreachable-code\""); \
457 _Pragma("clang diagnostic pop");
459 # define OF_DEALLOC_UNSUPPORTED \
460 [self doesNotRecognizeSelector: _cmd]; \
466 #define OF_SINGLETON_METHODS \
467 - (instancetype)autorelease \
472 - (instancetype)retain \
481 - (unsigned int)retainCount \
483 return OFMaxRetainCount; \
488 OF_DEALLOC_UNSUPPORTED \
491 #define OF_CONSTRUCTOR(prio) \
492 static void __attribute__((__constructor__(prio))) \
493 OF_PREPROCESSOR_CONCAT(constructor, __LINE__)(void)
494 #define OF_DESTRUCTOR(prio) \
495 static void __attribute__((__destructor__(prio))) \
496 OF_PREPROCESSOR_CONCAT(destructor, __LINE__)(void)
498 #define _OFByteSwap16Const(i) \
499 (((i) & UINT16_C(0xFF00)) >> 8 | ((i) & UINT16_C(0x00FF)) << 8)
500 #define _OFByteSwap32Const(i) \
501 (((i) & UINT32_C(0xFF000000)) >> 24 | \
502 ((i) & UINT32_C(0x00FF0000)) >> 8 | \
503 ((i) & UINT32_C(0x0000FF00)) << 8 | \
504 ((i) & UINT32_C(0x000000FF)) << 24)
505 #define _OFByteSwap64Const(i) \
506 (((i) & UINT64_C(0xFF00000000000000)) >> 56 | \
507 ((i) & UINT64_C(0x00FF000000000000)) >> 40 | \
508 ((i) & UINT64_C(0x0000FF0000000000)) >> 24 | \
509 ((i) & UINT64_C(0x000000FF00000000)) >> 8 | \
510 ((i) & UINT64_C(0x00000000FF000000)) << 8 | \
511 ((i) & UINT64_C(0x0000000000FF0000)) << 24 | \
512 ((i) & UINT64_C(0x000000000000FF00)) << 40 | \
513 ((i) & UINT64_C(0x00000000000000FF)) << 56)
515 static OF_INLINE uint16_t OF_CONST_FUNC
516 _OFByteSwap16NonConst(uint16_t i)
518 #if defined(OF_HAVE_BUILTIN_BSWAP16)
519 return __builtin_bswap16(i);
520 #elif (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__)
522 "xchg{b} { %h0, %b0 | %b0, %h0 }"
526 #elif defined(OF_POWERPC) && defined(__GNUC__)
533 #elif defined(OF_ARMV6) && defined(__GNUC__)
540 i = (i & UINT16_C(0xFF00)) >> 8 |
541 (i & UINT16_C(0x00FF)) << 8;
546 static OF_INLINE uint32_t OF_CONST_FUNC
547 _OFByteSwap32NonConst(uint32_t i)
549 #if defined(OF_HAVE_BUILTIN_BSWAP32)
550 return __builtin_bswap32(i);
551 #elif (defined(OF_AMD64) || defined(OF_X86)) && defined(__GNUC__)
557 #elif defined(OF_POWERPC) && defined(__GNUC__)
564 #elif defined(OF_ARMV6) && defined(__GNUC__)
571 i = (i & UINT32_C(0xFF000000)) >> 24 |
572 (i & UINT32_C(0x00FF0000)) >> 8 |
573 (i & UINT32_C(0x0000FF00)) << 8 |
574 (i & UINT32_C(0x000000FF)) << 24;
579 static OF_INLINE uint64_t OF_CONST_FUNC
580 _OFByteSwap64NonConst(uint64_t i)
582 #if defined(OF_HAVE_BUILTIN_BSWAP64)
583 return __builtin_bswap64(i);
584 #elif defined(OF_AMD64) && defined(__GNUC__)
590 #elif defined(OF_X86) && defined(__GNUC__)
594 "xchg{l} { %%eax, %%edx | edx, eax }"
599 i = (uint64_t)_OFByteSwap32NonConst(
600 (uint32_t)(i & UINT32_C(0xFFFFFFFF))) << 32 |
601 _OFByteSwap32NonConst((uint32_t)(i >> 32));
606 #if defined(__GNUC__) || defined(DOXYGEN)
613 # define OFByteSwap16(i) \
614 (__builtin_constant_p(i) ? _OFByteSwap16Const(i) : _OFByteSwap16NonConst(i))
622 # define OFByteSwap32(i) \
623 (__builtin_constant_p(i) ? _OFByteSwap32Const(i) : _OFByteSwap32NonConst(i))
631 # define OFByteSwap64(i) \
632 (__builtin_constant_p(i) ? _OFByteSwap64Const(i) : _OFByteSwap64NonConst(i))
634 # define OFByteSwap16(i) _OFByteSwap16Const(i)
635 # define OFByteSwap32(i) _OFByteSwap32Const(i)
636 # define OFByteSwap64(i) _OFByteSwap64Const(i)
645 static OF_INLINE uint32_t OF_CONST_FUNC
659 static OF_INLINE
float OF_CONST_FUNC
663 memcpy(&ret, &uInt32, 4);
673 static OF_INLINE uint64_t OF_CONST_FUNC
687 static OF_INLINE
double OF_CONST_FUNC
691 memcpy(&ret, &uInt64, 8);
701 static OF_INLINE
float OF_CONST_FUNC
714 static OF_INLINE
double OF_CONST_FUNC
721 #if defined(OF_BIG_ENDIAN) || defined(DOXYGEN)
729 # define OFFromBigEndian16(i) (i)
738 # define OFFromBigEndian32(i) (i)
747 # define OFFromBigEndian64(i) (i)
756 # define OFFromLittleEndian16(i) OFByteSwap16(i)
765 # define OFFromLittleEndian32(i) OFByteSwap32(i)
774 # define OFFromLittleEndian64(i) OFByteSwap64(i)
783 # define OFToBigEndian16(i) (i)
792 # define OFToBigEndian32(i) (i)
801 # define OFToBigEndian64(i) (i)
810 # define OFToLittleEndian16(i) OFByteSwap16(i)
819 # define OFToLittleEndian32(i) OFByteSwap32(i)
828 # define OFToLittleEndian64(i) OFByteSwap64(i)
830 # define OFFromBigEndian16(i) OFByteSwap16(i)
831 # define OFFromBigEndian32(i) OFByteSwap32(i)
832 # define OFFromBigEndian64(i) OFByteSwap64(i)
833 # define OFFromLittleEndian16(i) (i)
834 # define OFFromLittleEndian32(i) (i)
835 # define OFFromLittleEndian64(i) (i)
836 # define OFToBigEndian16(i) OFByteSwap16(i)
837 # define OFToBigEndian32(i) OFByteSwap32(i)
838 # define OFToBigEndian64(i) OFByteSwap64(i)
839 # define OFToLittleEndian16(i) (i)
840 # define OFToLittleEndian32(i) (i)
841 # define OFToLittleEndian64(i) (i)
844 #if defined(OF_FLOAT_BIG_ENDIAN) || defined(DOXYGEN)
851 # define OFFromBigEndianFloat(f) (f)
859 # define OFFromBigEndianDouble(d) (d)
867 # define OFFromLittleEndianFloat(f) OFByteSwapFloat(f)
875 # define OFFromLittleEndianDouble(d) OFByteSwapDouble(d)
883 # define OFToBigEndianFloat(f) (f)
891 # define OFToBigEndianDouble(d) (d)
899 # define OFToLittleEndianFloat(f) OFByteSwapFloat(f)
907 # define OFToLittleEndianDouble(d) OFByteSwapDouble(d)
909 # define OFFromBigEndianFloat(f) OFByteSwapFloat(f)
910 # define OFFromBigEndianDouble(d) OFByteSwapDouble(d)
911 # define OFFromLittleEndianFloat(f) (f)
912 # define OFFromLittleEndianDouble(d) (d)
913 # define OFToBigEndianFloat(f) OFByteSwapFloat(f)
914 # define OFToBigEndianDouble(d) OFByteSwapDouble(d)
915 # define OFToLittleEndianFloat(f) (f)
916 # define OFToLittleEndianDouble(d) (d)
926 #define OFRotateLeft(value, bits) \
927 (((bits) % (sizeof(value) * 8)) > 0 \
928 ? ((value) << ((bits) % (sizeof(value) * 8))) | \
929 ((value) >> (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \
939 #define OFRotateRight(value, bits) \
940 (((bits) % (sizeof(value) * 8)) > 0 \
941 ? ((value) >> ((bits) % (sizeof(value) * 8))) | \
942 ((value) << (sizeof(value) * 8 - ((bits) % (sizeof(value) * 8)))) \
952 #define OFRoundUpToPowerOf2(pow2, value) \
953 (((value) + (pow2) - 1) & ~((pow2) - 1))
955 #define OF_ULONG_BIT (sizeof(unsigned long) * CHAR_BIT)
957 #if defined(OF_HAVE__FLOAT16) || defined(DOXYGEN)
964 OFFloat16FromFloat(
float value)
969 static OF_INLINE
float
978 OFFloat16FromFloat(
float value)
983 # if (defined(OF_BIG_ENDIAN) && !defined(OF_FLOAT_BIG_ENDIAN)) || \
984 (!defined(OF_BIG_ENDIAN) && defined(OF_FLOAT_BIG_ENDIAN))
988 uint16 = (uint32 >> 16) & 0x8000;
990 if (uint32 & 0x7F800000)
991 uint16 |= (((uint32 & 0x7F800000) - 0x38000000) >> 13) & 0x7C00;
993 uint16 |= (uint32 >> 13) & 0x3FF;
995 # if (defined(OF_BIG_ENDIAN) && !defined(OF_FLOAT_BIG_ENDIAN)) || \
996 (!defined(OF_BIG_ENDIAN) && defined(OF_FLOAT_BIG_ENDIAN))
1003 static OF_INLINE
float
1008 # if (defined(OF_BIG_ENDIAN) && !defined(OF_FLOAT_BIG_ENDIAN)) || \
1009 (!defined(OF_BIG_ENDIAN) && defined(OF_FLOAT_BIG_ENDIAN))
1013 uint32 = (value & 0x8000) << 16;
1016 uint32 |= (((value & 0x7C00) + 0x1C000) & 0x3FC00) << 13;
1018 uint32 |= (value & 0x3FF) << 13;
1020 # if (defined(OF_BIG_ENDIAN) && !defined(OF_FLOAT_BIG_ENDIAN)) || \
1021 (!defined(OF_BIG_ENDIAN) && defined(OF_FLOAT_BIG_ENDIAN))
1029 static OF_INLINE
bool
1030 OFBitSetIsSet(
unsigned long *_Nonnull storage,
size_t idx)
1032 return storage[idx / OF_ULONG_BIT] & (1ul << (idx % OF_ULONG_BIT));
1035 static OF_INLINE
void
1036 OFBitSetSet(
unsigned long *_Nonnull storage,
size_t idx)
1038 storage[idx / OF_ULONG_BIT] |= (1ul << (idx % OF_ULONG_BIT));
1041 static OF_INLINE
void
1042 OFBitSetClear(
unsigned long *_Nonnull storage,
size_t idx)
1044 storage[idx / OF_ULONG_BIT] &= ~(1ul << (idx % OF_ULONG_BIT));
1047 static OF_INLINE
void
1048 OFZeroMemory(
void *_Nonnull buffer_,
size_t length)
1050 volatile unsigned char *buffer = (
volatile unsigned char *)buffer_;
1052 while (buffer < (
unsigned char *)buffer_ + length)
1056 static OF_INLINE
bool
1057 OFASCIIIsAlpha(
char c)
1059 return ((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z'));
1062 static OF_INLINE
bool
1063 OFASCIIIsDigit(
char c)
1065 return (c >=
'0' && c <=
'9');
1068 static OF_INLINE
bool
1069 OFASCIIIsAlnum(
char c)
1071 return (OFASCIIIsAlpha(c) || OFASCIIIsDigit(c));
1074 static OF_INLINE
bool
1075 OFASCIIIsSpace(
char c)
1077 return (c ==
' ' || c ==
'\t' || c ==
'\n' || c ==
'\r' || c ==
'\f' ||
1081 static OF_INLINE
char
1082 OFASCIIToUpper(
char c)
1084 return (c >=
'a' && c <=
'z' ?
'A' + (c -
'a') : c);
1087 static OF_INLINE
char
1088 OFASCIIToLower(
char c)
1090 return (c >=
'A' && c <=
'Z' ?
'a' + (c -
'A') : c);
void OFLog(OFConstantString *format,...)
Logs the specified printf-style format to OFStdErr.
Definition: OFStdIOStream.m:118
A class for storing constant strings using the @"" literal.
Definition: OFConstantString.h:42
static OF_INLINE float OF_CONST_FUNC OFBitConvertUInt32ToFloat(uint32_t uInt32)
Bit-converts the specified uint32_t to a float.
Definition: macros.h:660
#define OFByteSwap32(i)
Byte swaps the specified 32 bit integer.
Definition: macros.h:622
static OF_INLINE double OF_CONST_FUNC OFBitConvertUInt64ToDouble(uint64_t uInt64)
Bit-converts the specified uint64_t to a double.
Definition: macros.h:688
__extension__ typedef _Float16 OFFloat16
A type for 16 bit floating point numbers.
Definition: macros.h:961
#define OFByteSwap64(i)
Byte swaps the specified 64 bit integer.
Definition: macros.h:631
static OF_INLINE double OF_CONST_FUNC OFByteSwapDouble(double d)
Byte swaps the specified double.
Definition: macros.h:715
static OF_INLINE float OF_CONST_FUNC OFByteSwapFloat(float f)
Byte swaps the specified float.
Definition: macros.h:702
#define OFByteSwap16(i)
Byte swaps the specified 16 bit integer.
Definition: macros.h:613
static OF_INLINE uint64_t OF_CONST_FUNC OFBitConvertDoubleToUInt64(double d)
Bit-converts the specified double to a uint64_t.
Definition: macros.h:674
static OF_INLINE uint32_t OF_CONST_FUNC OFBitConvertFloatToUInt32(float f)
Bit-converts the specified float to a uint32_t.
Definition: macros.h:646