PageRenderTime 18ms CodeModel.GetById 11ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/Foundation/GTMObjC2Runtime.h

http://macfuse.googlecode.com/
C++ Header | 113 lines | 67 code | 11 blank | 35 comment | 3 complexity | 9a2cc3153ccac5c3248e315d18b9648a 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/message.h>
 46#import <objc/runtime.h>
 47#else
 48#import <objc/objc-runtime.h>
 49#import <objc/Object.h>
 50#endif
 51
 52#import <libkern/OSAtomic.h>
 53
 54#if GTM_MACOS_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
 55#import "objc/Protocol.h"
 56
 57OBJC_EXPORT Class object_getClass(id obj);
 58OBJC_EXPORT const char *class_getName(Class cls);
 59OBJC_EXPORT BOOL class_conformsToProtocol(Class cls, Protocol *protocol);
 60OBJC_EXPORT BOOL class_respondsToSelector(Class cls, SEL sel);
 61OBJC_EXPORT Class class_getSuperclass(Class cls);
 62OBJC_EXPORT Method *class_copyMethodList(Class cls, unsigned int *outCount);
 63OBJC_EXPORT SEL method_getName(Method m);
 64OBJC_EXPORT void method_exchangeImplementations(Method m1, Method m2);
 65OBJC_EXPORT IMP method_getImplementation(Method method);
 66OBJC_EXPORT IMP method_setImplementation(Method method, IMP imp);
 67OBJC_EXPORT struct objc_method_description protocol_getMethodDescription(Protocol *p,
 68                                                                         SEL aSel,
 69                                                                         BOOL isRequiredMethod,
 70                                                                         BOOL isInstanceMethod);
 71OBJC_EXPORT BOOL sel_isEqual(SEL lhs, SEL rhs);
 72
 73// If building for 10.4 but using the 10.5 SDK, don't include these.
 74#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
 75// atomics
 76// On Leopard these are GC aware
 77// Intentionally did not include the non-barrier versions, because I couldn't
 78// come up with a case personally where you wouldn't want to use the
 79// barrier versions.
 80GTM_INLINE bool OSAtomicCompareAndSwapPtrBarrier(void *predicate,
 81                                                 void *replacement,
 82                                                 void * volatile *theValue) {
 83#if defined(__LP64__) && __LP64__
 84  return OSAtomicCompareAndSwap64Barrier((int64_t)predicate,
 85                                         (int64_t)replacement,
 86                                         (int64_t *)theValue);
 87#else  // defined(__LP64__) && __LP64__
 88  return OSAtomicCompareAndSwap32Barrier((int32_t)predicate,
 89                                         (int32_t)replacement,
 90                                         (int32_t *)theValue);
 91#endif  // defined(__LP64__) && __LP64__
 92}
 93
 94#endif  // MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
 95#endif  // GTM_MACOS_SDK && (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5)
 96
 97#if GTM_MACOS_SDK && (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)
 98
 99GTM_INLINE BOOL objc_atomicCompareAndSwapGlobalBarrier(id predicate,
100                                                       id replacement,
101                                                       volatile id *objectLocation) {
102  return OSAtomicCompareAndSwapPtrBarrier(predicate,
103                                          replacement,
104                                          (void * volatile *)objectLocation);
105}
106GTM_INLINE BOOL objc_atomicCompareAndSwapInstanceVariableBarrier(id predicate,
107                                                                 id replacement,
108                                                                 volatile id *objectLocation) {
109  return OSAtomicCompareAndSwapPtrBarrier(predicate,
110                                          replacement,
111                                          (void * volatile *)objectLocation);
112}
113#endif  // GTM_MACOS_SDK && (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5)