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) \
47 _queue_new(sizeof(type))
50 * @brief Copy constructor (shallow copy, ok for basic types).
53 Queue
* queue
///< "this" pointer.
57 * @brief Check if the queue is empty.
60 Queue
* queue
///< "this" pointer.
64 * @brief Return size of the current queue.
67 Queue
* queue
///< "this" pointer.
71 * @brief Add something at the end of the queue.
74 Queue
* queue
, ///< "this" pointer.
75 void* data
///< Data to be pushed.
79 * @brief Add something at the end of the queue.
80 * @param queue "this" pointer
81 * @param data Data to be pushed.
83 * Usage: void queue_push(Queue* queue, void data)
85 #define queue_push(queue, data) \
87 typeof((data)) tmp = data; \
88 _queue_push(queue, &tmp); \
92 * @brief Return what is at the beginning of the queue.
95 Queue
* queue
///< "this" pointer.
99 * @brief Return what is at the beginning of the queue.
100 * @param queue "this" pointer.
101 * @param data Data to be assigned.
103 * Usage: void queue_peek(Queue* queue, void data)
105 #define queue_peek(queue, data) \
107 void* pData = _queue_peek(queue); \
108 data = *((typeof(&data))pData); \
112 * @brief Remove the beginning of the queue.
115 Queue
* queue
///< "this" pointer.
119 * @brief Clear the entire queue.
122 Queue
* queue
///< "this" pointer.
126 * @brief Destroy the queue: clear it, and free 'queue' pointer.
129 Queue
* queue
///< "this" pointer.