132
|
1 /**
|
|
2 * The vararg module is intended to facilitate vararg manipulation in D.
|
|
3 * It should be interface compatible with the C module "stdarg," and the
|
|
4 * two modules may share a common implementation if possible (as is done
|
|
5 * here).
|
|
6 *
|
|
7 * Copyright: Public Domain
|
|
8 * License: Public Domain
|
|
9 * Authors: Hauke Duden, Walter Bright
|
|
10 */
|
|
11 module tango.core.Vararg;
|
|
12
|
|
13
|
|
14 version( GNU )
|
|
15 {
|
|
16 public import std.stdarg;
|
|
17 }
|
|
18 else
|
|
19 {
|
|
20 /**
|
|
21 * The base vararg list type.
|
|
22 */
|
|
23 alias void* va_list;
|
|
24
|
|
25
|
|
26 template va_start( T )
|
|
27 {
|
|
28 /**
|
|
29 * This function initializes the supplied argument pointer for subsequent
|
|
30 * use by va_arg and va_end.
|
|
31 *
|
|
32 * Params:
|
|
33 * ap = The argument pointer to initialize.
|
|
34 * paramn = The identifier of the rightmost parameter in the function
|
|
35 * parameter list.
|
|
36 */
|
|
37 void va_start( out va_list ap, inout T parmn )
|
|
38 {
|
|
39 ap = cast(va_list) ( cast(void*) &parmn + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) );
|
|
40 }
|
|
41 }
|
|
42
|
|
43
|
|
44 template va_arg( T )
|
|
45 {
|
|
46 /**
|
|
47 * This function returns the next argument in the sequence referenced by
|
|
48 * the supplied argument pointer. The argument pointer will be adjusted
|
|
49 * to point to the next arggument in the sequence.
|
|
50 *
|
|
51 * Params:
|
|
52 * ap = The argument pointer.
|
|
53 *
|
|
54 * Returns:
|
|
55 * The next argument in the sequence. The result is undefined if ap
|
|
56 * does not point to a valid argument.
|
|
57 */
|
|
58 T va_arg( inout va_list ap )
|
|
59 {
|
|
60 T arg = *cast(T*) ap;
|
|
61 ap = cast(va_list) ( cast(void*) ap + ( ( T.sizeof + int.sizeof - 1 ) & ~( int.sizeof - 1 ) ) );
|
|
62 return arg;
|
|
63 }
|
|
64 }
|
|
65
|
|
66
|
|
67 /**
|
|
68 * This function cleans up any resources allocated by va_start. It is
|
|
69 * currently a no-op and exists mostly for syntax compatibility with
|
|
70 * the variadric argument functions for C.
|
|
71 *
|
|
72 * Params:
|
|
73 * ap = The argument pointer.
|
|
74 */
|
|
75 void va_end( va_list ap )
|
|
76 {
|
|
77
|
|
78 }
|
|
79
|
|
80
|
|
81 /**
|
|
82 * This function copied the argument pointer src to dst.
|
|
83 *
|
|
84 * Params:
|
|
85 * src = The source pointer.
|
|
86 * dst = The destination pointer.
|
|
87 */
|
|
88 void va_copy( out va_list dst, va_list src )
|
|
89 {
|
|
90 dst = src;
|
|
91 }
|
|
92 }
|