00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 @import "CPObject.j"
00024 @import "CPException.j"
00025
00026
00032 @implementation CPInvocation : CPObject
00033 {
00034 id _returnValue;
00035 CPMutableArray _arguments;
00036 CPMethodSignature _methodSignature;
00037 }
00038
00039
00045 + (id)invocationWithMethodSignature:(CPMethodSignature)aMethodSignature
00046 {
00047 return [[self alloc] initWithMethodSignature:aMethodSignature];
00048 }
00049
00055 - (id)initWithMethodSignature:(CPMethodSignature)aMethodSignature
00056 {
00057 self = [super init];
00058
00059 if (self)
00060 {
00061 _arguments = [];
00062 _methodSignature = aMethodSignature;
00063 }
00064
00065 return self;
00066 }
00067
00068
00073 - (void)setSelector:(SEL)aSelector
00074 {
00075 _arguments[1] = aSelector;
00076 }
00077
00081 - (SEL)selector
00082 {
00083 return _arguments[1];
00084 }
00085
00090 - (void)setTarget:(id)aTarget
00091 {
00092 _arguments[0] = aTarget;
00093 }
00094
00098 - (id)target
00099 {
00100 return _arguments[0];
00101 }
00102
00108 - (void)setArgument:(id)anArgument atIndex:(unsigned)anIndex
00109 {
00110 _arguments[anIndex] = anArgument;
00111 }
00112
00119 - (id)argumentAtIndex:(unsigned)anIndex
00120 {
00121 return _arguments[anIndex];
00122 }
00123
00128 - (void)setReturnValue:(id)aReturnValue
00129 {
00130 _returnValue = aReturnValue;
00131 }
00132
00136 - (id)returnValue
00137 {
00138 return _returnValue;
00139 }
00140
00141
00145 - (void)invoke
00146 {
00147 _returnValue = objj_msgSend.apply(objj_msgSend, _arguments);
00148 }
00149
00154 - (void)invokeWithTarget:(id)aTarget
00155 {
00156 _arguments[0] = aTarget;
00157 _returnValue = objj_msgSend.apply(objj_msgSend, _arguments);
00158 }
00159
00160 @end
00161
00162 var CPInvocationArguments = @"CPInvocationArguments",
00163 CPInvocationReturnValue = @"CPInvocationReturnValue";
00164
00165 @implementation CPInvocation (CPCoding)
00166
00172 - (id)initWithCoder:(CPCoder)aCoder
00173 {
00174 self = [super init];
00175
00176 if (self)
00177 {
00178 _returnValue = [aCoder decodeObjectForKey:CPInvocationReturnValue];
00179 _arguments = [aCoder decodeObjectForKey:CPInvocationArguments];
00180 }
00181
00182 return self;
00183 }
00184
00189 - (void)encodeWithCoder:(CPCoder)aCoder
00190 {
00191 [aCoder encodeObject:_returnValue forKey:CPInvocationReturnValue];
00192 [aCoder encodeObject:_arguments forKey:CPInvocationArguments];
00193 }
00194
00195 @end