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