forked from davekeck/EBFoundation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEBUtilities.h
More file actions
113 lines (95 loc) · 4.67 KB
/
Copy pathEBUtilities.h
File metadata and controls
113 lines (95 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#import <Foundation/Foundation.h>
#import <TargetConditionals.h>
#define EBTargetOSX (TARGET_OS_MAC && !TARGET_OS_IPHONE)
#define EBTargetIOS (TARGET_OS_MAC && TARGET_OS_IPHONE)
#define EBTry EBTry
#define EBFail EBFail
#define EBFinish EBFinish
#define EBStringify(a) #a
#define EBStaticArrayCount(array) (sizeof(array) / sizeof(*array))
#define EBEqualBools(a, b) ((bool)(a) == (bool)(b))
#define EBRaise(message, ...) [NSException raise: NSGenericException format: (message), ##__VA_ARGS__]
#define EBMakeStringConstExtern(constantName) extern NSString *const constantName;
#define EBMakeStringConst(constantName) NSString *const constantName = @EBStringify(constantName)
#define EBMakeUniquePointerConst(constantName) const void *const constantName = (const void *const)&constantName
#define EBMakeWeakSelf() __weak __typeof__(self) weakSelf = self
#define EBMakeStrongSelf() __typeof__(self) strongSelf = weakSelf
#define EBConfirmOrPerform(condition, action) \
({ \
if (!(condition)) \
{ \
action; \
} \
})
#define EBNoOp (void)0
#define EBValueOrFallback(value, fallback) \
({ \
__typeof__(value) __value = (value); \
__value ? __value : (fallback); \
})
#define EBMin(a, b) \
({ \
__typeof__(a) __a = (a); \
__typeof__(b) __b = (b); \
__a < __b ? __a : __b; \
})
#define EBMax(a, b) \
({ \
__typeof__(a) __a = (a); \
__typeof__(b) __b = (b); \
__a < __b ? __b : __a; \
})
#define EBCapMin EBMax
#define EBCapMax EBMin
#define EBCapRange(min, max, value) \
({ \
__typeof__(min) __min = (min); \
__typeof__(max) __max = (max); \
__typeof__(value) __value = (value); \
__value <= __min ? __min : (__value >= __max ? __max : __value); \
})
#define EBValueInRange(min, max, value) \
({ \
__typeof__(min) __min = (min); \
__typeof__(max) __max = (max); \
__typeof__(value) __value = (value); \
__value >= __min && __value <= __max; \
})
#define EBValueInRangeExclusive(min, max, value) \
({ \
__typeof__(min) __min = (min); \
__typeof__(max) __max = (max); \
__typeof__(value) __value = (value); \
__value >= __min && __value < __max; \
})
/* Return the min/max possible values for signed and unsigned types or variables. */
#define EBMinSignedVal(type) (-((intmax_t)1 << ((sizeof(type) * 8) - 1)))
#define EBMaxSignedVal(type) (((((intmax_t)1 << ((sizeof(type) * 8) - 2)) - 1) * 2) + 1)
#define EBMaxUnsignedVal(type) (((((uintmax_t)1 << ((sizeof(type) * 8) - 1)) - 1) * 2) + 1)
#if __has_feature(objc_arc)
#define EBSetTimer(oldTimer, newTimer) \
({ \
__typeof__(oldTimer) __oldTimer = (oldTimer); \
NSTimer *__newTimer = (newTimer); \
\
if (*__oldTimer != __newTimer) \
{ \
[*__oldTimer invalidate]; \
*__oldTimer = __newTimer; \
} \
})
#else
#define EBSetTimer(oldTimer, newTimer) \
({ \
__typeof__(oldTimer) __oldTimer = (oldTimer); \
NSTimer *__newTimer = (newTimer); \
\
if (*__oldTimer != __newTimer) \
{ \
[__newTimer retain]; \
[*__oldTimer invalidate]; \
[*__oldTimer release]; \
*__oldTimer = __newTimer; \
} \
})
#endif