PokerUnicorn
Loading...
Searching...
No Matches
Sugars

Cute macros. More...

#define STRINGIFY(x)   #x
 
#define TOSTRING(x)   STRINGIFY(x)
 
#define VARCAT(left, right)   left##right
 
#define LIST_FOREACH(list, node)
 
#define END_FOREACH    }}
 
#define LISTIFY(type)
 
#define ITEMIFY(type)
 
#define LIST_INIT(list)
 
#define LIST_ITEM_INIT(list)
 
#define LIST_APPEND(list, node)
 
#define LIST_PREPEND(list, node)
 
#define LIST_REMOVE(list, node)
 
#define LIST_SORT(list, a, b, cmp_expr)
 
#define R(expr)   PKRSRV_REF_BY(expr)
 

Detailed Description

Cute macros.

Macro Definition Documentation

◆ STRINGIFY

#define STRINGIFY ( x)    #x

◆ TOSTRING

#define TOSTRING ( x)    STRINGIFY(x)

◆ VARCAT

#define VARCAT ( left,
right )   left##right

◆ LIST_FOREACH

#define LIST_FOREACH ( list,
node )
Value:
{ \
int VARCAT(node, _i) = -1; \
__typeof__(list->next) _##node = NULL; \
__typeof__(list->next) _next_##node = list->next; \
while (_next_##node) { \
VARCAT(node, _i)++; \
__typeof__(list->next) node = _next_##node; \
_next_##node = (_next_##node)->next;
#define VARCAT(left, right)
Definition sugar.h:24

◆ END_FOREACH

#define END_FOREACH    }}

◆ LISTIFY

#define LISTIFY ( type)
Value:
type next; \
type prev; \
type terminal; \
int length;

◆ ITEMIFY

#define ITEMIFY ( type)
Value:
type next; \
type prev;

◆ LIST_INIT

#define LIST_INIT ( list)
Value:
list->prev = NULL; \
list->next = NULL; \
list->terminal = NULL; \
list->length = 0;

◆ LIST_ITEM_INIT

#define LIST_ITEM_INIT ( list)
Value:
list->prev = NULL; \
list->next = NULL;

◆ LIST_APPEND

#define LIST_APPEND ( list,
node )
Value:
if (!list->next) { \
list->next = node; \
} \
\
node->prev = list->terminal; \
if (list->terminal) { \
list->terminal->next = node; \
} \
list->terminal = node; \
\
list->length++;

◆ LIST_PREPEND

#define LIST_PREPEND ( list,
node )
Value:
node->prev = NULL; \
if (!list->next) { \
list->next = node; \
list->terminal = node; \
} else { \
node->next = list->next; \
list->next->prev = node; \
list->next = node; \
} \
list->length++;

◆ LIST_REMOVE

#define LIST_REMOVE ( list,
node )
Value:
if (list->terminal == node) { \
list->terminal = node->next \
? node->next \
: node->prev; \
} \
if (list->next == node) { \
list->next = node->next; \
} \
\
if (node->next) { \
node->next->prev = node->prev; \
} \
\
if (node->prev) { \
node->prev->next = node->next; \
} \
list->length--;

◆ LIST_SORT

#define LIST_SORT ( list,
a,
b,
cmp_expr )
Value:
{ \
__typeof__(list->next) array[list->length]; \
LIST_FOREACH(list, node) \
array[node_i] = node; \
for (int i = 0; i < list->length; i++) { \
for (int j = i + 1; j < list->length; j++) { \
if (cmp_expr) { \
__typeof__(list->next) tmp = array[i]; \
array[i] = array[j]; \
airray[j] = tmp; \
} \
} \
} \
if (list->length) { \
list->next = array[0]; \
list->terminal = array[list->length - 1]; \
} \
}
#define LIST_FOREACH(list, node)
Definition sugar.h:26
#define END_FOREACH
Definition sugar.h:35

◆ R

#define R ( expr)    PKRSRV_REF_BY(expr)