![]() |
API 0.9.5
|
00001 /* 00002 * CPProxy.j 00003 * Foundation 00004 * 00005 * Created by Francisco Tolmasky. 00006 * Copyright 2009, 280 North, Inc. 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public 00010 * License as published by the Free Software Foundation; either 00011 * version 2.1 of the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 @implementation CPProxy 00023 { 00024 id __doxygen__; 00025 } 00026 00027 + (void)load 00028 { 00029 } 00030 00031 + (void)initialize 00032 { 00033 } 00034 00035 + (Class)class 00036 { 00037 return self; 00038 } 00039 00040 + (id)alloc 00041 { 00042 return class_createInstance(self); 00043 } 00044 00045 + (BOOL)respondsToSelector:(SEL)selector 00046 { 00047 return !!class_getInstanceMethod(isa, aSelector); 00048 } 00049 00050 - (CPMethodSignature)methodSignatureForSelector:(SEL)aSelector 00051 { 00052 [CPException raise:CPInvalidArgumentException 00053 reason:@"-methodSignatureForSelector: called on abstract CPProxy class."]; 00054 } 00055 00056 - (void)forwardInvocation:(CPInvocation)anInvocation 00057 { 00058 [CPException raise:CPInvalidArgumentException 00059 reason:@"-forwardInvocation: called on abstract CPProxy class."]; 00060 } 00061 00062 // FIXME: This should be moved to the runtime? 00063 - (void)forward:(SEL)aSelector :(marg_list)args 00064 { 00065 return [CPObject methodForSelector:_cmd](self, _cmd, aSelector, args); 00066 } 00067 00068 - (unsigned)hash 00069 { 00070 return [self UID]; 00071 } 00072 00073 - (unsigned)UID 00074 { 00075 if (typeof self._UID === "undefined") 00076 self._UID = objj_generateObjectUID(); 00077 00078 return _UID; 00079 } 00080 00081 - (BOOL)isEqual:(id)anObject 00082 { 00083 return self === object; 00084 } 00085 00086 - (id)self 00087 { 00088 return self; 00089 } 00090 00091 - (Class)class 00092 { 00093 return isa; 00094 } 00095 00096 - (Class)superclass 00097 { 00098 return class_getSuperclass(isa); 00099 } 00100 00101 - (id)performSelector:(SEL)aSelector 00102 { 00103 return objj_msgSend(self, aSelector); 00104 } 00105 00106 - (id)performSelector:(SEL)aSelector withObject:(id)anObject 00107 { 00108 return objj_msgSend(self, aSelector, anObject); 00109 } 00110 00111 - (id)performSelector:(SEL)aSelector withObject:(id)anObject withObject:(id)anotherObject 00112 { 00113 return objj_msgSend(self, aSelector, anObject, anotherObject); 00114 } 00115 00116 - (BOOL)isProxy 00117 { 00118 return YES; 00119 } 00120 00121 - (BOOL)isKindOfClass:(Class)aClass 00122 { 00123 var signature = [self methodSignatureForSelector:_cmd], 00124 invocation = [CPInvocation invocationWithMethodSignature:signature]; 00125 00126 [self forwardInvocation:invocation]; 00127 00128 return [invocation returnValue]; 00129 } 00130 00131 - (BOOL)isMemberOfClass:(Class)aClass 00132 { 00133 var signature = [self methodSignatureForSelector:_cmd], 00134 invocation = [CPInvocation invocationWithMethodSignature:signature]; 00135 00136 [self forwardInvocation:invocation]; 00137 00138 return [invocation returnValue]; 00139 } 00140 00141 - (BOOL)respondsToSelector:(SEL)aSelector 00142 { 00143 var signature = [self methodSignatureForSelector:_cmd], 00144 invocation = [CPInvocation invocationWithMethodSignature:signature]; 00145 00146 [self forwardInvocation:invocation]; 00147 00148 return [invocation returnValue]; 00149 } 00150 00151 - (CPString)description 00152 { 00153 return "<" + class_getName(isa) + " 0x" + [CPString stringWithHash:[self UID]] + ">"; 00154 } 00155 00156 @end