API 0.9.5
Foundation/CPInvocation.j
Go to the documentation of this file.
00001 /*
00002  * CPInvocation.j
00003  * Foundation
00004  *
00005  * Created by Francisco Tolmasky.
00006  * Copyright 2008, 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 
00023 
00031 @implementation CPInvocation : CPObject
00032 {
00033     id                  _returnValue;
00034     CPMutableArray      _arguments;
00035     CPMethodSignature   _methodSignature;
00036 }
00037 
00038 // Creating CPInvocation Objects
00044 + (id)invocationWithMethodSignature:(CPMethodSignature)aMethodSignature
00045 {
00046     return [[self alloc] initWithMethodSignature:aMethodSignature];
00047 }
00048 
00054 - (id)initWithMethodSignature:(CPMethodSignature)aMethodSignature
00055 {
00056     self = [super init];
00057 
00058     if (self)
00059     {
00060         _arguments = [];
00061         _methodSignature = aMethodSignature;
00062     }
00063 
00064     return self;
00065 }
00066 
00067 // Configuring an Invocation Object
00072 - (void)setSelector:(SEL)aSelector
00073 {
00074     _arguments[1] = aSelector;
00075 }
00076 
00080 - (SEL)selector
00081 {
00082     return _arguments[1];
00083 }
00084 
00089 - (void)setTarget:(id)aTarget
00090 {
00091     _arguments[0] = aTarget;
00092 }
00093 
00097 - (id)target
00098 {
00099     return _arguments[0];
00100 }
00101 
00107 - (void)setArgument:(id)anArgument atIndex:(unsigned)anIndex
00108 {
00109     _arguments[anIndex] = anArgument;
00110 }
00111 
00118 - (id)argumentAtIndex:(unsigned)anIndex
00119 {
00120     return _arguments[anIndex];
00121 }
00122 
00127 - (void)setReturnValue:(id)aReturnValue
00128 {
00129     _returnValue = aReturnValue;
00130 }
00131 
00135 - (id)returnValue
00136 {
00137     return _returnValue;
00138 }
00139 
00140 // Dispatching an Invocation
00144 - (void)invoke
00145 {
00146     _returnValue = objj_msgSend.apply(objj_msgSend, _arguments);
00147 }
00148 
00153 - (void)invokeWithTarget:(id)aTarget
00154 {
00155     _arguments[0] = aTarget;
00156     _returnValue = objj_msgSend.apply(objj_msgSend, _arguments);
00157 }
00158 
00159 @end
00160 
00161 var CPInvocationArguments   = @"CPInvocationArguments",
00162     CPInvocationReturnValue = @"CPInvocationReturnValue";
00163 
00164 @implementation CPInvocation (CPCoding)
00165 
00171 - (id)initWithCoder:(CPCoder)aCoder
00172 {
00173     self = [super init];
00174 
00175     if (self)
00176     {
00177         _returnValue = [aCoder decodeObjectForKey:CPInvocationReturnValue];
00178         _arguments = [aCoder decodeObjectForKey:CPInvocationArguments];
00179     }
00180 
00181     return self;
00182 }
00183 
00188 - (void)encodeWithCoder:(CPCoder)aCoder
00189 {
00190     [aCoder encodeObject:_returnValue forKey:CPInvocationReturnValue];
00191     [aCoder encodeObject:_arguments forKey:CPInvocationArguments];
00192 }
00193 
00194 @end
 All Classes Files Functions Variables Defines