-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathivcDemoAppDelegate.m
More file actions
175 lines (144 loc) · 4.79 KB
/
ivcDemoAppDelegate.m
File metadata and controls
175 lines (144 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//
// ivcDemoAppDelegate.m
// ivcDemo
//
// Created by Uncle MiF on 4/19/10.
// Copyright 2010 Deep IT. All rights reserved.
//
#import "ivcDemoAppDelegate.h"
#import "NSObject+DIInvocation.h"
@implementation ivcDemoAppDelegate
@synthesize window;
-(NSString*)description2
{
return @"hey...";
}
-(void)test2
{
NSLog(@"%s",__PRETTY_FUNCTION__);
}
-(float)addVal:(float)val1 toVal:(float)val2
{
return val1 + val2;
}
-(int)printer:(const char*)fmt,...
{
va_list list;
va_start(list,fmt);
vprintf(fmt,list);
va_end(list);
return 13;
}
-(double)summer:(double)first,...
{
double sum = first;
va_list list;
va_start(list,first);
double cur;
while((cur = va_arg(list,double)))
{
sum += cur;
NSLog(@"+ %lf -> %lf",cur,sum);
}
va_end(list);
return sum;
}
+(void)noArgs{ puts(__PRETTY_FUNCTION__); }
-(void)noArgs{ puts(__PRETTY_FUNCTION__); }
+(void)withArgOne:(int)arg1 andArgTwo:(int)arg2{ printf("%s: %i %i\n",__PRETTY_FUNCTION__,arg1,arg2); }
-(void)withArgOne:(int)arg1 andArgTwo:(int)arg2{ printf("%s: %i %i\n",__PRETTY_FUNCTION__,arg1,arg2); }
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[[[self class] invocationForSelector:@selector(noArgs)] invoke];
[[self invocationForSelector:@selector(noArgs)] invoke];
int a = 11, b = 12, c = 13;
[[[self class] invocationForSelector:@selector(withArgOne:andArgTwo:) withArguments:&a, &b, nil] invoke];
[[self invocationForSelector:@selector(withArgOne:andArgTwo:) withArguments:&a, &b, nil] invoke];
[[self invocationForSelector:@selector(withArgOne:andArgTwo:) withArguments:&a, &b] invoke];// nil is optional
[[self invocationForSelector:@selector(withArgOne:andArgTwo:) withArguments:&a, &b, &c] invoke];// no more arguments than it needs
NSInvocation * ivc;
id ivb = [self producedInvocation:&ivc];
[ivb description2];
NSLog(@"ivb: %p",ivb);
NSLog(@"ivc: %@",ivc);
[ivc invoke];
id result;
result = nil, [ivc getReturnValue:&result];
NSLog(@"result: %@",result);
[[DIInvocationProducer producerForObject:self outInvocation:&ivc] test2];
NSLog(@"ivc: %@",ivc);
[ivc invoke];
id ivcFactory = [self invocationProducer];
[ivcFactory test2];
ivc = [ivcFactory producedInvocation];
NSLog(@"ivc: %@",ivc);
[ivc invoke];
ivcFactory = [DIInvocationProducer producerForObject:self];
[ivcFactory description];
ivc = [ivcFactory producedInvocation];
NSLog(@"ivc: %@",ivc);
[ivc invoke];
result = nil, [ivc getReturnValue:&result];
NSLog(@"result: %@",result);
ivcFactory = [[self class] invocationProducer];
[ivcFactory description];
ivc = [ivcFactory producedInvocation];
NSLog(@"ivc: %@",ivc);
[ivc invoke];
result = nil, [ivc getReturnValue:&result];
NSLog(@"result: %@",result);
[[[self class] producedInvocation:&ivc] description];
NSLog(@"ivc: %@",ivc);
[ivc invoke];
result = nil, [ivc getReturnValue:&result];
NSLog(@"result: %@",result);
[[self producedInvocation:&ivc] addVal:2.0 toVal:40.0];
NSLog(@"ivc: %@",ivc);
[ivc invoke];
float fResult;
fResult = 0.0, [ivc getReturnValue:&fResult];
NSLog(@"result: %f",fResult);
ivcFactory = [DIInvocationProducer producerForObject:nil];
[ivcFactory description];
ivc = [ivcFactory producedInvocation];
NSLog(@"ivc: %@",ivc);
[ivc invoke];
result = nil, [ivc getReturnValue:&result];
NSLog(@"result: %@",result);
[self printer:"%s, hi!\n","World"];
[[[self producedInvocation:&ivc] printer:"%s, test!\n","variable ivc..."], ivc invoke];
int iResult;
iResult = 0; [ivc getReturnValue:&iResult];
NSLog(@"result: %i",iResult);
NSLog(@"expecting: %lf",[self summer:(double)11.0,(double)2,(double)3,(double)4,(double)22,(double)0]);
[[self producedInvocation:&ivc] summer:(double)11,(double)2,(double)3,(double)4,(double)22,(double)0];
[self performSelectorInBackground:@selector(backgroundInvoke:) withObject:ivc];
NSMutableString * str = [@"str" mutableCopy];
[[[NSString producedInvocation:&ivc] stringWithString:str],
[ivc retainArguments], [str release],
ivc invoke];
result = nil; [ivc getReturnValue:&result];
NSLog(@"result: %@",result);
char * cStr = strdup("cStr");
[[[NSString producedInvocation:&ivc] stringWithCString:cStr], [ivc retainArguments], (*cStr = 0), free(cStr), ivc invoke];
result = nil; [ivc getReturnValue:&result];
NSLog(@"result: %@",result);
int i;
for (i = 0; i < 100; i++)
{
id iProducer = [[[self invocationProducer] retain] autorelease];
[iProducer summer:(double)11,(double)2,(double)3,(double)4,(double)22,(double)0];
[iProducer producedInvocation:&ivc];
[self performSelectorInBackground:@selector(backgroundInvoke:) withObject:ivc];
}
}
-(void)backgroundInvoke:(NSInvocation*)ivc
{
NSAutoreleasePool * arp = [NSAutoreleasePool new];
double dResult;
[ivc invoke];
dResult = 0; [ivc getReturnValue:&dResult];
NSLog(@"%s: result: %lf",__PRETTY_FUNCTION__,dResult);
[arp drain];
}
@end