PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/MapView/GTM/GTMDefines.h

http://github.com/route-me/route-me
C Header | 287 lines | 158 code | 31 blank | 98 comment | 13 complexity | 77e7607b06920eb3e073833e9e669c42 MD5 | raw file
  1// 
  2// GTMDefines.h
  3//
  4//  Copyright 2008 Google Inc.
  5//
  6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  7//  use this file except in compliance with the License.  You may obtain a copy
  8//  of the License at
  9// 
 10//  http://www.apache.org/licenses/LICENSE-2.0
 11// 
 12//  Unless required by applicable law or agreed to in writing, software
 13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 15//  License for the specific language governing permissions and limitations under
 16//  the License.
 17//
 18 
 19// ============================================================================
 20
 21#include <AvailabilityMacros.h>
 22#include <TargetConditionals.h>
 23
 24// Not all MAC_OS_X_VERSION_10_X macros defined in past SDKs
 25#ifndef MAC_OS_X_VERSION_10_5
 26  #define MAC_OS_X_VERSION_10_5 1050
 27#endif
 28#ifndef MAC_OS_X_VERSION_10_6
 29  #define MAC_OS_X_VERSION_10_6 1060
 30#endif
 31
 32// ----------------------------------------------------------------------------
 33// CPP symbols that can be overridden in a prefix to control how the toolbox
 34// is compiled.
 35// ----------------------------------------------------------------------------
 36
 37
 38// By setting the GTM_CONTAINERS_VALIDATION_FAILED_LOG and 
 39// GTM_CONTAINERS_VALIDATION_FAILED_ASSERT macros you can control what happens
 40// when a validation fails. If you implement your own validators, you may want
 41// to control their internals using the same macros for consistency.
 42#ifndef GTM_CONTAINERS_VALIDATION_FAILED_ASSERT
 43  #define GTM_CONTAINERS_VALIDATION_FAILED_ASSERT 0
 44#endif
 45
 46// Give ourselves a consistent way to do inlines.  Apple's macros even use
 47// a few different actual definitions, so we're based off of the foundation
 48// one.
 49#if !defined(GTM_INLINE)
 50  #if defined (__GNUC__) && (__GNUC__ == 4)
 51    #define GTM_INLINE static __inline__ __attribute__((always_inline))
 52  #else
 53    #define GTM_INLINE static __inline__
 54  #endif
 55#endif
 56
 57// Give ourselves a consistent way of doing externs that links up nicely
 58// when mixing objc and objc++
 59#if !defined (GTM_EXTERN)
 60  #if defined __cplusplus
 61    #define GTM_EXTERN extern "C"
 62  #else
 63    #define GTM_EXTERN extern
 64  #endif
 65#endif
 66
 67// Give ourselves a consistent way of exporting things if we have visibility
 68// set to hidden.
 69#if !defined (GTM_EXPORT)
 70  #define GTM_EXPORT __attribute__((visibility("default")))
 71#endif
 72
 73// _GTMDevLog & _GTMDevAssert
 74//
 75// _GTMDevLog & _GTMDevAssert are meant to be a very lightweight shell for
 76// developer level errors.  This implementation simply macros to NSLog/NSAssert.
 77// It is not intended to be a general logging/reporting system.
 78//
 79// Please see http://code.google.com/p/google-toolbox-for-mac/wiki/DevLogNAssert
 80// for a little more background on the usage of these macros.
 81//
 82//    _GTMDevLog           log some error/problem in debug builds
 83//    _GTMDevAssert        assert if conditon isn't met w/in a method/function
 84//                           in all builds.
 85// 
 86// To replace this system, just provide different macro definitions in your
 87// prefix header.  Remember, any implementation you provide *must* be thread
 88// safe since this could be called by anything in what ever situtation it has
 89// been placed in.
 90// 
 91
 92// We only define the simple macros if nothing else has defined this.
 93#ifndef _GTMDevLog
 94
 95#ifdef DEBUG
 96  #define _GTMDevLog(...) NSLog(__VA_ARGS__)
 97#else
 98  #define _GTMDevLog(...) do { } while (0)
 99#endif
