forked from BB9z/RFKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRFRuntime.h
109 lines (81 loc) · 2.72 KB
/
RFRuntime.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
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
/*!
RFRuntime
RFKit
Copyright (c) 2012-2013 BB9z
https://github.com/bb9z/RFKit
The MIT License (MIT)
http://www.opensource.org/licenses/mit-license.php
*/
#pragma mark - Macro options for Debug
// If DEBUG is true and NDEBUG is not defined, define RFDEBUG 1, else 0.
#ifndef RFDEBUG
# if DEBUG && !defined(NDEBUG)
# define RFDEBUG 1
# else
# define RFDEBUG 0
# endif
#endif
/** @enum RFDebugLevel
Used to change debug behave.
*/
enum {
// Silent.
RFDebugLevelSilent = 0,
// Default, won't log anything. For production environment.
RFDebugLevelFatal = 1,
RFDebugLevelDefault = RFDebugLevelFatal,
// Debug mode, show error. Enable log output. Assert enable.
RFDebugLevelError = 2,
// Show warning.
RFDebugLevelWarning = 3,
RFDebugLevelInfo = 4,
RFDebugLevelVerbose = 5
};
#ifndef RFDebugLevel
# if RFDEBUG
# define RFDebugLevel RFDebugLevelError
# else
# define RFDebugLevel RFDebugLevelFatal
# endif
#endif
#pragma mark - Headers
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "dout.h"
#import "RFARC.h"
#import "RFDispatch.h"
#import "RFFeatureSupport.h"
#pragma mark - ObjC Ext
#import "metamacros.h"
#import "EXTKeyPathCoding.h"
#import "EXTScope.h"
/**
\@keypathClassInstance allows compile-time verification of key paths. Similar to
\@keypath, but accept a class as parameter instead of a instance variable.
@code
NSString *objectIDPath = @keypathClassInstance(NSManagedObject, objectID);
// => @"objectID"
NSString *footerViewFramePath = @keypathClassInstance(UITableView, tableFooterView, frame);
// => @"frame"
@endcode
@bug In a class method, cannot use `self` as CLASS.
*/
#define keypathClassInstance(...)\
metamacro_if_eq(2, metamacro_argcount(__VA_ARGS__))(keypathClassInstance1(__VA_ARGS__))(keypathClassInstance2(__VA_ARGS__))
#define keypathClassInstance1(CLASS, PATH)\
(({CLASS *_proxy_; ((void)(NO && ((void)_proxy_.PATH, NO)), # PATH);}))
#define keypathClassInstance2(CLASS, PROPERTY, PATH)\
(({CLASS *_proxy_; ((void)(NO && ((void)_proxy_.PROPERTY.PATH, NO)), # PATH);}))
#pragma mark - Language Addition
/** Define a const NSString
@code
RFDefineConstString(aaa);
RFDefineConstString(bbb, "something");
// Will be
NSString *const aaa = @"aaa";
NSString *const bbb = @"something";
@endcode
*/
#define RFDefineConstString(...) metamacro_if_eq(1, metamacro_argcount(__VA_ARGS__))(_RFDefineConstString1(metamacro_at0(__VA_ARGS__)))(_RFDefineConstString2(metamacro_at0(__VA_ARGS__), metamacro_at1(__VA_ARGS__)))
#define _RFDefineConstString1(name) NSString *const name = @metamacro_stringify_(name)
#define _RFDefineConstString2(name, value) NSString *const name = @value