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
00030 @implementation CPInvocation : CPObject
00031 {
00032 id _returnValue;
00033 CPMutableArray _arguments;
00034 CPMethodSignature _methodSignature;
00035 }
00036
00037
00043 + (id)invocationWithMethodSignature:(CPMethodSignature)aMethodSignature
00044 {
00045 return [[self alloc] initWithMethodSignature:aMethodSignature];
00046 }
00047
00053 - (id)initWithMethodSignature:(CPMethodSignature)aMethodSignature
00054 {
00055 self = [super init];
00056
00057 if (self)
00058 {
00059 _arguments = [];
00060 _methodSignature = aMethodSignature;
00061 }
00062
00063 return self;
00064 }
00065
00066
00071 - (void)setSelector:(SEL)aSelector
00072 {
00073 _arguments[1] = aSelector;
00074 }
00075
00079 - (SEL)selector
00080 {
00081 return _arguments[1];
00082 }
00083
00088 - (void)setTarget:(id)aTarget
00089 {
00090 _arguments[0] = aTarget;
00091 }
00092
00096 - (id)target
00097 {
00098 return _arguments[0];
00099 }
00100
00106 - (void)setArgument:(id)anArgument atIndex:(unsigned)anIndex
00107 {
00108 _arguments[anIndex] = anArgument;
00109 }
00110
00117 - (id)argumentAtIndex:(unsigned)anIndex
00118 {
00119 return _arguments[anIndex];
00120 }
00121
00126 - (void)setReturnValue:(id)aReturnValue
00127 {
00128 _returnValue = aReturnValue;
00129 }
00130
00134 - (id)returnValue
00135 {
00136 return _returnValue;
00137 }
00138
00139
00143 - (void)invoke
00144 {
00145 _returnValue = objj_msgSend.apply(objj_msgSend, _arguments);
00146 }
00147
00152 - (void)invokeWithTarget:(id)aTarget
00153 {
00154 _arguments[0] = aTarget;
00155 _returnValue = objj_msgSend.apply(objj_msgSend, _arguments);
00156 }
00157
00158 @end
00159
00160 var CPInvocationArguments = @"CPInvocationArguments",
00161 CPInvocationReturnValue = @"CPInvocationReturnValue";
00162
00163 @implementation CPInvocation (CPCoding)
00164
00170 - (id)initWithCoder:(CPCoder)aCoder
00171 {
00172 self = [super init];
00173
00174 if (self)
00175 {
00176 _returnValue = [aCoder decodeObjectForKey:CPInvocationReturnValue];
00177 _arguments = [aCoder decodeObjectForKey:CPInvocationArguments];
00178 }
00179
00180 return self;
00181 }
00182
00187 - (void)encodeWithCoder:(CPCoder)aCoder
00188 {
00189 [aCoder encodeObject:_returnValue forKey:CPInvocationReturnValue];
00190 [aCoder encodeObject:_arguments forKey:CPInvocationArguments];
00191 }
00192
00193 @end