-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathRFRuntime.h
160 lines (129 loc) · 3.78 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*!
RFRuntime
RFKit
Copyright (c) 2012-2015, 2017-2018 BB9z
https://github.com/BB9z/RFKit
The MIT License (MIT)
http://www.opensource.org/licenses/mit-license.php
*/
#pragma once
#pragma mark - Macro options for Debug
// If DEBUG is true and NDEBUG is not defined, define RFDEBUG 1, else 0.
#ifndef RFDEBUG
# if defined(DEBUG) && !defined(NDEBUG)
# if DEBUG
# define RFDEBUG 1
# else
# define RFDEBUG 0
# endif
# 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 "RFFoundation.h"
#if TARGET_OS_OSX
# import <AppKit/AppKit.h>
#else
# import <UIKit/UIKit.h>
#endif
#import "dout.h"
#import "RFARC.h"
#import "RFDispatch.h"
#import "RFFeatureSupport.h"
#pragma mark - Bridge NS types and UI types
#if TARGET_OS_OSX
#if !defined(UIEdgeInsets)
# define UIEdgeInsets NSEdgeInsets
#endif
#if !defined(UIEdgeInsetsMake)
# define UIEdgeInsetsMake NSEdgeInsetsMake
#endif
#if !defined(UIEdgeInsetsEqualToEdgeInsets)
# define UIEdgeInsetsEqualToEdgeInsets NSEdgeInsetsEqual
#endif
#if !defined(UIEdgeInsetsZero)
# define UIEdgeInsetsZero NSEdgeInsetsZero
#endif
#if !defined(UIImage)
# define UIImage NSImage
#endif
#if !defined(UIResponder)
# define UIResponder NSResponder
#endif
#if !defined(UIView)
# define UIView NSView
#endif
#if !defined(UIViewController)
# define UIViewController NSViewController
#endif
#if !defined(UIButton)
# define UIButton NSButton
#endif
#if !defined(UITableView)
# define UITableView NSTableView
#endif
#if !defined(UICollectionView)
# define UICollectionView NSCollectionView
#endif
#if !defined(UIStoryboardSegue)
# define UIStoryboardSegue NSStoryboardSegue
#endif
#endif // END: TARGET_OS_OSX
#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__))(_rf_keypathClassInstance1_(__VA_ARGS__))(_rf_keypathClassInstance2_(__VA_ARGS__))
#define _rf_keypathClassInstance1_(CLASS, PATH)\
keypath(CLASS.new, PATH)
#define _rf_keypathClassInstance2_(CLASS, PROPERTY, PATH)\
keypath(CLASS.new.PROPERTY, 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__))(_rf_DefineConstString1_(metamacro_at0(__VA_ARGS__)))(_rf_DefineConstString2_(metamacro_at0(__VA_ARGS__), metamacro_at1(__VA_ARGS__)))
#define _rf_DefineConstString1_(name) NSString *const name = @metamacro_stringify_(name)
#define _rf_DefineConstString2_(name, value) NSString *const name = @value