rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rlist.h
Go to the documentation of this file.
1/* RLIB - Convenience library for useful things
2 * Copyright (C) 2015-2018 Haakon Sporsheim <haakon.sporsheim@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3.0 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library.
16 * See the COPYING file at the root of the source repository.
17 */
18#ifndef __R_LIST_H__
19#define __R_LIST_H__
20
21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
23#endif
24
63#include <rlib/data/rlist-internal.h>
64#include <rlib/data/rcbctx.h>
66
67#include <rlib/rmem.h>
68
70
73R__LIST_DECL (RList, r_list, rpointer, R_API)
75#define r_list_prepend r_list_prepend_copy
77#define r_list_append r_list_append_copy
79#define r_list_contains r_list_contains_full
84R__SLIST_DECL (RSList, r_slist, rpointer, R_API)
86#define r_slist_prepend r_slist_prepend_copy
88#define r_slist_append r_slist_append_copy
90#define r_slist_contains r_slist_contains_full
106
107R__SLIST_DECL (RFreeList, r_free_list, RFreePtrCtx, R_API)
108
109static inline RFreeList * r_free_list_alloc (rpointer ptr, RDestroyNotify notify)
110{
111 RFreeList * ret;
112 if ((ret = r_free_list_alloc0 ()) != NULL) {
113 ret->data.ptr = ptr;
114 ret->data.notify = notify;
115 }
116 return ret;
117}
118static inline RFreeList * r_free_list_prepend (RFreeList * lst,
119 rpointer ptr, RDestroyNotify notify)
120{
121 return r_free_list_prepend_link (lst, r_free_list_alloc (ptr, notify));
122}
123
132R__LIST_DECL (RCBList, r_cblist, RFuncCallbackCtx, R_API)
133
134
136 rpointer data, RDestroyNotify datanotify,
137 rpointer user, RDestroyNotify usernotify) R_ATTR_MALLOC;
139#define r_cblist_alloc(cb, data, user) \
140 r_cblist_alloc_full (cb, data, NULL, user, NULL)
142R_API RCBList * r_cblist_prepend_full (RCBList * head, RFunc cb,
143 rpointer data, RDestroyNotify datanotify,
146#define r_cblist_prepend(head, cb, data, user) \
147 r_cblist_prepend_full (head, cb, data, NULL, user, NULL)
149R_API RCBList * r_cblist_append_full (RCBList * entry, RFunc cb,
150 rpointer data, RDestroyNotify datanotify,
153#define r_cblist_append(head, cb, data, user) \
154 r_cblist_append_full (head, cb, data, NULL, user, NULL)
156R_API rboolean r_cblist_contains (RCBList * head, RFunc cb, rpointer data);
161R_API rsize r_cblist_call (RCBList * head);
162
172R__LIST_DECL (RCBRList, r_cbrlist, RFuncReturnCallbackCtx, R_API)
173
174
176 rpointer data, RDestroyNotify datanotify,
177 rpointer user, RDestroyNotify usernotify) R_ATTR_MALLOC;
179#define r_cbrlist_alloc(cb, data, user) \
180 r_cbrlist_alloc_full (cb, data, NULL, user, NULL)
182R_API RCBRList * r_cbrlist_prepend_full (RCBRList * head, RFuncReturn cb,
183 rpointer data, RDestroyNotify datanotify,
186#define r_cbrlist_prepend(head, cb, data, user) \
187 r_cbrlist_prepend_full (head, cb, data, NULL, user, NULL)
189R_API RCBRList * r_cbrlist_append_full (RCBRList * entry, RFuncReturn cb,
190 rpointer data, RDestroyNotify datanotify,
193#define r_cbrlist_append(head, cb, data, user) \
194 r_cbrlist_append_full (head, cb, data, NULL, user, NULL)
204R_API RCBRList * r_cbrlist_call (RCBRList * head) R_ATTR_WARN_UNUSED_RESULT;
205
213R__SLIST_DECL (RCBSList, r_cbslist, RFuncCallbackCtx, R_API)
214
215
217 rpointer data, RDestroyNotify datanotify,
218 rpointer user, RDestroyNotify usernotify) R_ATTR_MALLOC;
220#define r_cbslist_alloc(cb, data, user) \
221 r_cbslist_alloc_full (cb, data, NULL, user, NULL)
223R_API RCBSList * r_cbslist_prepend_full (RCBSList * head, RFunc cb,
224 rpointer data, RDestroyNotify datanotify,
227#define r_cbslist_prepend(head, cb, data, user) \
228 r_cbslist_prepend_full (head, cb, data, NULL, user, NULL)
230R_API RCBSList * r_cbslist_append_full (RCBSList * entry, RFunc cb,
231 rpointer data, RDestroyNotify datanotify,
234#define r_cbslist_append(head, cb, data, user) \
235 r_cbslist_append_full (head, cb, data, NULL, user, NULL)
237R_API rboolean r_cbslist_contains (RCBSList * head, RFunc cb, rpointer data);
239R_API rsize r_cbslist_call (RCBSList * head);
240
243R_END_DECLS
244
247#endif /* __R_LIST_H__ */
rboolean r_cblist_contains(RCBList *head, RFunc cb, rpointer data)
TRUE iff head contains a matching (cb, data) pair.
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.
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.
RCBSList * r_cbslist_alloc_full(RFunc cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify)
Allocate a standalone callback node (singly-linked).
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.
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.
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.
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.
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.
RCBRList * r_cbrlist_call(RCBRList *head) R_ATTR_WARN_UNUSED_RESULT
Iterate the list, removing entries whose callback returned FALSE.
RCBList * r_cblist_alloc_full(RFunc cb, rpointer data, RDestroyNotify datanotify, rpointer user, RDestroyNotify usernotify)
Allocate a standalone callback node with full ownership wiring.
rboolean r_cbslist_contains(RCBSList *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.
rsize r_cbslist_call(RCBSList *head)
Invoke every callback in the list; returns the number called.
#define NULL
Null pointer constant (defined only if absent).
Definition rmacros.h:126
#define R_ATTR_WARN_UNUSED_RESULT
Warn if a function's return value is ignored.
Definition rmacros.h:278
#define R_API
Public-API decoration: resolves to R_API_EXPORT while building rlib and R_API_IMPORT for consumers.
Definition rmacros.h:115
#define R_BEGIN_DECLS
Open an extern "C" block under C++ (no-op in C).
Definition rmacros.h:196
int rboolean
Boolean type (typedef'd to int).
Definition rtypes.h:59
void(* RFunc)(rpointer data, rpointer user)
Generic iteration callback over (data, user) pairs.
Definition rtypes.h:403
void(* RDestroyNotify)(rpointer ptr)
Destructor callback: free / release the value at ptr.
Definition rtypes.h:401
void * rpointer
Generic pointer (alias for void *).
Definition rtypes.h:327
unsigned long rsize
Unsigned pointer-sized size type (like size_t).
Definition rtypes.h:290
rboolean(* RFuncReturn)(rpointer data, rpointer user)
Iteration callback that can short-circuit by returning FALSE.
Definition rtypes.h:419
Callback + data + user-data + per-side destroy-notify tuples used by Linked lists,...
Pre-built hash / equality function pairs for the common key types (pointer-identity,...
Memory allocation, byte-buffer operations, and pattern scanning.
(pointer, destroy-notifier) pair stored in RFreeList.
Definition rlist.h:102
rpointer ptr
Definition rlist.h:103
RDestroyNotify notify
Definition rlist.h:104
Callback context for a void-returning function.
Definition rcbctx.h:61
Callback context for a function that returns rboolean.
Definition rcbctx.h:98