100
101#endif // _GTMDevLog
102
103// Declared here so that it can easily be used for logging tracking if
104// necessary. See GTMUnitTestDevLog.h for details.
105@class NSString;
106GTM_EXTERN void _GTMUnitTestDevLog(NSString *format, ...);
107
108#ifndef _GTMDevAssert
109// we directly invoke the NSAssert handler so we can pass on the varargs
110// (NSAssert doesn't have a macro we can use that takes varargs)
111#if !defined(NS_BLOCK_ASSERTIONS)
112  #define _GTMDevAssert(condition, ...)                                       \
113    do {                                                                      \
114      if (!(condition)) {                                                     \
115        [[NSAssertionHandler currentHandler]                                  \
116            handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
117                               file:[NSString stringWithUTF8String:__FILE__]  \
118                         lineNumber:__LINE__                                  \
119                        description:__VA_ARGS__];                             \
120      }                                                                       \
121    } while(0)
122#else // !defined(NS_BLOCK_ASSERTIONS)
123  #define _GTMDevAssert(condition, ...) do { } while (0)
124#endif // !defined(NS_BLOCK_ASSERTIONS)
125
126#endif // _GTMDevAssert
127
128// _GTMCompileAssert
129// _GTMCompileAssert is an assert that is meant to fire at compile time if you
130// want to check things at compile instead of runtime. For example if you
131// want to check that a wchar is 4 bytes instead of 2 you would use
132// _GTMCompileAssert(sizeof(wchar_t) == 4, wchar_t_is_4_bytes_on_OS_X)
133// Note that the second "arg" is not in quotes, and must be a valid processor
134// symbol in it's own right (no spaces, punctuation etc).
135
136// Wrapping this in an #ifndef allows external groups to define their own
137// compile time assert scheme.
138#ifndef _GTMCompileAssert
139  // We got this technique from here:
140  // http://unixjunkie.blogspot.com/2007/10/better-compile-time-asserts_29.html
141
142  #define _GTMCompileAssertSymbolInner(line, msg) _GTMCOMPILEASSERT ## line ## __ ## msg
143  #define _GTMCompileAssertSymbol(line, msg) _GTMCompileAssertSymbolInner(line, msg)
144  #define _GTMCompileAssert(test, msg) \
145    typedef char _GTMCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ]
146#endif // _GTMCompileAssert
147
148// Macro to allow you to create NSStrings out of other macros.
149// #define FOO foo
150// NSString *fooString = GTM_NSSTRINGIFY(FOO);
151#if !defined (GTM_NSSTRINGIFY)
152  #define GTM_NSSTRINGIFY_INNER(x) @#x
153  #define GTM_NSSTRINGIFY(x) GTM_NSSTRINGIFY_INNER(x)
154#endif
155
156// Macro to allow fast enumeration when building for 10.5 or later, and
157// reliance on NSEnumerator for 10.4.  Remember, NSDictionary w/ FastEnumeration
158// does keys, so pick the right thing, nothing is done on the FastEnumeration
159// side to be sure you're getting what you wanted.
160#ifndef GTM_FOREACH_OBJECT
161  #if TARGET_OS_IPHONE || !(MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
162    #define GTM_FOREACH_ENUMEREE(element, enumeration) \
163      for (element in enumeration)
164    #define GTM_FOREACH_OBJECT(element, collection) \
165      for (element in collection)
166    #define GTM_FOREACH_KEY(element, collection) \
167      for (element in collection)
168  #else
169    #define GTM_FOREACH_ENUMEREE(element, enumeration) \
170      for (NSEnumerator *_ ## element ## _enum = enumeration; \
171           (element = [_ ## element ## _enum nextObject]) != nil; )
172    #define GTM_FOREACH_OBJECT(element, collection) \
173      GTM_FOREACH_ENUMEREE(element, [collection objectEnumerator])
174    #define GTM_FOREACH_KEY(element, collection) \
175      GTM_FOREACH_ENUMEREE(element, [collection keyEnumerator])
176  #endif
177#endif
178
179// ============================================================================
180
181// ----------------------------------------------------------------------------
182// CPP symbols defined based on the project settings so the GTM code has
183// simple things to test against w/o scattering the knowledge of project
184// setting through all the code.
185// ----------------------------------------------------------------------------
186
187// Provide a single constant CPP symbol that all of GTM uses for ifdefing
188// iPhone code.
189#if TARGET_OS_IPHONE // iPhone SDK
190  // For iPhone specific stuff
191  #define GTM_IPHONE_SDK 1
192  #if TARGET_IPHONE_SIMULATOR
193    #define GTM_IPHONE_SIMULATOR 1
194  #else
195    #define GTM_IPHONE_DEVICE 1
196  #endif  // TARGET_IPHONE_SIMULATOR
197#else
198  // For MacOS specific stuff
199  #define GTM_MACOS_SDK 1
200#endif
201
202// Some of our own availability macros
203#if GTM_MACOS_SDK
204#define GTM_AVAILABLE_ONLY_ON_IPHONE UNAVAILABLE_ATTRIBUTE
205#define GTM_AVAILABLE_ONLY_ON_MACOS
206#else 
207#define GTM_AVAILABLE_ONLY_ON_IPHONE
208#define GTM_AVAILABLE_ONLY_ON_MACOS UNAVAILABLE_ATTRIBUTE
209#endif 
210
211// Provide a symbol to include/exclude extra code for GC support.  (This mainly
212// just controls the inclusion of finalize methods).
213#ifndef GTM_SUPPORT_GC
214  #if GTM_IPHONE_SDK
215    // iPhone never needs GC
216    #define GTM_SUPPORT_GC 0
217  #else
218    // We can't find a symbol to tell if GC is supported/required, so best we
219    // do on Mac targets is include it if we're on 10.5 or later.
220    #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
221      #define GTM_SUPPORT_GC 0
222    #else
223      #define GTM_SUPPORT_GC 1
224    #endif
225  #endif
226#endif
227
228// To simplify support for 64bit (and Leopard in general), we provide the type
229// defines for non Leopard SDKs
230#if !(MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
231 // NSInteger/NSUInteger and Max/Mins
232  #ifndef NSINTEGER_DEFINED
233    #if __LP64__ || NS_BUILD_32_LIKE_64
234      typedef long NSInteger;
235      typedef unsigned long NSUInteger;
236    #else
237      typedef int NSInteger;
238      typedef unsigned int NSUInteger;
239    #endif
240    #define NSIntegerMax    LONG_MAX
241    #define NSIntegerMin    LONG_MIN
242    #define NSUIntegerMax   ULONG_MAX
243    #define NSINTEGER_DEFINED 1
244  #endif  // NSINTEGER_DEFINED
245  // CGFloat
246  #ifndef CGFLOAT_DEFINED
247    #if defined(__LP64__) && __LP64__
248      // This really is an untested path (64bit on Tiger?)
249      typedef double CGFloat;
250      #define CGFLOAT_MIN DBL_MIN
251      #define CGFLOAT_MAX DBL_MAX
252      #define CGFLOAT_IS_DOUBLE 1
253    #else /* !defined(__LP64__) || !__LP64__ */
254      typedef float CGFloat;
255      #define CGFLOAT_MIN FLT_MIN
256      #define CGFLOAT_MAX FLT_MAX
257      #define CGFLOAT_IS_DOUBLE 0
258    #endif /* !defined(__LP64__) || !__LP64__ */
259    #define CGFLOAT_DEFINED 1
260  #endif // CGFLOAT_DEFINED
261#endif  // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
262
263// Some support for advanced clang static analysis functionality
264// See http://clang-analyzer.llvm.org/annotations.html
265#ifndef __has_feature      // Optional.
266  #define __has_feature(x) 0 // Compatibility with non-clang compilers.
267#endif
268
269#ifndef NS_RETURNS_RETAINED
270  #if __has_feature(attribute_ns_returns_retained)
271    #define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
272  #else
273    #define NS_RETURNS_RETAINED
274  #endif
275#endif
276
277#ifndef CF_RETURNS_RETAINED
278  #if __has_feature(attribute_cf_returns_retained)
279    #define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
280  #else
281    #define CF_RETURNS_RETAINED
282  #endif
283#endif
284
285#ifndef GTM_NONNULL
286  #define GTM_NONNULL(x) __attribute__((nonnull(x)))
287#endif