Debian Codegraph @

src/doc/old-manual/uffi/ref_aggregate.xml

raw symbols SCIP
1 <?xml version="1.0" encoding="utf-8"?>
2 <!DOCTYPE book [
3 <!ENTITY % eclent SYSTEM "../ecl.ent">
4 %eclent;
5 ]>
6 <book xmlns="http://docbook.org/ns/docbook" version="5.0" xml:lang="en">
7 <reference xml:id="uffi.aggregates">
8 <title>Aggregate Types</title>
9 <partintro>
10 <title>Overview</title>
11 <para>
12 Aggregate types are comprised of one or more primitive types.
13 </para>
14 </partintro>
15
16 <refentry xml:id="uffi.def-enum">
17 <refnamediv>
18 <refname><function>def-enum</function></refname>
19 <refpurpose>Defines a &C; enumeration.
20 </refpurpose>
21 <refclass>Macro</refclass>
22 </refnamediv>
23 <refsynopsisdiv>
24 <title>Syntax</title>
25 <synopsis>
26 <function>def-enum</function> <replaceable>name fields &amp;key separator-string</replaceable>
27 </synopsis>
28 </refsynopsisdiv>
29 <refsect1>
30 <title>Arguments and Values</title>
31 <variablelist>
32 <varlistentry>
33 <term><parameter>name</parameter></term>
34 <listitem>
35 <para>A symbol that names the enumeration.
36 </para>
37 </listitem>
38 </varlistentry>
39 <varlistentry>
40 <term><parameter>fields</parameter></term>
41 <listitem>
42 <para>A list of field defintions. Each definition can be
43 a symbol or a list of two elements. Symbols get assigned a value of the
44 current counter which starts at <computeroutput>0</computeroutput> and
45 increments by <computeroutput>1</computeroutput> for each subsequent symbol. It the field definition is a list, the first position is the symbol and the second
46 position is the value to assign the the symbol. The current counter gets set
47 to <computeroutput>1+</computeroutput> this value.
48 </para>
49 </listitem>
50 </varlistentry>
51 <varlistentry>
52 <term><parameter>separator-string</parameter></term>
53 <listitem>
54 <para>A string that governs the creation of constants. The
55 default is <computeroutput>"#"</computeroutput>.</para>
56 </listitem>
57 </varlistentry>
58 </variablelist>
59 </refsect1>
60 <refsect1>
61 <title>Description</title>
62 <para>
63 Declares a &C; enumeration. It generates constants with integer values for the elements of the enumeration. The symbols for the these constant
64 values are created by the <function>concatenation</function> of the
65 enumeration name, separator-string, and field symbol. Also creates
66 a foreign type with the name <parameter>name</parameter> of type
67 <constant>:int</constant>.
68 </para>
69 </refsect1>
70 <refsect1>
71 <title>Examples</title>
72 <screen>
73 (def-enum abc (:a :b :c))
74 ;; Creates constants abc#a (1), abc#b (2), abc#c (3) and defines
75 ;; the foreign type "abc" to be :int
76
77 (def-enum efoo (:e1 (:e2 10) :e3) :separator-string "-")
78 ;; Creates constants efoo-e1 (1), efoo-e2 (10), efoo-e3 (11) and defines
79 ;; the foreign type efoo to be :int</screen>
80 </refsect1>
81 <refsect1>
82 <title>Side Effects</title>
83 <para>Creates a :int foreign type, defines constants.</para>
84 </refsect1>
85 <refsect1>
86 <title>Affected by</title>
87 <para>None.</para>
88 </refsect1>
89 <refsect1>
90 <title>Exceptional Situations</title>
91 <para>None.</para>
92 </refsect1>
93 </refentry>
94
95
96 <refentry xml:id="uffi.def-struct">
97 <refnamediv>
98 <refname><function>def-struct</function></refname>
99 <refpurpose>Defines a &C; structure.
100 </refpurpose>
101 <refclass>Macro</refclass>
102 </refnamediv>
103 <refsynopsisdiv>
104 <title>Syntax</title>
105 <synopsis>
106 <function>def-struct</function> <replaceable>name &amp;rest fields</replaceable>
107 </synopsis>
108 </refsynopsisdiv>
109 <refsect1>
110 <title>Arguments and Values</title>
111 <variablelist>
112 <varlistentry>
113 <term><parameter>name</parameter></term>
114 <listitem>
115 <para>A symbol that names the structure.
116 </para>
117 </listitem>
118 </varlistentry>
119 <varlistentry>
120 <term><parameter>fields</parameter></term>
121 <listitem>
122 <para>A variable number of field defintions. Each definition is a list consisting of a symbol naming the field followed by its foreign type.
123 </para>
124 </listitem>
125 </varlistentry>
126 </variablelist>
127 </refsect1>
128 <refsect1>
129 <title>Description</title>
130 <para>
131 Declares a structure. A special type is available as a slot
132 in the field. It is a pointer that points to an instance of the parent
133 structure. It's type is <constant>:pointer-self</constant>.
134
135 </para>
136 </refsect1>
137 <refsect1>
138 <title>Examples</title>
139 <screen>
140 (def-struct foo (a :unsigned-int)
141 (b (* :char))
142 (c (:array :int 10))
143 (next :pointer-self))</screen>
144 </refsect1>
145 <refsect1>
146 <title>Side Effects</title>
147 <para>Creates a foreign type.</para>
148 </refsect1>
149 <refsect1>
150 <title>Affected by</title>
151 <para>None.</para>
152 </refsect1>
153 <refsect1>
154 <title>Exceptional Situations</title>
155 <para>None.</para>
156 </refsect1>
157 </refentry>
158
159
160 <refentry xml:id="uffi.get-slot-value">
161 <refnamediv>
162 <refname><function>get-slot-value</function></refname>
163 <refpurpose>Retrieves a value from a slot of a structure.
164 </refpurpose>
165 <refclass>Macro</refclass>
166 </refnamediv>
167 <refsynopsisdiv>
168 <title>Syntax</title>
169 <synopsis>
170 <function>get-slot-value</function> <replaceable>obj type field</replaceable> => <returnvalue>value</returnvalue>
171 </synopsis>
172 </refsynopsisdiv>
173 <refsect1>
174 <title>Arguments and Values</title>
175 <variablelist>
176 <varlistentry>
177 <term><parameter>obj</parameter></term>
178 <listitem>
179 <para>A pointer to foreign structure.
180 </para>
181 </listitem>
182 </varlistentry>
183 <varlistentry>
184 <term><parameter>type</parameter></term>
185 <listitem>
186 <para>A name of the foreign structure.
187 </para>
188 </listitem>
189 </varlistentry>
190 <varlistentry>
191 <term><parameter>field</parameter></term>
192 <listitem>
193 <para>A name of the desired field in foreign structure.
194 </para>
195 </listitem>
196 </varlistentry>
197 <varlistentry>
198 <term><returnvalue>value</returnvalue></term>
199 <listitem>
200 <para>The value of the field in the structure.
201 </para>
202 </listitem>
203 </varlistentry>
204 </variablelist>
205 </refsect1>
206 <refsect1>
207 <title>Description</title>
208 <para>
209 Accesses a slot value from a structure. This is generalized
210 and can be used with <function>setf</function>.
211 </para>
212 </refsect1>
213 <refsect1>
214 <title>Examples</title>
215 <screen>
216 (get-slot-value foo-ptr 'foo-structure 'field-name)
217 (setf (get-slot-value foo-ptr 'foo-structure 'field-name) 10)</screen>
218 </refsect1>
219 <refsect1>
220 <title>Side Effects</title>
221 <para>None.</para>
222 </refsect1>
223 <refsect1>
224 <title>Affected by</title>
225 <para>None.</para>
226 </refsect1>
227 <refsect1>
228 <title>Exceptional Situations</title>
229 <para>None.</para>
230 </refsect1>
231 </refentry>
232
233 <refentry xml:id="uffi.get-slot-pointer">
234 <refnamediv>
235 <refname><function>get-slot-pointer</function></refname>
236 <refpurpose>Retrieves a pointer from a slot of a structure.
237 </refpurpose>
238 <refclass>Macro</refclass>
239 </refnamediv>
240 <refsynopsisdiv>
241 <title>Syntax</title>
242 <synopsis>
243 <function>get-slot-pointer</function> <replaceable>obj type field</replaceable> => <returnvalue>pointer</returnvalue>
244 </synopsis>
245 </refsynopsisdiv>
246 <refsect1>
247 <title>Arguments and Values</title>
248 <variablelist>
249 <varlistentry>
250 <term><parameter>obj</parameter></term>
251 <listitem>
252 <para>A pointer to foreign structure.
253 </para>
254 </listitem>
255 </varlistentry>
256 <varlistentry>
257 <term><parameter>type</parameter></term>
258 <listitem>
259 <para>A name of the foreign structure.
260 </para>
261 </listitem>
262 </varlistentry>
263 <varlistentry>
264 <term><parameter>field</parameter></term>
265 <listitem>
266 <para>A name of the desired field in foreign structure.
267 </para>
268 </listitem>
269 </varlistentry>
270 <varlistentry>
271 <term><returnvalue>pointer</returnvalue></term>
272 <listitem>
273 <para>The value of the field in the structure.
274 </para>
275 </listitem>
276 </varlistentry>
277 </variablelist>
278 </refsect1>
279 <refsect1>
280 <title>Description</title>
281 <para>
282 This is similar to <function>get-slot-value</function>. It
283 is used when the value of a slot is a pointer type.
284 </para>
285 </refsect1>
286 <refsect1>
287 <title>Examples</title>
288 <screen>
289 (get-slot-pointer foo-ptr 'foo-structure 'my-char-ptr)</screen>
290 </refsect1>
291 <refsect1>
292 <title>Side Effects</title>
293 <para>None.</para>
294 </refsect1>
295 <refsect1>
296 <title>Affected by</title>
297 <para>None.</para>
298 </refsect1>
299 <refsect1>
300 <title>Exceptional Situations</title>
301 <para>None.</para>
302 </refsect1>
303 </refentry>
304
305
306 <refentry xml:id="uffi.def-array-pointer">
307 <refnamediv>
308 <refname><function>def-array-pointer</function></refname>
309 <refpurpose>Defines a pointer to a array of type.
310 </refpurpose>
311 <refclass>Macro</refclass>
312 </refnamediv>
313 <refsynopsisdiv>
314 <title>Syntax</title>
315 <synopsis>
316 <function>def-array-pointer</function> <replaceable>name type</replaceable>
317 </synopsis>
318 </refsynopsisdiv>
319 <refsect1>
320 <title>Arguments and Values</title>
321 <variablelist>
322 <varlistentry>
323 <term><parameter>name</parameter></term>
324 <listitem>
325 <para>A name of the new foreign type.
326 </para>
327 </listitem>
328 </varlistentry>
329 <varlistentry>
330 <term><parameter>type</parameter></term>
331 <listitem>
332 <para>The foreign type of the array elements.
333 </para>
334 </listitem>
335 </varlistentry>
336 </variablelist>
337 </refsect1>
338 <refsect1>
339 <title>Description</title>
340 <para>
341 Defines a type tat is a pointer to an array of type.
342 </para>
343 </refsect1>
344 <refsect1>
345 <title>Examples</title>
346 <screen>
347 (def-array-pointer byte-array-pointer :unsigned-char)</screen>
348 </refsect1>
349 <refsect1>
350 <title>Side Effects</title>
351 <para>Defines a new foreign type.</para>
352 </refsect1>
353 <refsect1>
354 <title>Affected by</title>
355 <para>None.</para>
356 </refsect1>
357 <refsect1>
358 <title>Exceptional Situations</title>
359 <para>None.</para>
360 </refsect1>
361 </refentry>
362
363
364 <refentry xml:id="uffi.deref-array">
365 <refnamediv>
366 <refname><function>deref-array</function></refname>
367 <refpurpose>Deference an array.
368 </refpurpose>
369 <refclass>Macro</refclass>
370 </refnamediv>
371 <refsynopsisdiv>
372 <title>Syntax</title>
373 <synopsis>
374 <function>deref-array</function> <replaceable>array type position</replaceable> => <returnvalue>value</returnvalue>
375 </synopsis>
376 </refsynopsisdiv>
377 <refsect1>
378 <title>Arguments and Values</title>
379 <variablelist>
380 <varlistentry>
381 <term><parameter>array</parameter></term>
382 <listitem>
383 <para>A foreign array.
384 </para>
385 </listitem>
386 </varlistentry>
387 <varlistentry>
388 <term><parameter>type</parameter></term>
389 <listitem>
390 <para>The foreign type of the array.
391 </para>
392 </listitem>
393 </varlistentry>
394 <varlistentry>
395 <term><parameter>position</parameter></term>
396 <listitem>
397 <para>An integer specifying the position to retrieve from
398 the array.
399 </para>
400 </listitem>
401 </varlistentry>
402 <varlistentry>
403 <term><returnvalue>value</returnvalue></term>
404 <listitem>
405 <para>The value stored in the position of the array.
406 </para>
407 </listitem>
408 </varlistentry>
409 </variablelist>
410 </refsect1>
411 <refsect1>
412 <title>Description</title>
413 <para>
414 Dereferences (retrieves) the value of an array element.
415 </para>
416 </refsect1>
417 <refsect1>
418 <title>Examples</title>
419 <screen>
420 (def-array-pointer ca :char)
421 (let ((fs (convert-to-foreign-string "ab")))
422 (values (null-char-p (deref-array fs 'ca 0))
423 (null-char-p (deref-array fs 'ca 2))))
424 => &nil;
425 &t;</screen>
426 </refsect1>
427 <refsect1>
428 <title>Notes</title>
429 <para>
430 The TYPE argument is ignored for CL implementations other than
431 AllegroCL. If you want to cast a pointer to another type use
432 WITH-CAST-POINTER together with DEREF-POINTER/DEREF-ARRAY.
433 </para>
434 </refsect1>
435 <refsect1>
436 <title>Side Effects</title>
437 <para>None.</para>
438 </refsect1>
439 <refsect1>
440 <title>Affected by</title>
441 <para>None.</para>
442 </refsect1>
443 <refsect1>
444 <title>Exceptional Situations</title>
445 <para>None.</para>
446 </refsect1>
447 </refentry>
448
449 <refentry xml:id="uffi.def-union">
450 <refnamediv>
451 <refname><function>def-union</function></refname>
452 <refpurpose>Defines a foreign union type.
453 </refpurpose>
454 <refclass>Macro</refclass>
455 </refnamediv>
456 <refsynopsisdiv>
457 <title>Syntax</title>
458 <synopsis>
459 <function>def-union</function> <replaceable>name &amp;rest fields</replaceable>
460 </synopsis>
461 </refsynopsisdiv>
462 <refsect1>
463 <title>Arguments and Values</title>
464 <variablelist>
465 <varlistentry>
466 <term><parameter>name</parameter></term>
467 <listitem>
468 <para>A name of the new union type.
469 </para>
470 </listitem>
471 </varlistentry>
472 <varlistentry>
473 <term><parameter>fields</parameter></term>
474 <listitem>
475 <para>A list of fields of the union.
476 </para>
477 </listitem>
478 </varlistentry>
479 </variablelist>
480 </refsect1>
481 <refsect1>
482 <title>Description</title>
483 <para>
484 Defines a foreign union type.
485 </para>
486 </refsect1>
487 <refsect1>
488 <title>Examples</title>
489 <screen>
490 (def-union test-union
491 (a-char :char)
492 (an-int :int))
493
494 (let ((u (allocate-foreign-object 'test-union)))
495 (setf (get-slot-value u 'test-union 'an-int) (+ 65 (* 66 256)))
496 (prog1
497 (ensure-char-character (get-slot-value u 'test-union 'a-char))
498 (free-foreign-object u)))
499 => #\A</screen>
500 </refsect1>
501 <refsect1>
502 <title>Side Effects</title>
503 <para>Defines a new foreign type.</para>
504 </refsect1>
505 <refsect1>
506 <title>Affected by</title>
507 <para>None.</para>
508 </refsect1>
509 <refsect1>
510 <title>Exceptional Situations</title>
511 <para>None.</para>
512 </refsect1>
513 </refentry>
514
515 </reference>
516 </book>
517 <!-- Keep this comment at the end of the file
518 Local variables:
519 mode: nxml
520 sgml-indent-step: 1
521 nxml-child-indent: 1
522 nxml-outline-child-indent: 0
523 fill-column: 79
524 End:
525 -->