Macros
squeue.h File Reference

Generic queue implementation. More...

Macros

#define VTM_SQUEUE_STRUCT(NODE_TYPE)
 
#define VTM_SQUEUE_INIT(NAME)
 
#define VTM_SQUEUE_ADD(NAME, NODE_PTR)
 
#define VTM_SQUEUE_POLL(NAME, NODE_PTR)
 
#define VTM_SQUEUE_REMOVE(NAME, NODE_PTR, PREV_PTR, FUNC)
 
#define VTM_SQUEUE_IS_EMPTY(NAME)   (NAME.head == NULL)
 
#define VTM_SQUEUE_FOR_EACH(NAME, NODE_PTR)
 
#define VTM_SQUEUE_FOR_EACH_MOD(NAME, NODE_PTR, PREV_PTR, NEXT_PTR)
 
#define VTM_SQUEUE_CLEAR(NAME, NODE_TYPE, FUNC)
 

Macro Definition Documentation

#define VTM_SQUEUE_STRUCT (   NODE_TYPE)
Value:
struct { \
NODE_TYPE *head; \
NODE_TYPE *tail; \
}

Defines the struct that holds the queue.

The struct definition that represents the items in the queue must have a member called "next" which must be a pointer to a struct instance.

Parameters
NODE_TYPEname of the struct whose instances are stored as items in the queue
#define VTM_SQUEUE_INIT (   NAME)
Value:
do { \
NAME.head = NULL; \
NAME.tail = NULL; \
} while (0)

Initializes the queue.

This function must be called, before any of the other functions can be used.

Parameters
NAMEthe target queue variable
#define VTM_SQUEUE_ADD (   NAME,
  NODE_PTR 
)
Value:
do { \
NODE_PTR->next = NULL; \
if (NAME.tail) \
NAME.tail->next = NODE_PTR; \
NAME.tail = NODE_PTR; \
if (!NAME.head) \
NAME.head = NODE_PTR; \
} while (0)

Adds an item to the queue.

Parameters
NAMEthe target queue variable
NODE_PTRpointer to struct instance that is added to the queue
#define VTM_SQUEUE_POLL (   NAME,
  NODE_PTR 
)
Value:
do { \
NODE_PTR = NAME.head; \
if (NAME.head) { \
NAME.head = NAME.head->next; \
if (NAME.tail == NODE_PTR) \
NAME.tail = NULL; \
} \
} while (0)

Retrieves and removes the head element of the queue.

Parameters
NAMEthe target queue variable
[out]NODE_PTRstores the retrieved element
#define VTM_SQUEUE_REMOVE (   NAME,
  NODE_PTR,
  PREV_PTR,
  FUNC 
)
Value:
do { \
if (PREV_PTR) \
PREV_PTR->next = NODE_PTR->next; \
else \
NAME.head = NODE_PTR->next; \
if (NODE_PTR == NAME.tail) \
NAME.tail = PREV_PTR; \
FUNC(NODE_PTR); \
} while (0)

Removes the given item from the queue.

Parameters
NAMEthe target queue variable
NODE_PTRthe item that should be removed
PREV_PTRthe predecessor of the item that should be removed
FUNCfunction pointer that is called with the removed element
#define VTM_SQUEUE_IS_EMPTY (   NAME)    (NAME.head == NULL)

Checks wether the queue is empty.

Parameters
NAMEthe target queue variable
#define VTM_SQUEUE_FOR_EACH (   NAME,
  NODE_PTR 
)
Value:
for (NODE_PTR = NAME.head; NODE_PTR != NULL; \
NODE_PTR = NODE_PTR->next)

Iterates through the queue.

Parameters
NAMEthe target queue variable
[out]NODE_PTRwill point to current item
#define VTM_SQUEUE_FOR_EACH_MOD (   NAME,
  NODE_PTR,
  PREV_PTR,
  NEXT_PTR 
)
Value:
for (NODE_PTR = NAME.head, \
PREV_PTR = NULL, \
NEXT_PTR = NODE_PTR ? NODE_PTR->next : NULL; \
NODE_PTR != NULL; \
PREV_PTR = NODE_PTR, \
NODE_PTR = NEXT_PTR, \
NEXT_PTR = NEXT_PTR ? NEXT_PTR->next : NULL)

Iterates through the queue and allows possible modification.

Parameters
NAMEthe target queue variable
[out]NODE_PTRwill point to current item
[out]PREV_PTRwill point to previous item, can be NULL
[out]NEXT_PTRwill point to next item, can be NULL
#define VTM_SQUEUE_CLEAR (   NAME,
  NODE_TYPE,
  FUNC 
)
Value:
do { \
NODE_TYPE *node; \
NODE_TYPE *prev; \
NODE_TYPE *next; \
VTM_UNUSED(prev); \
VTM_SQUEUE_FOR_EACH_MOD(NAME, node, prev, next) { \
FUNC(node); \
} \
NAME.head = NULL; \
NAME.tail = NULL; \
} while (0)
#define VTM_UNUSED(VAR)
Definition: macros.h:26
#define VTM_SQUEUE_FOR_EACH_MOD(NAME, NODE_PTR, PREV_PTR, NEXT_PTR)
Definition: squeue.h:124

Removes all items from the queue.

Parameters
NAMEthe target queue variable
NODE_TYPEname of the struct whose instances are stored as items in the queue
FUNCfunction pointer that is called with each removed element