Intrusive List ================ .. todo:: Check for ``typeof()`` availability. --------------------------------------------------------------- Types --------------------------------------------------------------- .. c:type:: ymo_list_head_t Generic list datastructure. .. code-block:: c :caption: Definition typedef struct ymo_list_head ymo_list_head_t; .. c:struct:: ymo_list_head Simple linked list head structure. .. code-block:: c :caption: Definition struct ymo_list_head { struct ymo_list_head* next; struct ymo_list_head* prev; }; --------------------------------------------------------------- Functions --------------------------------------------------------------- .. c:function:: static inline void ymo_list_insert( ymo_list_head_t* prev, ymo_list_head_t* current, ymo_list_head_t* next ) Insert an item into a list between ``prev`` and ``next`` (both of which may be null). .. c:function:: static inline const ymo_list_head_t* ymo_list_next(const ymo_list_head_t* head) Get the next item in a list. .. c:function:: static inline const ymo_list_head_t* ymo_list_prev(const ymo_list_head_t* head) Get the previous item in a list. --------------------------------------------------------------- Type-generic Macros --------------------------------------------------------------- .. c:macro:: YMO_LIST_HEAD_M Insert a list into a structure, using a specific name. .. code-block:: c :caption: Example typedef struct my_type { YMO_LIST_HEAD_M(head); char my_data[100]; } my_type_t; .. code-block:: c :caption: Definition #define YMO_LIST_HEAD_M(name) \ ymo_list_head_t name .. c:macro:: YMO_LIST_HEAD YMO_LIST_HEAD_M using a generic name. (See :c:macro:`YMO_LIST_HEAD_M`) .. code-block:: c :caption: Definition #define YMO_LIST_HEAD() \ ymo_list_head_t YMO_LIST_NAME_DEFAULT .. c:macro:: YMO_LIST_INIT_M Initialize a list head object. .. code-block:: c :caption: Example my_type_t my_obj; YMO_LIST_INIT_M(&my_obj, head); .. code-block:: c :caption: Definition #define YMO_LIST_INIT_M(p, m) \ ((p)->m->prev = (p)->m->next = NULL) .. c:macro:: YMO_LIST_INIT YMO_LIST_INIT_M using a generic name. (See :c:macro:`YMO_LIST_INIT_M`) .. code-block:: c :caption: Definition #define YMO_LIST_INIT(p) \ YMO_LIST_INIT_M(p, YMO_LIST_NAME_DEFAULT) .. c:macro:: YMO_LIST_APPEND_M Append an item to c list. .. code-block:: c :caption: Example my_type_t c; my_type_t n; YMO_LIST_INIT(&c, head); YMO_LIST_INIT(&n, head); YMO_LIST_APPEND_M(&c, &n, head); .. code-block:: c :caption: Definition #define YMO_LIST_APPEND_M(c, n, m) \ ymo_list_insert(&c->m, &n->m, NULL) .. c:macro:: YMO_LIST_APPEND YMO_LIST_APPEND_M using c generic name. (See :c:macro:`YMO_LIST_APPEND_M`) .. code-block:: c :caption: Definition #define YMO_LIST_APPEND(c, n) \ YMO_LIST_APPEND_M(c, n, YMO_LIST_NAME_DEFAULT) .. c:macro:: YMO_LIST_INSERT_M .. code-block:: c :caption: Definition #define YMO_LIST_INSERT_M(p, c, n, m) \ ymo_list_insert(p->m, c->m, n->m) .. c:macro:: YMO_LIST_INSERT YMO_LIST_INSERT_M using a generic name. (See :c:macro:`YMO_LIST_INSERT_M`) .. code-block:: c :caption: Definition #define YMO_LIST_INSERT(p, c, n) \ YMO_LIST_INSERT_M(p, c, n, YMO_LIST_NAME_DEFAULT) .. c:macro:: YMO_LIST_NEXT_M .. code-block:: c :caption: Definition #define YMO_LIST_NEXT_M(p, t, m) \ ((t*)(((YMO_LIST_PTR_AR_TYPE)ymo_list_next(&p->m)) - offsetof(t,m))) .. c:macro:: YMO_LIST_NEXT YMO_LIST_NEXT_M using a generic name. (See :c:macro:`YMO_LIST_NEXT_M`) .. code-block:: c :caption: Definition #define YMO_LIST_NEXT(p, t) \ YMO_LIST_NEXT_M(p, t, YMO_LIST_NAME_DEFAULT) .. c:macro:: YMO_LIST_PREV_M .. code-block:: c :caption: Definition #define YMO_LIST_PREV_M(p, t, m) \ ((t*)(((YMO_LIST_PTR_AR_TYPE)ymo_list_prev(&p->m)) - offsetof(t,m))) .. c:macro:: YMO_LIST_PREV YMO_LIST_PREV_M using a generic name. (See :c:macro:`YMO_LIST_PREV_M`) .. code-block:: c :caption: Definition #define YMO_LIST_PREV(p, t) \ YMO_LIST_PREV_M(p, t, YMO_LIST_NAME_DEFAULT) .. c:macro:: YMO_LIST_LAST_M .. code-block:: c :caption: Definition #define YMO_LIST_LAST_M(c, t, m) \ ((t*)(((YMO_LIST_PTR_AR_TYPE)ymo_list_last(&c->m)) - offsetof(t,m))) .. c:macro:: YMO_LIST_LAST YMO_LIST_LAST_M using a generic name. (See :c:macro:`YMO_LIST_LAST_M`) .. code-block:: c :caption: Definition #define YMO_LIST_LAST(c, t) \ YMO_LIST_LAST_M(c, t, YMO_LIST_NAME_DEFAULT)