-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSObject+DIInvocation.h
More file actions
86 lines (61 loc) · 2.73 KB
/
NSObject+DIInvocation.h
File metadata and controls
86 lines (61 loc) · 2.73 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
// (c) 2010, Deep IT, Uncle MiF
// COMMON FILE: Common
#import <Foundation/Foundation.h>
// + NSInvocationBuilder (the private root class) functionality
@interface DIInvocationProducer
{
Class isa;
id target;
NSInvocation* *ivcRef;
NSInvocation * invocation;
#ifndef __OBJC_GC__
id refHelper;// for ARP-support
#endif
}
+(id)producerForObject:(id)aTarget;
+(id)producerForObject:(id)aTarget outInvocation:(NSInvocation* *)ivcRef;
-(NSInvocation*)producedInvocation;
-(oneway void)release;
-(id)retain;
-(id)autorelease;
-(NSUInteger)retainCount;
@end
@interface NSObject (DIInvocation)
+(NSInvocation*)invocationForSelector:(SEL)aSelector;
-(NSInvocation*)invocationForSelector:(SEL)aSelector;
+(NSInvocation*)invocationForSelector:(SEL)aSelector withArguments:(void*)first,...;// first is argument after self and _cmd (real internal index is 2)
-(NSInvocation*)invocationForSelector:(SEL)aSelector withArguments:(void*)first,...;// first is argument after self and _cmd (real internal index is 2)
+(id/* DIInvocationProducer* */)producedInvocation:(NSInvocation* *)ivcRef;// just "call" a method right with arguments from me to return NSInvocation instance by ref
-(id/* DIInvocationProducer* */)producedInvocation:(NSInvocation* *)ivcRef;// NSInvocation * readyForMagic; [[self returnInvocation:&readyForMagic] fooA:argA fooB:argB]; [readyForMagic invoke];
+(id/* DIInvocationProducer* */)invocationProducer;
-(id/* DIInvocationProducer* */)invocationProducer;
@end
/*
Usage demo:
#import "NSObject+DIInvocation.h"
#import <Foundation/Foundation.h>
@interface Foo:NSObject
@end
@implementation Foo
+(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); }
@end
int main()
{
NSAutoreleasePool * arp = [NSAutoreleasePool new];
[[Foo invocationForSelector:@selector(noArgs)] invoke];
Foo * foo = [[Foo new] autorelease];
[[foo invocationForSelector:@selector(noArgs)] invoke];
int a = 11, b = 12, c = 13;
[[Foo invocationForSelector:@selector(withArgOne:andArgTwo:) withArguments:&a, &b, nil] invoke];
[[foo invocationForSelector:@selector(withArgOne:andArgTwo:) withArguments:&a, &b, nil] invoke];
[[foo invocationForSelector:@selector(withArgOne:andArgTwo:) withArguments:&a, &b] invoke];// nil is optional
[[foo invocationForSelector:@selector(withArgOne:andArgTwo:) withArguments:&a, &b, &c] invoke];// no more arguments than it needs
NSInvocation * magicInvocation;
[[[foo producedInvocation:&magicInvocation] withArgOne:a andArgTwo:b], magicInvocation invoke];// magic rocks
[arp drain];
return 0;
}
*/