10 #include "cgds/types.h"
11 #include "cgds/safe_alloc.h"
12 #include "cgds/List.h"
15 * @brief Queue containing generic data.
16 * @param dataSize Size in bytes of a queue element.
18 typedef struct Queue
{
19 size_t dataSize
; ///< Size in bytes of a queue element.
20 List
* list
; ///< Internal list representation
24 * @brief Initialize an empty queue.
25 * @param queue "this" pointer.
26 * @param dataSize Size in bytes of a queue element.
29 Queue
* queue
, ///< "this" pointer.
30 size_t dataSize
///< Size in bytes of a queue element.
34 * @brief Return an allocated and initialized queue.
37 size_t dataSize
///< Size in bytes of a queue element.
41 * @brief Return an allocated and initialized queue.
42 * @param type Type of a queue element (int, char*, ...).
44 * Usage: Queue* queue_new(<Type> type)
46 #define queue_new(type) \
48 _queue_new(sizeof(type)); \
52 * @brief Copy constructor (shallow copy, ok for basic types).
55 Queue
* queue
///< "this" pointer.
59 * @brief Check if the queue is empty.
62 Queue
* queue
///< "this" pointer.
66 * @brief Return size of the current queue.
69 Queue
* queue
///< "this" pointer.
73 * @brief Add something at the end of the queue.
76 Queue
* queue
, ///< "this" pointer.
77 void* data
///< Data to be pushed.
81 * @brief Add something at the end of the queue.
82 * @param queue "this" pointer
83 * @param data Data to be pushed.
85 * Usage: void queue_push(Queue* queue, void data)
87 #define queue_push(queue, data) \
89 typeof((data)) tmp = data; \
90 _queue_push(queue, &tmp); \
94 * @brief Return what is at the beginning of the queue.
97 Queue
* queue
///< "this" pointer.
101 * @brief Return what is at the beginning of the queue.
102 * @param queue "this" pointer.
103 * @param data Data to be assigned.
105 * Usage: void queue_peek(Queue* queue, void data)
107 #define queue_peek(queue, data) \
109 void* pData = _queue_peek(queue); \
110 data = *((typeof(&data))pData); \
114 * @brief Remove the beginning of the queue.
117 Queue
* queue
///< "this" pointer.
121 * @brief Clear the entire queue.
124 Queue
* queue
///< "this" pointer.
128 * @brief Destroy the queue: clear it, and free 'queue' pointer.
131 Queue
* queue
///< "this" pointer.