1
|
1 /**
|
|
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
|
|
3 * Authors: Jacob Carlborg
|
|
4 * Version: Initial created: Feb 1, 2009
|
|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
|
|
6 */
|
|
7 module dstep.objc.objc;
|
|
8
|
|
9 import dstep.internal.String;
|
|
10 import dstep.internal.Types;
|
|
11 import bindings = dstep.objc.bindings;
|
|
12 import dstep.objc.message;
|
|
13 import dstep.objc.runtime;
|
|
14
|
|
15 import mambo.io;
|
|
16
|
|
17 alias objc_object* id;
|
|
18 alias objc_class* Class;
|
|
19 alias objc_selector* SEL;
|
|
20 alias extern (C) id function(id self, SEL op, ...) IMP;
|
|
21 alias bool BOOL;
|
|
22 alias char* STR;
|
|
23
|
|
24 alias typeof(null) Nil;
|
|
25 alias typeof(null) nil;
|
|
26
|
|
27 alias c_long arith_t;
|
|
28 alias c_ulong uarith_t;
|
|
29
|
|
30 const bool YES = true;
|
|
31 const bool NO = false;
|
|
32
|
|
33 struct objc_object
|
|
34 {
|
|
35 Class isa;
|
|
36
|
|
37
|
|
38
|
|
39 // D Extensions:
|
|
40
|
|
41 string getClassName ()
|
|
42 {
|
|
43 return fromStringz(bindings.object_getClassName(this));
|
|
44 }
|
|
45
|
|
46 Ivar setInstanceVariable (T, string name) (T value)
|
|
47 {
|
|
48 return bindings.object_setInstanceVariable(this, name.ptr, value);
|
|
49 }
|
|
50
|
|
51 Ivar getInstanceVariable (T, string name) (out T outValue)
|
|
52 {
|
|
53 return bindings.object_getInstanceVariable(this, name.ptr, &outValue);
|
|
54 }
|
|
55
|
|
56 objc_property_t* getProperty (string name, bool isRequiredProperty, bool isInstanceProperty)
|
|
57 {
|
|
58 return bindings.protocol_getProperty(this, name.toStringz(), isRequiredProperty, isInstanceProperty);
|
|
59 }
|
|
60
|
|
61 objc_property_t* copyPropertyList (out uint outCount)
|
|
62 {
|
|
63 return bindings.protocol_copyPropertyList(this, &outCount);
|
|
64 }
|
|
65
|
|
66 Protocol** copyProtocolList (out uint outCount)
|
|
67 {
|
|
68 return bindings.protocol_copyProtocolList(this, &outCount);
|
|
69 }
|
|
70
|
|
71 string getName ()
|
|
72 {
|
|
73 return fromStringz(bindings.protocol_getName(this));
|
|
74 }
|
|
75
|
|
76 objc_method_description* copyMethodDescriptionList (bool isRequiredMethod, bool isInstanceMethod, out uint outCount)
|
|
77 {
|
|
78 return bindings.protocol_copyMethodDescriptionList(this, isRequiredMethod, isInstanceMethod, &outCount);
|
|
79 }
|
|
80
|
|
81 id copy (size_t size)
|
|
82 {
|
|
83 return bindings.object_copy(this, size);
|
|
84 }
|
|
85
|
|
86 id dispose ()
|
|
87 {
|
|
88 return bindings.object_dispose(this);
|
|
89 }
|
|
90
|
|
91 Class getClass ()
|
|
92 {
|
|
93 return bindings.object_getClass(this);
|
|
94 }
|
|
95
|
|
96 Class setClass (Class cls)
|
|
97 {
|
|
98 return bindings.object_setClass(this, cls);
|
|
99 }
|
|
100
|
|
101 void* getIndexedIvars ()
|
|
102 {
|
|
103 return bindings.object_getIndexedIvars(this);
|
|
104 }
|
|
105
|
|
106 id getIvar (Ivar ivar)
|
|
107 {
|
|
108 return bindings.object_getIvar(this, ivar);
|
|
109 }
|
|
110
|
|
111 void setIvar (Ivar ivar, Protocol* value)
|
|
112 {
|
|
113 return bindings.object_setIvar(this, ivar, value);
|
|
114 }
|
|
115
|
|
116 bool conformsToProtocol (Protocol* other)
|
|
117 {
|
|
118 return bindings.protocol_conformsToProtocol(this, other);
|
|
119 }
|
|
120
|
|
121 bool isEqual (id other)
|
|
122 {
|
|
123 return bindings.protocol_isEqual(this, other);
|
|
124 }
|
|
125
|
|
126 objc_method_description getMethodDescription (SEL aSel, bool isRequiredMethod, bool isInstanceMethod)
|
|
127 {
|
|
128 return bindings.protocol_getMethodDescription(this, aSel, isRequiredMethod, isInstanceMethod);
|
|
129 }
|
|
130
|
|
131
|
|
132
|
|
133 // message.h
|
|
134
|
|
135 R msgSend (R = id, ARGS...) (SEL op, ARGS args)
|
|
136 {
|
|
137 return (cast(R function (id, SEL, ARGS))&bindings.objc_msgSend)(this, op, args);
|
|
138 }
|
|
139
|
|
140 void msgSend_stret (T, ARGS...) (out T stretAddr, SEL op, ARGS args)
|
|
141 {
|
|
142 if (T.sizeof > STRUCT_SIZE_LIMIT)
|
|
143 (cast(void function (T*, id, SEL, ARGS...))&bindings.objc_msgSend_stret)(&stretAddr, this, op, args);
|
|
144
|
|
145 else
|
|
146 stretAddr = (*cast(T function (id, SEL, ARGS...))&bindings.objc_msgSend)(this, op, args);
|
|
147 }
|
|
148
|
|
149 static if (dstep.internal.Version.X86 || X86_64)
|
|
150 {
|
|
151 R msgSend_fpret (R = id, ARGS...) (SEL op, ARGS args)
|
|
152 {
|
|
153 version (X86_64)
|
|
154 static assert(!is(R == real), "dstep.objc.objc.objc_object.msgSend_fpret: Only real are legal return value for objc_msgSend_fpret");
|
|
155
|
|
156 else
|
|
157 static assert(!is(R == double) && !is(R == float), "dstep.objc.objc.objc_object.msgSend_fpret: Only double and float are legal return values for objc_msgSend_fpret");
|
|
158
|
|
159 return (cast(R function (id, SEL, ARGS...))&bindings.objc_msgSend_fpret)(this, op, args);
|
|
160 }
|
|
161 }
|
|
162
|
|
163 R invoke (R = id, ARGS...) (Method m, ARGS args)
|
|
164 {
|
|
165 return (cast(R function (id, SEL, ARGS...))&bindings.method_invoke)(this, m, args);
|
|
166 }
|
|
167
|
|
168 void invoke_stret (ARGS...) (Method m, ARGS args)
|
|
169 {
|
|
170 return (cast(R function (id, SEL, ARGS...))&bindings.method_invoke_stret)(this, m, args);
|
|
171 }
|
|
172
|
|
173 R msgSendv (R = id, T) (SEL op, size_t arg_size, T arg_frame)
|
|
174 {
|
|
175 (cast(R function (id, SEL, size_t, T))&bindings.objc_msgSendv)(this, op, arg_size, arg_frame);
|
|
176 }
|
|
177
|
|
178 void msgSendv_stret (R = id, T) (out T stretAddr, SEL op, size_t arg_size, T arg_frame)
|
|
179 {
|
|
180 if (R.sizeof > STRUCT_SIZE_LIMIT)
|
|
181 (cast(void function (R*, id, SEL, size_t, T))&bindings.objc_msgSendv_stret)(&stretAddr, this, op, arg_size, arg_frame);
|
|
182
|
|
183 else
|
|
184 stretAddr = (*cast(R function (id, SEL, size_t, T))&bindings.objc_msgSendv)(this, op, arg_size, arg_frame);
|
|
185 }
|
|
186
|
|
187 version (X86)
|
|
188 {
|
|
189 R msgSendv_fpret (R = id, T) (SEL op, uint arg_size, T arg_frame)
|
|
190 {
|
|
191 static assert(!is(R == double) && !is(R == float), "dstep.objc.objc.objc_object.msgSend_fpret: Only double and float are legal return values for objc_msgSendv_fpret");
|
|
192 return (cast(R function (id, SEL, uint, T))&bindings.objc_msgSendv_fpret)(this, op, arg_size, arg_frame);
|
|
193 }
|
|
194 }
|
|
195 }
|
|
196
|
|
197 struct objc_selector
|
|
198 {
|
|
199 void* sel_id;
|
|
200 char* sel_types;
|
|
201
|
|
202
|
|
203
|
|
204 // D Extensions:
|
|
205
|
|
206 string getName ()
|
|
207 {
|
|
208 return fromStringz(bindings.sel_getName(this));
|
|
209 }
|
|
210
|
|
211 bool isEqual (SEL rhs)
|
|
212 {
|
|
213 return bindings.sel_isEqual(this, rhs);
|
|
214 }
|
|
215
|
|
216 bool isMapped ()
|
|
217 {
|
|
218 return bindings.sel_isMapped(this);
|
|
219 }
|
|
220 } |