API  0.9.10
CPInvocation.j
Go to the documentation of this file.
1 /*
2  * CPInvocation.j
3  * Foundation
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2008, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 
30 @implementation CPInvocation : CPObject
31 {
32  id _returnValue;
33  CPMutableArray _arguments;
34  CPMethodSignature _methodSignature;
35 }
36 
37 // Creating CPInvocation Objects
43 + (id)invocationWithMethodSignature:(CPMethodSignature)aMethodSignature
44 {
45  return [[self alloc] initWithMethodSignature:aMethodSignature];
46 }
47 
53 - (id)initWithMethodSignature:(CPMethodSignature)aMethodSignature
54 {
55  self = [super init];
56 
57  if (self)
58  {
59  _arguments = [];
60  _methodSignature = aMethodSignature;
61  }
62 
63  return self;
64 }
65 
66 // Configuring an Invocation Object
71 - (void)setSelector:(SEL)aSelector
72 {
73  _arguments[1] = aSelector;
74 }
75 
79 - (SEL)selector
80 {
81  return _arguments[1];
82 }
83 
88 - (void)setTarget:(id)aTarget
89 {
90  _arguments[0] = aTarget;
91 }
92 
96 - (id)target
97 {
98  return _arguments[0];
99 }
100 
106 - (void)setArgument:(id)anArgument atIndex:(CPUInteger)anIndex
107 {
108  _arguments[anIndex] = anArgument;
109 }
110 
117 - (id)argumentAtIndex:(CPUInteger)anIndex
118 {
119  return _arguments[anIndex];
120 }
121 
126 - (void)setReturnValue:(id)aReturnValue
127 {
128  _returnValue = aReturnValue;
129 }
130 
135 {
136  return _returnValue;
137 }
138 
139 // Dispatching an Invocation
143 - (void)invoke
144 {
145  _returnValue = objj_msgSend.apply(objj_msgSend, _arguments);
146 }
147 
152 - (void)invokeWithTarget:(id)aTarget
153 {
154  _arguments[0] = aTarget;
155  _returnValue = objj_msgSend.apply(objj_msgSend, _arguments);
156 }
157 
158 @end
159 
160 var CPInvocationArguments = @"CPInvocationArguments",
161  CPInvocationReturnValue = @"CPInvocationReturnValue";
162 
163 @implementation CPInvocation (CPCoding)
164 
170 - (id)initWithCoder:(CPCoder)aCoder
171 {
172  self = [super init];
173 
174  if (self)
175  {
176  _returnValue = [aCoder decodeObjectForKey:CPInvocationReturnValue];
177  _arguments = [aCoder decodeObjectForKey:CPInvocationArguments];
178  }
179 
180  return self;
181 }
182 
187 - (void)encodeWithCoder:(CPCoder)aCoder
188 {
189  [aCoder encodeObject:_returnValue forKey:CPInvocationReturnValue];
190  [aCoder encodeObject:_arguments forKey:CPInvocationArguments];
191 }
192 
193 @end
An object representation of a message.
Definition: CPInvocation.h:2
var CPInvocationArguments
Definition: CPInvocation.j:160
Defines methods for use when archiving & restoring (enc/decoding).
Definition: CPCoder.h:2
id init()
Definition: CPObject.j:145
var CPInvocationReturnValue
Definition: CPInvocation.j:161
id initWithMethodSignature:(CPMethodSignature aMethodSignature)
Definition: CPInvocation.j:53
id alloc()
Definition: CPObject.j:130