rlib
Convenience library for useful things
Loading...
Searching...
No Matches
Linked lists

Doubly- and singly-linked list templates plus the four callback-flavoured specialisations that the rest of rlib uses to manage deferred work. More...

Files

file  rlist.h
 Linked-list types: doubly / singly linked plus the callback-flavoured specialisations.
 

Data Structures

struct  RFreePtrCtx
 (pointer, destroy-notifier) pair stored in RFreeList. More...
 

Free list — defer cleanup of heterogeneous resources

static RFreeList * r_free_list_alloc (rpointer ptr, RDestroyNotify notify)
 
static RFreeList * r_free_list_prepend (RFreeList *lst, rpointer ptr, RDestroyNotify notify)
 

Callback list (RCBList — doubly-linked)

Doubly-linked list of RFuncCallbackCtx tuples. Use for "fire these callbacks later in order" patterns where the caller also needs to walk in reverse.

RCBList * r_cblist_alloc_full (RFunc cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify)
 Allocate a standalone callback node with full ownership wiring.
 
RCBList * r_cblist_prepend_full (RCBList *head, RFunc cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify) R_ATTR_WARN_UNUSED_RESULT
 Prepend a new callback to the head with full ownership wiring.
 
RCBList * r_cblist_append_full (RCBList *entry, RFunc cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify) R_ATTR_WARN_UNUSED_RESULT
 Append a new callback to the tail with full ownership wiring.
 
rboolean r_cblist_contains (RCBList *head, RFunc cb, rpointer data)
 TRUE iff head contains a matching (cb, data) pair.
 
rsize r_cblist_call (RCBList *head)
 Invoke every callback in the list in order; returns the number called.
 
#define r_cblist_alloc(cb, data, user)    r_cblist_alloc_full (cb, data, NULL, user, NULL)
 Convenience: allocate without destroy notifiers.
 
#define r_cblist_prepend(head, cb, data, user)    r_cblist_prepend_full (head, cb, data, NULL, user, NULL)
 Convenience: prepend without destroy notifiers.
 
#define r_cblist_append(head, cb, data, user)    r_cblist_append_full (head, cb, data, NULL, user, NULL)
 Convenience: append without destroy notifiers.
 

Return-value callback list (RCBRList — doubly-linked)

Same shape as RCBList but each callback returns rboolean; nodes whose callback returns FALSE are removed from the list during iteration. Use for one-shot subscribers or filter chains.

RCBRList * r_cbrlist_alloc_full (RFuncReturn cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify)
 Allocate a standalone return-callback node with full ownership wiring.
 
RCBRList * r_cbrlist_prepend_full (RCBRList *head, RFuncReturn cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify) R_ATTR_WARN_UNUSED_RESULT
 Prepend a return-callback to the head.
 
RCBRList * r_cbrlist_append_full (RCBRList *entry, RFuncReturn cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify) R_ATTR_WARN_UNUSED_RESULT
 Append a return-callback to the tail.
 
rboolean r_cbrlist_contains (RCBRList *head, RFuncReturn cb, rpointer data)
 TRUE iff head contains a matching (cb, data) pair.
 
RCBRList * r_cbrlist_call (RCBRList *head) R_ATTR_WARN_UNUSED_RESULT
 Iterate the list, removing entries whose callback returned FALSE.
 
#define r_cbrlist_alloc(cb, data, user)    r_cbrlist_alloc_full (cb, data, NULL, user, NULL)
 Convenience: allocate without destroy notifiers.
 
#define r_cbrlist_prepend(head, cb, data, user)    r_cbrlist_prepend_full (head, cb, data, NULL, user, NULL)
 Convenience: prepend without destroy notifiers.
 
#define r_cbrlist_append(head, cb, data, user)    r_cbrlist_append_full (head, cb, data, NULL, user, NULL)
 Convenience: append without destroy notifiers.
 

Callback list (RCBSList — singly-linked)

Same surface as RCBList but with singly-linked storage; cheaper when reverse traversal isn't needed.

RCBSList * r_cbslist_alloc_full (RFunc cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify)
 Allocate a standalone callback node (singly-linked).
 
RCBSList * r_cbslist_prepend_full (RCBSList *head, RFunc cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify) R_ATTR_WARN_UNUSED_RESULT
 Prepend a new callback.
 
RCBSList * r_cbslist_append_full (RCBSList *entry, RFunc cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify) R_ATTR_WARN_UNUSED_RESULT
 Append a new callback.
 
rboolean r_cbslist_contains (RCBSList *head, RFunc cb, rpointer data)
 TRUE iff head contains a matching (cb, data) pair.
 
rsize r_cbslist_call (RCBSList *head)
 Invoke every callback in the list; returns the number called.
 
#define r_cbslist_alloc(cb, data, user)    r_cbslist_alloc_full (cb, data, NULL, user, NULL)
 Convenience: allocate without destroy notifiers.
 
#define r_cbslist_prepend(head, cb, data, user)    r_cbslist_prepend_full (head, cb, data, NULL, user, NULL)
 Convenience: prepend without destroy notifiers.
 
#define r_cbslist_append(head, cb, data, user)    r_cbslist_append_full (head, cb, data, NULL, user, NULL)
 Convenience: append without destroy notifiers.
 

Doubly-linked list (RList) of rpointer values

#define r_list_prepend   r_list_prepend_copy
 Convenience: prepend defaults to value-copy semantics.
 
#define r_list_append   r_list_append_copy
 Convenience: append defaults to value-copy semantics.
 
#define r_list_contains   r_list_contains_full
 Convenience: contains defaults to identity equality.
 

Singly-linked list (RSList) of rpointer values

#define r_slist_prepend   r_slist_prepend_copy
 Convenience: prepend defaults to value-copy semantics.
 
#define r_slist_append   r_slist_append_copy
 Convenience: append defaults to value-copy semantics.
 
#define r_slist_contains   r_slist_contains_full
 Convenience: contains defaults to identity equality.
 

Detailed Description

Doubly- and singly-linked list templates plus the four callback-flavoured specialisations that the rest of rlib uses to manage deferred work.

Five list types are declared in this header, all generated from R__LIST_DECL / R__SLIST_DECL templates in rlist-internal.h so the surface is uniform across types:

Each type carries the standard set of _alloc / _alloc_full / _prepend / _append / _contains / _destroy accessors emitted by the template. The macros in this header (r_list_prepend = r_list_prepend_copy etc.) make value-by-copy the default insertion path.

Function Documentation

◆ r_cbrlist_call()

RCBRList * r_cbrlist_call ( RCBRList *  head)

Iterate the list, removing entries whose callback returned FALSE.

Returns
The (possibly shorter) list head; pass back through the original variable.