FORS Pipeline Reference Manual  4.12.5
list.h
1 /* $Id: list.h,v 1.10 2013-05-16 08:40:07 cgarcia Exp $
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17 
18 /*
19  * $Author: cgarcia $
20  * $Date: 2013-05-16 08:40:07 $
21  * $Revision: 1.10 $
22  * $Name: not supported by cvs2svn $
23  */
24 
25 #ifndef LIST_ELEM
26 #error Define LIST_ELEM before including
27 #endif
28 
29 #include <cpl.h>
30 #include <list_void.h>
31 #include <stdio.h>
32 
33 #define LIST_CON(a,b) a ## _ ## b
34 #define LIST_CAT(a,b) LIST_CON(a,b)
35 
36 #define LIST LIST_CAT(LIST_ELEM, list)
37 
38 #ifndef LIST_DEFINE
39 
40 typedef struct LIST LIST;
41 
42 typedef double (*LIST_CAT(LIST, func_eval))(const LIST_ELEM *,
43  void *);
44 
45 typedef bool (*LIST_CAT(LIST, func_lt))(const LIST_ELEM *,
46  const LIST_ELEM *,
47  void *);
48 
49 typedef bool (*LIST_CAT(LIST, func_predicate))(const LIST_ELEM *,
50  void *);
51 
52 #endif
53 
54 CPL_BEGIN_DECLS
55 
56 LIST *
57 LIST_CAT(LIST, new)(void)
58 #ifdef LIST_DEFINE
59 {
60  return (LIST *) list_new();
61 }
62 #else
63 ;
64 #endif
65 
66 
67 LIST *
68 LIST_CAT(LIST, duplicate)(const LIST *l,
69  LIST_ELEM * (*duplicate)(const LIST_ELEM *))
70 #ifdef LIST_DEFINE
71 {
72  return (LIST *)
73  list_duplicate((const list *)l,
74  (void *(*)(const void *)) duplicate);
75 }
76 #else
77 ;
78 #endif
79 
80 void
81 LIST_CAT(LIST, delete)(LIST **l,
82  void (*ldelete)(LIST_ELEM **))
83 #ifdef LIST_DEFINE
84 {
85  list_delete((list **)l, (void (*)(void **))ldelete);
86 }
87 #else
88 ;
89 #endif
90 
91 void
92 LIST_CAT(LIST, delete_const)(const LIST **l,
93  void (*ldelete)(LIST_ELEM **))
94 #ifdef LIST_DEFINE
95 {
96  list_delete_const((const list **)l, (void (*)(void **))ldelete);
97 }
98 #else
99 ;
100 #endif
101 
102 void
103 LIST_CAT(LIST, insert)(LIST *l, LIST_ELEM *e)
104 #ifdef LIST_DEFINE
105 {
106  list_insert((list *)l, e);
107 }
108 #else
109 ;
110 #endif
111 
112 void
113 LIST_CAT(LIST, reverse)(LIST *l)
114 #ifdef LIST_DEFINE
115 {
116  list_reverse((list *)l);
117 }
118 #else
119 ;
120 #endif
121 
122 int
123 LIST_CAT(LIST, size)(const LIST *l)
124 #ifdef LIST_DEFINE
125 {
126  return list_size((const list *)l);
127 }
128 #else
129 ;
130 #endif
131 
132 
133 LIST_ELEM *
134 LIST_CAT(LIST, first)(LIST *l)
135 #ifdef LIST_DEFINE
136 {
137  return (LIST_ELEM*)list_first((list *)l);
138 }
139 #else
140 ;
141 #endif
142 
143 
144 LIST_ELEM *
145 LIST_CAT(LIST, next)(LIST *l)
146 #ifdef LIST_DEFINE
147 {
148  return (LIST_ELEM*)list_next((list *)l);
149 }
150 #else
151 ;
152 #endif
153 
154 
155 const LIST_ELEM *
156 LIST_CAT(LIST, first_const)(const LIST *l)
157 #ifdef LIST_DEFINE
158 {
159  return (const LIST_ELEM*)list_first_const((list *)l);
160 }
161 #else
162 ;
163 #endif
164 
165 
166 const LIST_ELEM *
167 LIST_CAT(LIST, next_const)(const LIST *l)
168 #ifdef LIST_DEFINE
169 {
170  return (const LIST_ELEM*)list_next_const((const list *)l);
171 }
172 #else
173 ;
174 #endif
175 
176 void
177 LIST_CAT(LIST, first_pair)(LIST *l,
178  LIST_ELEM **e1,
179  LIST_ELEM **e2)
180 #ifdef LIST_DEFINE
181 {
182  list_first_pair((list *)l, (void **)e1, (void **)e2);
183  return;
184 }
185 #else
186 ;
187 #endif
188 
189 void
190 LIST_CAT(LIST, next_pair)(LIST *l,
191  LIST_ELEM **e1,
192  LIST_ELEM **e2)
193 #ifdef LIST_DEFINE
194 {
195  list_next_pair((list *)l, (void **)e1, (void **)e2);
196  return;
197 }
198 #else
199 ;
200 #endif
201 
202 void
203 LIST_CAT(LIST, first_pair_const)(const LIST *l,
204  const LIST_ELEM **e1,
205  const LIST_ELEM **e2)
206 #ifdef LIST_DEFINE
207 {
208  list_first_pair((list *)l, (void **)e1, (void **)e2);
209  return;
210 }
211 #else
212 ;
213 #endif
214 void
215 LIST_CAT(LIST, next_pair_const)(const LIST *l,
216  const LIST_ELEM **e1,
217  const LIST_ELEM **e2)
218 #ifdef LIST_DEFINE
219 {
220  list_next_pair((list *)l, (void **)e1, (void **)e2);
221  return;
222 }
223 #else
224 ;
225 #endif
226 
227 const LIST_ELEM *
228 LIST_CAT(LIST, remove_const)(LIST *l, const LIST_ELEM *e)
229 #ifdef LIST_DEFINE
230 {
231  return (const LIST_ELEM*)list_remove_const((list *)l, e);
232 }
233 #else
234 ;
235 #endif
236 
237 LIST_ELEM *
238 LIST_CAT(LIST, remove)(LIST *l, LIST_ELEM *e)
239 #ifdef LIST_DEFINE
240 {
241  return (LIST_ELEM*)list_remove((list *)l, e);
242 }
243 #else
244 ;
245 #endif
246 
247 
248 LIST *
249 LIST_CAT(LIST, extract)(const LIST *l,
250  LIST_ELEM * (*duplicate)(const LIST_ELEM *),
251  LIST_CAT(LIST, func_predicate) predicate,
252  void *data)
253 #ifdef LIST_DEFINE
254 {
255  return (LIST *)list_extract((const list *)l,
256  (void *(*)(const void *))duplicate,
257  (list_func_predicate) predicate,
258  data);
259 }
260 #else
261 ;
262 #endif
263 
264 
265 const LIST_ELEM *
266 LIST_CAT(LIST, max_const)(const LIST *l,
267  LIST_CAT(LIST, func_lt) less_than,
268  void *data)
269 #ifdef LIST_DEFINE
270 {
271  return (const LIST_ELEM*)list_max_const((list *)l,
272  (list_func_lt) less_than,
273  data);
274 }
275 #else
276 ;
277 #endif
278 
279 LIST_ELEM *
280 LIST_CAT(LIST, max)(LIST *l,
281  LIST_CAT(LIST, func_lt) less_than,
282  void *data)
283 #ifdef LIST_DEFINE
284 {
285  return (LIST_ELEM*)list_max((list *)l,
286  (list_func_lt) less_than,
287  data);
288 }
289 #else
290 ;
291 #endif
292 
293 LIST_ELEM *
294 LIST_CAT(LIST, min)(LIST *l,
295  LIST_CAT(LIST, func_lt) less_than,
296  void *data)
297 #ifdef LIST_DEFINE
298 {
299  return (LIST_ELEM*)list_min((list *)l,
300  (list_func_lt) less_than,
301  data);
302 }
303 #else
304 ;
305 #endif
306 
307 
308 LIST_ELEM *
309 LIST_CAT(LIST, min_val)(LIST *l,
310  LIST_CAT(LIST, func_eval) eval,
311  void *data)
312 #ifdef LIST_DEFINE
313 {
314  return (LIST_ELEM*)list_min_val((list *)l,
315  (list_func_eval) eval,
316  data);
317 }
318 #else
319 ;
320 #endif
321 
322 
323 LIST_ELEM *
324 LIST_CAT(LIST, max_val)(LIST *l,
325  LIST_CAT(LIST, func_eval) eval,
326  void *data)
327 #ifdef LIST_DEFINE
328 {
329  return (LIST_ELEM*)list_max_val((list *)l,
330  (list_func_eval) eval,
331  data);
332 }
333 #else
334 ;
335 #endif
336 
337 
338 const LIST_ELEM *
339 LIST_CAT(LIST, kth_const)(const LIST *l, int k,
340  LIST_CAT(LIST, func_lt) less_than,
341  void *data)
342 #ifdef LIST_DEFINE
343 {
344  return (const LIST_ELEM*)list_kth_const((list *)l, k,
345  (list_func_lt) less_than,
346  data);
347 }
348 #else
349 ;
350 #endif
351 
352 LIST_ELEM *
353 LIST_CAT(LIST, kth)(LIST *l, int k,
354  LIST_CAT(LIST, func_lt) less_than,
355  void *data)
356 #ifdef LIST_DEFINE
357 {
358  return (LIST_ELEM*)list_kth((list *)l, k,
359  (list_func_lt) less_than,
360  data);
361 }
362 #else
363 ;
364 #endif
365 
366 
367 LIST_ELEM *
368 LIST_CAT(LIST, kth_val)(LIST *l, int k,
369  LIST_CAT(LIST, func_eval) eval,
370  void *data)
371 #ifdef LIST_DEFINE
372 {
373  return (LIST_ELEM*)list_kth_val((list *)l, k,
374  (list_func_eval) eval,
375  data);
376 }
377 #else
378 ;
379 #endif
380 
381 
382 
383 const LIST_ELEM *
384 LIST_CAT(LIST, kth_val_const)(const LIST *l, int k,
385  LIST_CAT(LIST, func_eval) eval,
386  void *data)
387 #ifdef LIST_DEFINE
388 {
389  return (const LIST_ELEM*)list_kth_val_const((const list *)l, k,
390  (list_func_eval) eval,
391  data);
392 }
393 #else
394 ;
395 #endif
396 
397 
398 
399 
400 double
401 LIST_CAT(LIST, mean)(LIST *l,
402  LIST_CAT(LIST, func_eval) eval,
403  void *data)
404 #ifdef LIST_DEFINE
405 {
406  return list_mean((list *)l,
407  (list_func_eval) eval,
408  data);
409 }
410 #else
411 ;
412 #endif
413 
414 double
415 LIST_CAT(LIST, mean_optimal)(LIST *l,
416  LIST_CAT(LIST, func_eval) eval, void *data_eval,
417  LIST_CAT(LIST, func_eval) eval_err, void *data_err,
418  double *err,
419  double *red_chisq)
420 #ifdef LIST_DEFINE
421 {
422  return list_mean_optimal((list *)l,
423  (list_func_eval) eval, data_eval,
424  (list_func_eval) eval_err, data_err,
425  err,
426  red_chisq);
427 }
428 #else
429 ;
430 #endif
431 
432 
433 double
434 LIST_CAT(LIST, median)(const LIST *l,
435  LIST_CAT(LIST, func_eval) eval,
436  void *data)
437 #ifdef LIST_DEFINE
438 {
439  return list_median((const list *)l,
440  (list_func_eval) eval,
441  data);
442 }
443 #else
444 ;
445 #endif
446 
447 
448 double
449 LIST_CAT(LIST, mad)(LIST *l,
450  LIST_CAT(LIST, func_eval) eval,
451  void *data)
452 #ifdef LIST_DEFINE
453 {
454  return list_mad((list *)l,
455  (list_func_eval) eval,
456  data);
457 }
458 #else
459 ;
460 #endif
461 
462 CPL_END_DECLS
463 
list * list_duplicate(const list *l, void *(*duplicate)(const void *))
Copy constructor.
Definition: list.c:126
list * list_extract(const list *l, void *(*duplicate)(const void *), bool(*predicate)(const void *, void *), void *data)
Extract elements.
Definition: list.c:507
list * list_new(void)
Constructor.
Definition: list.c:108
Definition: list.c:74