/MapView/GTM/GTMObjC2Runtime.h

http://github.com/route-me/route-me · C Header · 111 lines · 65 code · 11 blank · 35 comment · 1 complexity · 95570733f4eec12263376a693d442bc6 MD5 · raw file

  1. //
  2. // GTMObjC2Runtime.h
  3. //
  4. // Copyright 2007-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. #import <objc/objc-api.h>
  19. #import <objc/objc-auto.h>
  20. #import "GTMDefines.h"
  21. // These functions exist for code that we want to compile on both the < 10.5
  22. // sdks and on the >= 10.5 sdks without warnings. It basically reimplements
  23. // certain parts of the objc2 runtime in terms of the objc1 runtime. It is not
  24. // a complete implementation as I've only implemented the routines I know we
  25. // use. Feel free to add more as necessary.
  26. // These functions are not documented because they conform to the documentation
  27. // for the ObjC2 Runtime.
  28. #if OBJC_API_VERSION >= 2 // Only have optional and req'd keywords in ObjC2.
  29. #define AT_OPTIONAL @optional
  30. #define AT_REQUIRED @required
  31. #else
  32. #define AT_OPTIONAL
  33. #define AT_REQUIRED
  34. #endif
  35. // The file objc-runtime.h was moved to runtime.h and in Leopard, objc-runtime.h
  36. // was just a wrapper around runtime.h. For the iPhone SDK, this objc-runtime.h
  37. // is removed in the iPhoneOS2.0 SDK.
  38. //
  39. // The |Object| class was removed in the iPhone2.0 SDK too.
  40. #if GTM_IPHONE_SDK
  41. #import <objc/runtime.h>
  42. #else
  43. #import <objc/objc-runtime.h>
  44. #import <objc/Object.h>
  45. #endif
  46. #import <libkern/OSAtomic.h>
  47. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  48. #import "objc/Protocol.h"
  49. OBJC_EXPORT Class object_getClass(id obj);
  50. OBJC_EXPORT const char *class_getName(Class cls);
  51. OBJC_EXPORT BOOL class_conformsToProtocol(Class cls, Protocol *protocol);
  52. OBJC_EXPORT BOOL class_respondsToSelector(Class cls, SEL sel);
  53. OBJC_EXPORT Class class_getSuperclass(Class cls);
  54. OBJC_EXPORT Method *class_copyMethodList(Class cls, unsigned int *outCount);
  55. OBJC_EXPORT SEL method_getName(Method m);
  56. OBJC_EXPORT void method_exchangeImplementations(Method m1, Method m2);
  57. OBJC_EXPORT IMP method_getImplementation(Method method);
  58. OBJC_EXPORT IMP method_setImplementation(Method method, IMP imp);
  59. OBJC_EXPORT struct objc_method_description protocol_getMethodDescription(Protocol *p,
  60. SEL aSel,
  61. BOOL isRequiredMethod,
  62. BOOL isInstanceMethod);
  63. // If building for 10.4 but using the 10.5 SDK, don't include these.
  64. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  65. // atomics
  66. // On Leopard these are GC aware
  67. // Intentionally did not include the non-barrier versions, because I couldn't
  68. // come up with a case personally where you wouldn't want to use the
  69. // barrier versions.
  70. GTM_INLINE bool OSAtomicCompareAndSwapPtrBarrier(void *predicate,
  71. void *replacement,
  72. void * volatile *theValue) {
  73. #if defined(__LP64__) && __LP64__
  74. return OSAtomicCompareAndSwap64Barrier((int64_t)predicate,
  75. (int64_t)replacement,
  76. (int64_t *)theValue);
  77. #else // defined(__LP64__) && __LP64__
  78. return OSAtomicCompareAndSwap32Barrier((int32_t)predicate,
  79. (int32_t)replacement,
  80. (int32_t *)theValue);
  81. #endif // defined(__LP64__) && __LP64__
  82. }
  83. #endif // MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  84. #endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  85. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  86. GTM_INLINE BOOL objc_atomicCompareAndSwapGlobalBarrier(id predicate,
  87. id replacement,
  88. volatile id *objectLocation) {
  89. return OSAtomicCompareAndSwapPtrBarrier(predicate,
  90. replacement,
  91. (void * volatile *)objectLocation);
  92. }
  93. GTM_INLINE BOOL objc_atomicCompareAndSwapInstanceVariableBarrier(id predicate,
  94. id replacement,
  95. volatile id *objectLocation) {
  96. return OSAtomicCompareAndSwapPtrBarrier(predicate,
  97. replacement,
  98. (void * volatile *)objectLocation);
  99. }
  100. #endif // MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5