GTMDefines.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. // CPP symbols that can be overridden in a prefix to control how the toolbox
  21. // is compiled.
  22. // ----------------------------------------------------------------------------
  23. // GTMHTTPFetcher will support logging by default but only hook its input
  24. // stream support for logging when requested. You can control the inclusion of
  25. // the code by providing your own definitions for these w/in a prefix header.
  26. //
  27. #ifndef GTM_HTTPFETCHER_ENABLE_LOGGING
  28. # define GTM_HTTPFETCHER_ENABLE_LOGGING 1
  29. #endif // GTM_HTTPFETCHER_ENABLE_LOGGING
  30. #ifndef GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING
  31. # define GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING 0
  32. #endif // GTM_HTTPFETCHER_ENABLE_INPUTSTREAM_LOGGING
  33. // _GTMDevLog & _GTMDevAssert
  34. //
  35. // _GTMDevLog & _GTMDevAssert are meant to be a very lightweight shell for
  36. // developer level errors. This implementation simply macros to NSLog/NSAssert.
  37. // It is not intended to be a general logging/reporting system.
  38. //
  39. // Please see http://code.google.com/p/google-toolbox-for-mac/wiki/DevLogNAssert
  40. // for a little more background on the usage of these macros.
  41. //
  42. // _GTMDevLog log some error/problem in debug builds
  43. // _GTMDevAssert assert if conditon isn't met w/in a method/function
  44. // in all builds.
  45. //
  46. // To replace this system, just provide different macro definitions in your
  47. // prefix header. Remember, any implementation you provide *must* be thread
  48. // safe since this could be called by anything in what ever situtation it has
  49. // been placed in.
  50. //
  51. // We only define the simple macros if nothing else has defined this.
  52. #ifndef _GTMDevLog
  53. #ifdef DEBUG
  54. #define _GTMDevLog(...) NSLog(__VA_ARGS__)
  55. #else
  56. #define _GTMDevLog(...) do { } while (0)
  57. #endif
  58. // we directly invoke the NSAssert handler so we can pass on the varargs
  59. // (NSAssert doesn't have a macro we can use that takes varargs)
  60. #if !defined(NS_BLOCK_ASSERTIONS)
  61. #define _GTMDevAssert(condition, ...) \
  62. do { \
  63. if (!(condition)) { \
  64. [[NSAssertionHandler currentHandler] \
  65. handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
  66. file:[NSString stringWithUTF8String:__FILE__] \
  67. lineNumber:__LINE__ \
  68. description:__VA_ARGS__]; \
  69. } \
  70. } while(0)
  71. #else // !defined(NS_BLOCK_ASSERTIONS)
  72. #define _GTMDevAssert(condition, ...) do { } while (0)
  73. #endif // !defined(NS_BLOCK_ASSERTIONS)
  74. #endif // _GTMDevLog
  75. // ============================================================================
  76. // ----------------------------------------------------------------------------
  77. // CPP symbols defined based on the project settings so the GTM code has
  78. // simple things to test against w/o scattering the knowledge of project
  79. // setting through all the code.
  80. // ----------------------------------------------------------------------------
  81. // Provide a single constant CPP symbol that all of GTM uses for ifdefing
  82. // iPhone code.
  83. #include <TargetConditionals.h>
  84. #if TARGET_OS_IPHONE // iPhone SDK
  85. // For iPhone specific stuff
  86. #define GTM_IPHONE_SDK 1
  87. #else
  88. // For MacOS specific stuff
  89. #define GTM_MACOS_SDK 1
  90. #endif
  91. // To simplify support for 64bit (and Leopard in general), we provide the type
  92. // defines for non Leopard SDKs
  93. #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4
  94. // NSInteger/NSUInteger and Max/Mins
  95. #ifndef NSINTEGER_DEFINED
  96. #if __LP64__ || NS_BUILD_32_LIKE_64
  97. typedef long NSInteger;
  98. typedef unsigned long NSUInteger;
  99. #else
  100. typedef int NSInteger;
  101. typedef unsigned int NSUInteger;
  102. #endif
  103. #define NSIntegerMax LONG_MAX
  104. #define NSIntegerMin LONG_MIN
  105. #define NSUIntegerMax ULONG_MAX
  106. #define NSINTEGER_DEFINED 1
  107. #endif // NSINTEGER_DEFINED
  108. // CGFloat
  109. #ifndef CGFLOAT_DEFINED
  110. #if defined(__LP64__) && __LP64__
  111. // This really is an untested path (64bit on Tiger?)
  112. typedef double CGFloat;
  113. #define CGFLOAT_MIN DBL_MIN
  114. #define CGFLOAT_MAX DBL_MAX
  115. #define CGFLOAT_IS_DOUBLE 1
  116. #else /* !defined(__LP64__) || !__LP64__ */
  117. typedef float CGFloat;
  118. #define CGFLOAT_MIN FLT_MIN
  119. #define CGFLOAT_MAX FLT_MAX
  120. #define CGFLOAT_IS_DOUBLE 0
  121. #endif /* !defined(__LP64__) || !__LP64__ */
  122. #define CGFLOAT_DEFINED 1
  123. #endif // CGFLOAT_DEFINED
  124. #endif // MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4