/thirdparty/breakpad/common/mac/GTMDefines.h

http://github.com/tomahawk-player/tomahawk · C++ Header · 241 lines · 124 code · 25 blank · 92 comment · 15 complexity · 7e10673f5bf6e931109bf26c06f1e348 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 fast enumeration when building for 10.5 or later, and
  129. // reliance on NSEnumerator for 10.4. Remember, NSDictionary w/ FastEnumeration
  130. // does keys, so pick the right thing, nothing is done on the FastEnumeration
  131. // side to be sure you're getting what you wanted.
  132. #ifndef GTM_FOREACH_OBJECT
  133. #if TARGET_OS_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  134. #define GTM_FOREACH_OBJECT(element, collection) \
  135. for (element in collection)
  136. #define GTM_FOREACH_KEY(element, collection) \
  137. for (element in collection)
  138. #else
  139. #define GTM_FOREACH_OBJECT(element, collection) \
  140. for (NSEnumerator * _ ## element ## _enum = [collection objectEnumerator]; \
  141. (element = [_ ## element ## _enum nextObject]) != nil; )
  142. #define GTM_FOREACH_KEY(element, collection) \
  143. for (NSEnumerator * _ ## element ## _enum = [collection keyEnumerator]; \
  144. (element = [_ ## element ## _enum nextObject]) != nil; )
  145. #endif
  146. #endif
  147. // ============================================================================
  148. // ----------------------------------------------------------------------------
  149. // CPP symbols defined based on the project settings so the GTM code has
  150. // simple things to test against w/o scattering the knowledge of project
  151. // setting through all the code.
  152. // ----------------------------------------------------------------------------
  153. // Provide a single constant CPP symbol that all of GTM uses for ifdefing
  154. // iPhone code.
  155. #if TARGET_OS_IPHONE // iPhone SDK
  156. // For iPhone specific stuff
  157. #define GTM_IPHONE_SDK 1
  158. #if TARGET_IPHONE_SIMULATOR
  159. #define GTM_IPHONE_SIMULATOR 1
  160. #else
  161. #define GTM_IPHONE_DEVICE 1
  162. #endif // TARGET_IPHONE_SIMULATOR
  163. #else
  164. // For MacOS specific stuff
  165. #define GTM_MACOS_SDK 1
  166. #endif
  167. // Provide a symbol to include/exclude extra code for GC support. (This mainly
  168. // just controls the inclusion of finalize methods).
  169. #ifndef GTM_SUPPORT_GC
  170. #if GTM_IPHONE_SDK
  171. // iPhone never needs GC
  172. #define GTM_SUPPORT_GC 0
  173. #else
  174. // We can't find a symbol to tell if GC is supported/required, so best we
  175. // do on Mac targets is include it if we're on 10.5 or later.
  176. #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
  177. #define GTM_SUPPORT_GC 0
  178. #else
  179. #define GTM_SUPPORT_GC 1
  180. #endif
  181. #endif
  182. #endif
  183. // To simplify support for 64bit (and Leopard in general), we provide the type
  184. // defines for non Leopard SDKs
  185. #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
  186. // NSInteger/NSUInteger and Max/Mins
  187. #ifndef NSINTEGER_DEFINED
  188. #if __LP64__ || NS_BUILD_32_LIKE_64
  189. typedef long NSInteger;
  190. typedef unsigned long NSUInteger;
  191. #else
  192. typedef int NSInteger;
  193. typedef unsigned int NSUInteger;
  194. #endif
  195. #define NSIntegerMax LONG_MAX
  196. #define NSIntegerMin LONG_MIN
  197. #define NSUIntegerMax ULONG_MAX
  198. #define NSINTEGER_DEFINED 1
  199. #endif // NSINTEGER_DEFINED
  200. // CGFloat
  201. #ifndef CGFLOAT_DEFINED
  202. #if defined(__LP64__) && __LP64__
  203. // This really is an untested path (64bit on Tiger?)
  204. typedef double CGFloat;
  205. #define CGFLOAT_MIN DBL_MIN
  206. #define CGFLOAT_MAX DBL_MAX
  207. #define CGFLOAT_IS_DOUBLE 1
  208. #else /* !defined(__LP64__) || !__LP64__ */
  209. typedef float CGFloat;
  210. #define CGFLOAT_MIN FLT_MIN
  211. #define CGFLOAT_MAX FLT_MAX
  212. #define CGFLOAT_IS_DOUBLE 0
  213. #endif /* !defined(__LP64__) || !__LP64__ */
  214. #define CGFLOAT_DEFINED 1
  215. #endif // CGFLOAT_DEFINED
  216. #endif // MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4