LibCDS
queue.h
Go to the documentation of this file.
1 /**
2  * @file queue.h The FIFO queue.
3  */
4 
5 #ifndef _QUEUE_H_
6 #define _QUEUE_H_
7 
8 #include "../util.h"
9 
10 /** QueueData is the data type for the container private information. */
11 typedef struct _QueueData QueueData;
12 
13 /** The implementation for queue. */
14 typedef struct _Queue {
15  /** The container private information */
17 
18  /** Insert an item to the tail of the queue.
19  @see QueuePush */
20  int32_t (*push) (struct _Queue*, Item);
21 
22  /** Retrieve item from the head of the queue.
23  @see QueueFront */
24  int32_t (*front) (struct _Queue*, Item*);
25 
26  /** Retrieve item from the tail of the queue.
27  @see QueueBack */
28  int32_t (*back) (struct _Queue*, Item*);
29 
30  /** Delete an item from the head of the queue.
31  @see QueuePop */
32  int32_t (*pop) (struct _Queue*);
33 
34  /** Return the number of stored items.
35  @see QueueSize */
36  int32_t (*size) (struct _Queue*);
37 
38  /** Set the custom item resource clean method.
39  @see QueueSetDestroy */
40  int32_t (*set_destroy) (struct _Queue*, void (*) (Item));
41 } Queue;
42 
43 
44 /*===========================================================================*
45  * Definition for the exported member operations *
46  *===========================================================================*/
47 /**
48  * @brief The constructor for Queue.
49  *
50  * @param ppObj The double pointer to the to be constructed queue
51  *
52  * @retval SUCC
53  * @retval ERR_NOMEM Insufficient memory for queue construction
54  */
55 int32_t QueueInit(Queue **ppObj);
56 
57 /**
58  * @brief The destructor for Queue.
59  *
60  * If the custom resource clean method is set, it also runs the clean method
61  * for all the items.
62  *
63  * @param ppObj The double pointer to the to be destructed queue
64  */
65 void QueueDeinit(Queue **ppObj);
66 
67 /**
68  * @brief Insert an item to the tail of the queue.
69  *
70  * This function inserts an item to the tail of the queue with the corresponding
71  * queue size extension.
72  *
73  * @param self The pointer to Queue structure
74  * @param item The designated item
75  *
76  * @retval SUCC
77  * @retval ERR_NOINIT Uninitialized container
78  * @retval ERR_NOMEM Insufficient memory for queue extension
79  */
80 int32_t QueuePush(Queue *self, Item item);
81 
82 /**
83  * @brief Delete item from top of the queue.
84  *
85  * This function deletes item from top of the queue. If the custom resource clean
86  * method is set, it also runs the clean method for the deleted item.
87  *
88  * @param self The pointer to Queue structure
89  *
90  * @retval SUCC
91  * @retval ERR_NOINIT Uninitialized container
92  * @retval ERR_IDX Empty queue
93  */
94 int32_t QueuePop(Queue *self);
95 
96 /**
97  * @brief Retrieve item from the head of the queue.
98  *
99  * This function retrieves item from the head of the queue. If the queue is not
100  * empty, the item is returned by the second parameter. Otherwise, the error
101  * code is returned and the second parameter is updated with NULL.
102  *
103  * @param self The pointer to Queue structure
104  * @param pItem The pointer to the returned item
105  *
106  * @retval SUCC
107  * @retval ERR_NOINIT Uninitialized container
108  * @retval ERR_IDX Empty queue
109  * @retval ERR_GET Invalid parameter to store returned item
110  */
111 int32_t QueueFront(Queue *self, Item *pItem);
112 
113 /**
114  * @brief Retrieve item from the tail of the queue.
115  *
116  * This function retrieves item from the tail of the queue. If the queue is not
117  * empty, the item is returned by the second parameter. Otherwise, the error
118  * code is returned and the second parameter is updated with NULL.
119  *
120  * @param self The pointer to Queue structure
121  * @param pItem The pointer to the returned item
122  *
123  * @retval SUCC
124  * @retval ERR_NOINIT Uninitialized container
125  * @retval ERR_IDX Empty queue
126  * @retval ERR_GET Invalid parameter to store returned item
127  */
128 int32_t QueueBack(Queue *self, Item *pItem);
129 
130 
131 /**
132  * @brief Return the number of stored items.
133  *
134  * @param self The pointer to Queue structure
135  *
136  * @return The number of items
137  * @retval ERR_NOINIT Uninitialized container
138  */
139 int32_t QueueSize(Queue *self);
140 
141 /**
142  * @brief Set the custom item resource clean method.
143  *
144  * @param self The pointer to Queue structure
145  * @param pFunc The function pointer to the custom method
146  *
147  * @retval SUCC
148  * @retval ERR_NOINIT Uninitialized container
149  */
150 int32_t QueueSetDestroy(Queue *self, void (*pFunc) (Item));
151 
152 #endif
int32_t QueueSize(Queue *self)
Return the number of stored items.
int32_t QueueFront(Queue *self, Item *pItem)
Retrieve item from the head of the queue.
QueueData * pData
The container private information.
Definition: queue.h:16
int32_t QueueInit(Queue **ppObj)
The constructor for Queue.
int32_t QueuePop(Queue *self)
Delete item from top of the queue.
The implementation for queue.
Definition: queue.h:14
struct _QueueData QueueData
QueueData is the data type for the container private information.
Definition: queue.h:11
int32_t QueueSetDestroy(Queue *self, void(*pFunc)(Item))
Set the custom item resource clean method.
void QueueDeinit(Queue **ppObj)
The destructor for Queue.
int32_t QueuePush(Queue *self, Item item)
Insert an item to the tail of the queue.
int32_t QueueBack(Queue *self, Item *pItem)
Retrieve item from the tail of the queue.