00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import "CPException.j"
00024 @import "CPInvocation.j"
00025 @import "CPString.j"
00026
00027
00028 @implementation CPProxy
00029 {
00030 }
00031
00032 + (void)load
00033 {
00034 }
00035
00036 + (void)initialize
00037 {
00038 }
00039
00040 + (Class)class
00041 {
00042 return self;
00043 }
00044
00045 + (id)alloc
00046 {
00047 return class_createInstance(self);
00048 }
00049
00050 + (BOOL)respondsToSelector:(SEL)selector
00051 {
00052 return !!class_getInstanceMethod(isa, aSelector);
00053 }
00054
00055 - (CPMethodSignature)methodSignatureForSelector:(SEL)aSelector
00056 {
00057 [CPException raise:CPInvalidArgumentException
00058 reason:@"-methodSignatureForSelector: called on abstract CPProxy class."];
00059 }
00060
00061 - (void)forwardInvocation:(CPInvocation)anInvocation
00062 {
00063 [CPException raise:CPInvalidArgumentException
00064 reason:@"-forwardInvocation: called on abstract CPProxy class."];
00065 }
00066
00067
00068 - (void)forward:(SEL)aSelector :(marg_list)args
00069 {
00070 [CPObject methodForSelector:_cmd](self, _cmd, aSelector, args);
00071 }
00072
00073 - (unsigned)hash
00074 {
00075 return [self UID];
00076 }
00077
00078 - (unsigned)UID
00079 {
00080 if (typeof self._UID === "undefined")
00081 self._UID = objj_generateObjectUID();
00082
00083 return _UID;
00084 }
00085
00086 - (BOOL)isEqual:(id)anObject
00087 {
00088 return self === object;
00089 }
00090
00091 - (id)self
00092 {
00093 return self;
00094 }
00095
00096 - (Class)class
00097 {
00098 return isa;
00099 }
00100
00101 - (Class)superclass
00102 {
00103 return class_getSuperclass(isa);
00104 }
00105
00106 - (id)performSelector:(SEL)aSelector
00107 {
00108 return objj_msgSend(self, aSelector);
00109 }
00110
00111 - (id)performSelector:(SEL)aSelector withObject:(id)anObject
00112 {
00113 return objj_msgSend(self, aSelector, anObject);
00114 }
00115
00116 - (id)performSelector:(SEL)aSelector withObject:(id)anObject withObject:(id)anotherObject
00117 {
00118 return objj_msgSend(self, aSelector, anObject, anotherObject);
00119 }
00120
00121 - (BOOL)isProxy
00122 {
00123 return YES;
00124 }
00125
00126 - (BOOL)isKindOfClass:(Class)aClass
00127 {
00128 var signature = [self methodSignatureForSelector:_cmd],
00129 invocation = [CPInvocation invocationWithMethodSignature:signature];
00130
00131 [self forwardInvocation:invocation];
00132
00133 return [invocation returnValue];
00134 }
00135
00136 -(BOOL)isMemberOfClass:(Class)aClass
00137 {
00138 var signature = [self methodSignatureForSelector:_cmd],
00139 invocation = [CPInvocation invocationWithMethodSignature:signature];
00140
00141 [self forwardInvocation:invocation];
00142
00143 return [invocation returnValue];
00144 }
00145
00146 - (BOOL)respondsToSelector:(SEL)aSelector
00147 {
00148 var signature = [self methodSignatureForSelector:_cmd],
00149 invocation = [CPInvocation invocationWithMethodSignature:signature];
00150
00151 [self forwardInvocation:invocation];
00152
00153 return [invocation returnValue];
00154 }
00155
00156 - (CPString)description
00157 {
00158 return "<" + class_getName(isa) + " 0x" + [CPString stringWithHash:[self UID]] + ">";
00159 }
00160
00161 @end