-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCQMacros.h
36 lines (33 loc) · 1.01 KB
/
CQMacros.h
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
/**
Copyright (C) 2016 Quentin Mathe
Author: Quentin Mathe <[email protected]>
Date: August 2016
License: MIT (see COPYING)
*/
/**
* Simple macro for safely initialising the superclass.
*/
#define SUPERINIT if((self = [super init]) == nil) { return nil; }
/**
* Exception macro to check whether the given argument respects a condition.
*
* When the condition evaluates to NO, an NSInvalidArgumentException is raised.
*/
#define INVALIDARG_EXCEPTION_TEST(arg, condition) do { \
if (NO == (condition)) \
{ \
[NSException raise: NSInvalidArgumentException format: @"For %@, %s " \
"must respect %s", NSStringFromSelector(_cmd), #arg , #condition]; \
} \
} while (0);
/**
* Exception macro to check the given argument is not nil, otherwise an
* NSInvalidArgumentException is raised.
*/
#define NILARG_EXCEPTION_TEST(arg) do { \
if (nil == arg) \
{ \
[NSException raise: NSInvalidArgumentException format: @"For %@, " \
"%s must not be nil", NSStringFromSelector(_cmd), #arg]; \
} \
} while(0);