API  0.9.6
 All Classes Files Functions Variables Macros Groups Pages
CPProxy.j
Go to the documentation of this file.
1 /*
2  * CPProxy.j
3  * Foundation
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2009, 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 @implementation CPProxy
23 {
24  id __doxygen__;
25 }
26 
27 + (void)load
28 {
29 }
30 
31 + (void)initialize
32 {
33 }
34 
35 + (Class)class
36 {
37  return self;
38 }
39 
40 + (id)alloc
41 {
42  return class_createInstance(self);
43 }
44 
45 + (BOOL)respondsToSelector:(SEL)selector
46 {
47  return !!class_getInstanceMethod(isa, aSelector);
48 }
49 
50 - (CPMethodSignature)methodSignatureForSelector:(SEL)aSelector
51 {
52  [CPException raise:CPInvalidArgumentException
53  reason:@"-methodSignatureForSelector: called on abstract CPProxy class."];
54 }
55 
56 - (void)forwardInvocation:(CPInvocation)anInvocation
57 {
58  [CPException raise:CPInvalidArgumentException
59  reason:@"-forwardInvocation: called on abstract CPProxy class."];
60 }
61 
62 // FIXME: This should be moved to the runtime?
63 - (void)forward:(SEL)aSelector :(marg_list)args
64 {
65  return [CPObject methodForSelector:_cmd](self, _cmd, aSelector, args);
66 }
67 
68 - (unsigned)hash
69 {
70  return [self UID];
71 }
72 
73 - (unsigned)UID
74 {
75  if (typeof self._UID === "undefined")
76  self._UID = objj_generateObjectUID();
77 
78  return _UID;
79 }
80 
81 - (BOOL)isEqual:(id)anObject
82 {
83  return self === object;
84 }
85 
86 - (id)self
87 {
88  return self;
89 }
90 
91 - (Class)class
92 {
93  return isa;
94 }
95 
96 - (Class)superclass
97 {
98  return class_getSuperclass(isa);
99 }
100 
101 - (id)performSelector:(SEL)aSelector
102 {
103  return objj_msgSend(self, aSelector);
104 }
105 
106 - (id)performSelector:(SEL)aSelector withObject:(id)anObject
107 {
108  return objj_msgSend(self, aSelector, anObject);
109 }
110 
111 - (id)performSelector:(SEL)aSelector withObject:(id)anObject withObject:(id)anotherObject
112 {
113  return objj_msgSend(self, aSelector, anObject, anotherObject);
114 }
115 
116 - (BOOL)isProxy
117 {
118  return YES;
119 }
120 
121 - (BOOL)isKindOfClass:(Class)aClass
122 {
123  var signature = [self methodSignatureForSelector:_cmd],
124  invocation = [CPInvocation invocationWithMethodSignature:signature];
125 
126  [self forwardInvocation:invocation];
127 
128  return [invocation returnValue];
129 }
130 
131 - (BOOL)isMemberOfClass:(Class)aClass
132 {
133  var signature = [self methodSignatureForSelector:_cmd],
134  invocation = [CPInvocation invocationWithMethodSignature:signature];
135 
136  [self forwardInvocation:invocation];
137 
138  return [invocation returnValue];
139 }
140 
141 - (BOOL)respondsToSelector:(SEL)aSelector
142 {
143  var signature = [self methodSignatureForSelector:_cmd],
144  invocation = [CPInvocation invocationWithMethodSignature:signature];
145 
146  [self forwardInvocation:invocation];
147 
148  return [invocation returnValue];
149 }
150 
152 {
153  return "<" + class_getName(isa) + " 0x" + [CPString stringWithHash:[self UID]] + ">";
154 }
155 
156 @end