PageRenderTime 25ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 1ms

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