Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
01dfbff77014928ee6fd204cc5c94eaca8e8cfbd
[simgrid.git] / include / xbt / fifo.h
1 /*      $Id$     */
2
3 /* Copyright (c) 2004 Arnaud Legrand. All rights reserved.                  */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef _XBT_FIFO_H
9 #define _XBT_FIFO_H
10 #include "xbt/misc.h" /* BEGIN_DECL */
11
12 BEGIN_DECL()
13
14 /** \addtogroup XBT_fifo
15  *  @{ */
16
17 /** @name 1. Constructor/destructor
18  *  @{
19  */
20
21 /** \brief  Bucket structure 
22 */
23 typedef struct xbt_fifo_item *xbt_fifo_item_t;
24
25 /** \brief  FIFO structure
26 */
27 typedef struct xbt_fifo *xbt_fifo_t;
28
29 xbt_fifo_t xbt_fifo_new(void);
30 void xbt_fifo_free(xbt_fifo_t);
31 /** @} */
32
33 /** @name 2. Perl-like functions
34  *  @{
35  */
36 xbt_fifo_item_t xbt_fifo_push(xbt_fifo_t, void *);
37 void *xbt_fifo_pop(xbt_fifo_t);
38 xbt_fifo_item_t xbt_fifo_unshift(xbt_fifo_t, void *);
39 void *xbt_fifo_shift(xbt_fifo_t);
40 int xbt_fifo_size(xbt_fifo_t);
41 int xbt_fifo_is_in(xbt_fifo_t, void *);
42 /** @} */
43
44 /** @name 3. Manipulating items directly
45  *
46  *  @{
47  */
48
49 xbt_fifo_item_t xbt_fifo_new_item(void);
50 void xbt_fifo_set_item_content(xbt_fifo_item_t, void *);
51 void *xbt_fifo_get_item_content(xbt_fifo_item_t);
52 void xbt_fifo_free_item(xbt_fifo_item_t);
53
54 void xbt_fifo_push_item(xbt_fifo_t, xbt_fifo_item_t);
55 xbt_fifo_item_t xbt_fifo_pop_item(xbt_fifo_t);
56 void xbt_fifo_unshift_item(xbt_fifo_t, xbt_fifo_item_t);
57 xbt_fifo_item_t xbt_fifo_shift_item(xbt_fifo_t);
58
59 void xbt_fifo_remove(xbt_fifo_t, void *);
60 void xbt_fifo_remove_item(xbt_fifo_t, xbt_fifo_item_t);
61
62 xbt_fifo_item_t xbt_fifo_get_first_item(xbt_fifo_t l);
63 xbt_fifo_item_t xbt_fifo_get_next_item(xbt_fifo_item_t i);
64 xbt_fifo_item_t xbt_fifo_get_prev_item(xbt_fifo_item_t i);
65
66 /** 
67  * \brief List iterator
68  * asserts and stuff
69  * \param f a list (#xbt_fifo_t)
70  * \param i a bucket (#xbt_fifo_item_t)
71  * \param type a type
72  * \param n an object of type \a type.
73  *
74  * Iterates over the whole list. 
75  */
76 #define xbt_fifo_foreach(f,i,n,type)                  \
77    for(i=xbt_fifo_get_first_item(f);                    \
78      ((i)?(n=(type)(xbt_fifo_get_item_content(i))):(NULL));             \
79        i=xbt_fifo_get_next_item(i))
80
81 /** @} */
82
83 /** @name 4. Miscanaleous
84  *
85  *  @{
86  */
87 void **xbt_fifo_to_array(xbt_fifo_t);
88 xbt_fifo_t xbt_fifo_copy(xbt_fifo_t);
89 /** @} */
90
91 /** @name 5. Deprecated functions: don't use!
92  *
93  *  @{
94  */
95 xbt_fifo_item_t xbt_fifo_newitem(void);
96 void xbt_fifo_freeitem(xbt_fifo_item_t);
97
98 xbt_fifo_item_t xbt_fifo_getFirstItem(xbt_fifo_t l);
99 xbt_fifo_item_t xbt_fifo_getNextItem(xbt_fifo_item_t i);
100 xbt_fifo_item_t xbt_fifo_getPrevItem(xbt_fifo_item_t i);
101 /** @} */
102
103 END_DECL()
104
105 /** @} */
106 #endif                          /* _XBT_FIFO_H */