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
00034 @implementation CPInvocation : CPObject
00035 {
00036 id _returnValue;
00037 CPMutableArray _arguments;
00038 CPMethodSignature _methodSignature;
00039 }
00040
00041
00047 + (id)invocationWithMethodSignature:(CPMethodSignature)aMethodSignature
00048 {
00049 return [[self alloc] initWithMethodSignature:aMethodSignature];
00050 }
00051
00057 - (id)initWithMethodSignature:(CPMethodSignature)aMethodSignature
00058 {
00059 self = [super init];
00060
00061 if (self)
00062 {
00063 _arguments = [];
00064 _methodSignature = aMethodSignature;
00065 }
00066
00067 return self;
00068 }
00069
00070
00075 - (void)setSelector:(SEL)aSelector
00076 {
00077 _arguments[1] = aSelector;
00078 }
00079
00083 - (SEL)selector
00084 {
00085 return _arguments[1];
00086 }
00087
00092 - (void)setTarget:(id)aTarget
00093 {
00094 _arguments[0] = aTarget;
00095 }
00096
00100 - (id)target
00101 {
00102 return _arguments[0];
00103 }
00104
00110 - (void)setArgument:(id)anArgument atIndex:(unsigned)anIndex
00111 {
00112 _arguments[anIndex] = anArgument;
00113 }
00114
00121 - (id)argumentAtIndex:(unsigned)anIndex
00122 {
00123 return _arguments[anIndex];
00124 }
00125
00130 - (void)setReturnValue:(id)aReturnValue
00131 {
00132 _returnValue = aReturnValue;
00133 }
00134
00138 - (id)returnValue
00139 {
00140 return _returnValue;
00141 }
00142
00143
00147 - (void)invoke
00148 {
00149 _returnValue = objj_msgSend.apply(objj_msgSend, _arguments);
00150 }
00151
00156 - (void)invokeWithTarget:(id)aTarget
00157 {
00158 _arguments[0] = aTarget;
00159 _returnValue = objj_msgSend.apply(objj_msgSend, _arguments);
00160 }
00161
00162 @end
00163
00164 var CPInvocationArguments = @"CPInvocationArguments",
00165 CPInvocationReturnValue = @"CPInvocationReturnValue";
00166
00167 @implementation CPInvocation (CPCoding)
00168
00174 - (id)initWithCoder:(CPCoder)aCoder
00175 {
00176 self = [super init];
00177
00178 if (self)
00179 {
00180 _returnValue = [aCoder decodeObjectForKey:CPInvocationReturnValue];
00181 _arguments = [aCoder decodeObjectForKey:CPInvocationArguments];
00182 }
00183
00184 return self;
00185 }
00186
00191 - (void)encodeWithCoder:(CPCoder)aCoder
00192 {
00193 [aCoder encodeObject:_returnValue forKey:CPInvocationReturnValue];
00194 [aCoder encodeObject:_arguments forKey:CPInvocationArguments];
00195 }
00196
00197 @end