Merge pull request #9 from gunyarakun/fix-typo
[cocotron.git] / Foundation / NSObjCRuntime.h
blobd80583d3534101b1edda289f3bd83d51d744a904
1 /* Copyright (c) 2006-2007 Christopher J. W. Lloyd
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
9 #import <objc/objc.h>
10 #include <stdarg.h>
11 #include <stdint.h>
12 #include <limits.h>
14 #ifdef __clang__
15 #define FOUNDATION_DLLEXPORT
16 #define FOUNDATION_DLLIMPORT
17 #else
18 #define FOUNDATION_DLLEXPORT __declspec(dllexport)
19 #define FOUNDATION_DLLIMPORT __declspec(dllimport)
20 #endif
22 #ifdef __cplusplus
24 #if defined(__WIN32__)
25 #if defined(FOUNDATION_INSIDE_BUILD)
26 #define FOUNDATION_EXPORT extern "C" FOUNDATION_DLLEXPORT
27 #else
28 #define FOUNDATION_EXPORT extern "C" FOUNDATION_DLLIMPORT
29 #endif
30 #else
31 #define FOUNDATION_EXPORT extern "C"
32 #endif
34 #else
36 #if defined(__WIN32__)
37 #if defined(FOUNDATION_INSIDE_BUILD)
38 #define FOUNDATION_EXPORT FOUNDATION_DLLEXPORT extern
39 #else
40 #define FOUNDATION_EXPORT FOUNDATION_DLLIMPORT extern
41 #endif
42 #else
43 #define FOUNDATION_EXPORT extern
44 #endif
46 #endif
48 #define NS_INLINE static inline
50 #ifdef __clang__
51 #define NS_ROOT_CLASS __attribute__((objc_root_class))
52 #else
53 #define NS_ROOT_CLASS
54 #endif
56 #ifndef __has_feature
57 #define __has_feature(x) 0
58 #endif
60 #ifndef __has_extension
61 #define __has_extension(x) 0
62 #endif
64 #ifndef __has_attribute
65 #define __has_attribute(x) 0
66 #endif
68 #if __has_feature(attribute_ns_returns_retained)
69 #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
70 #else
71 #define NS_RETURNS_RETAINED
72 #endif
74 #if __has_feature(attribute_ns_returns_not_retained)
75 #define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
76 #else
77 #define NS_RETURNS_NOT_RETAINED
78 #endif
80 #ifndef CF_RETURNS_RETAINED
81 #if __has_feature(attribute_cf_returns_retained)
82 #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
83 #else
84 #define CF_RETURNS_RETAINED
85 #endif
86 #endif
88 @class NSString;
90 #define NSINTEGER_DEFINED 1
92 #if defined(__LP64__)
93 typedef long NSInteger;
94 typedef unsigned long NSUInteger;
95 #define NSIntegerMax LONG_MAX
96 #define NSIntegerMin LONG_MIN
97 #define NSUIntegerMax ULONG_MAX
98 #define NSIntegerFormat "%ld"
99 #define NSUIntegerFormat "%lu"
100 #else
101 typedef int NSInteger;
102 typedef unsigned int NSUInteger;
103 #define NSIntegerMax INT_MAX
104 #define NSIntegerMin INT_MIN
105 #define NSUIntegerMax UINT_MAX
106 #define NSIntegerFormat "%d"
107 #define NSUIntegerFormat "%u"
108 #endif
110 enum {
111 NSOrderedAscending = -1,
112 NSOrderedSame = 0,
113 NSOrderedDescending = 1
116 typedef NSInteger NSComparisonResult;
118 #define NSNotFound NSIntegerMax
120 #ifndef MIN
121 #define MIN(a, b) ({__typeof__(a) _a = (a); __typeof__(b) _b = (b); (_a < _b) ? _a : _b; })
122 #else
123 #warning MIN is already defined, MIN(a, b) may not behave as expected.
124 #endif
126 #ifndef MAX
127 #define MAX(a, b) ({__typeof__(a) _a = (a); __typeof__(b) _b = (b); (_a > _b) ? _a : _b; })
128 #else
129 #warning MAX is already defined, MAX(a, b) may not not behave as expected.
130 #endif
132 #ifndef ABS
133 #define ABS(a) ({__typeof__(a) _a = (a); (_a < 0) ? -_a : _a; })
134 #else
135 #warning ABS is already defined, ABS(a) may not behave as expected.
136 #endif
138 #ifndef NS_ENUM
139 #define NS_ENUM(_type, _name) \
140 _type _name; \
141 enum
142 #endif
144 #ifndef NS_OPTIONS
145 #define NS_OPTIONS(_type, _name) \
146 _type _name; \
147 enum
148 #endif
150 FOUNDATION_EXPORT void NSLog(NSString *format, ...);
151 FOUNDATION_EXPORT void NSLogv(NSString *format, va_list args);
153 FOUNDATION_EXPORT const char *NSGetSizeAndAlignment(const char *type, NSUInteger *size, NSUInteger *alignment);
155 FOUNDATION_EXPORT SEL NSSelectorFromString(NSString *selectorName);
156 FOUNDATION_EXPORT NSString *NSStringFromSelector(SEL selector);
158 FOUNDATION_EXPORT Class NSClassFromString(NSString *className);
159 FOUNDATION_EXPORT NSString *NSStringFromClass(Class aClass);