rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rlist.h File Reference

Linked-list types: doubly / singly linked plus the callback-flavoured specialisations. More...

#include <rlib/data/rlist-internal.h>
#include <rlib/data/rcbctx.h>
#include <rlib/data/rhashfuncs.h>
#include <rlib/rmem.h>

Go to the source code of this file.

Data Structures

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

Macros

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.
 

Functions

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.

#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.
 
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.
 

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.

#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.
 
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.
 

Callback list (RCBSList — singly-linked)

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

#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.
 
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.
 

Detailed Description

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