37 #define restrict |
43 #define restrict |
38 #endif |
44 #endif |
39 extern "C" { |
45 extern "C" { |
40 #endif |
46 #endif |
41 |
47 |
|
48 /** |
|
49 * Generic loop statement for lists. |
|
50 * |
|
51 * The first argument is the type of the list and its elements (e.g. UcxList). |
|
52 * The structure invariant of the list must be as follows: |
|
53 * <ul> |
|
54 * <li>a first (non-<code>NULL</code>) element</li> |
|
55 * <li>for each element a reference to the <code>next</code> element (the |
|
56 * variable name of the pointer MUST be <code>next</code>)</li> |
|
57 * <li>the last element of the list MUST have the <code>next</code> pointer |
|
58 * set to <code>NULL</code></li> |
|
59 * </ul> |
|
60 * |
|
61 * The second argument is a pointer to the list. In most cases this will be the |
|
62 * pointer to the first element of the list, but it may also be an arbitrary |
|
63 * element of the list. The iteration will then start with that element. |
|
64 * |
|
65 * The third argument is the name of the iteration variable. The scope of |
|
66 * this variable is limited to the <code>UCX_FOREACH</code> statement. |
|
67 * |
|
68 * @param type The type of <b>both</b> the list and the element |
|
69 * @param list The first element of the list |
|
70 * @param elem The variable name of the element |
|
71 */ |
42 #define UCX_FOREACH(type,list,elem) \ |
72 #define UCX_FOREACH(type,list,elem) \ |
43 for (type elem = list ; elem != NULL ; elem = elem->next) |
73 for (type elem = list ; elem != NULL ; elem = elem->next) |
44 |
74 |
45 /* element1,element2,custom data -> {-1,0,1} */ |
75 /** |
|
76 * Function pointer to a compare function. |
|
77 * |
|
78 * The compare function shall take three arguments: the two values that shall be |
|
79 * compared and optional additional data. |
|
80 * The function shall then return -1 if the first argument is less than the |
|
81 * second argument, 1 if the first argument is greater than the second argument |
|
82 * and 0 if both arguments are equal. If the third argument is |
|
83 * <code>NULL</code>, it shall be ignored. |
|
84 */ |
46 typedef int(*cmp_func)(void*,void*,void*); |
85 typedef int(*cmp_func)(void*,void*,void*); |
47 |
86 |
48 /* element,custom data -> copy of element */ |
87 /** |
|
88 * Function pointer to a copy function. |
|
89 * |
|
90 * The copy function shall create a copy of the first argument and may use |
|
91 * additional data provided by the second argument. If the second argument is |
|
92 * <code>NULL</code>, it shall be ignored. |
|
93 |
|
94 * <b>Attention:</b> if pointers returned by functions of this type may be |
|
95 * passed to <code>free()</code> depends on the implementation of the |
|
96 * respective <code>copy_func</code>. |
|
97 */ |
49 typedef void*(*copy_func)(void*,void*); |
98 typedef void*(*copy_func)(void*,void*); |
50 |
99 |
51 /* buffer, element size, element count, stream */ |
100 /** |
|
101 * Function pointer to a write function. |
|
102 * |
|
103 * The signature of the write function shall be compatible to the signature |
|
104 * of standard <code>fwrite</code>, though it may use arbitrary data types for |
|
105 * source and destination. |
|
106 * |
|
107 * The arguments shall contain (in ascending order): a pointer to the source, |
|
108 * the length of one element, the element count, a pointer to the destination. |
|
109 */ |
52 typedef size_t(*write_func)(const void*, size_t, size_t, void*); |
110 typedef size_t(*write_func)(const void*, size_t, size_t, void*); |
53 |
111 |
54 /* buffer, element size, element count, stream */ |
112 /** |
|
113 * Function pointer to a read function. |
|
114 * |
|
115 * The signature of the read function shall be compatible to the signature |
|
116 * of standard <code>fread</code>, though it may use arbitrary data types for |
|
117 * source and destination. |
|
118 * |
|
119 * The arguments shall contain (in ascending order): a pointer to the |
|
120 * destination, the length of one element, the element count, a pointer to the |
|
121 * source. |
|
122 */ |
55 typedef size_t(*read_func)(void*, size_t, size_t, void*); |
123 typedef size_t(*read_func)(void*, size_t, size_t, void*); |
56 |
124 |
57 #ifdef __cplusplus |
125 #ifdef __cplusplus |
58 } |
126 } |
59 #endif |
127 #endif |