summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-08-02 10:10:11 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-08-02 10:10:11 +0000
commit9ad676bab098d754b57265fc335a7f045e192d96 (patch)
tree3667c5b1442f1d9fda3498b500d6d21e46e201d8
parentdcec3c8c4e7bfb9c0cb904047d57188f6b377575 (diff)
downloadrsyslog-9ad676bab098d754b57265fc335a7f045e192d96.tar.gz
rsyslog-9ad676bab098d754b57265fc335a7f045e192d96.tar.xz
rsyslog-9ad676bab098d754b57265fc335a7f045e192d96.zip
enhanced linkedList class, new method to get count, new method to execute a
user-supplied function on all members
-rw-r--r--linkedlist.c44
-rw-r--r--linkedlist.h7
2 files changed, 51 insertions, 0 deletions
diff --git a/linkedlist.c b/linkedlist.c
index 2e0d5052..4037193b 100644
--- a/linkedlist.c
+++ b/linkedlist.c
@@ -206,6 +206,50 @@ rsRetVal llFind(linkedList_t *pThis, void *pKey, void **ppData)
return iRet;
}
+
+/* provide the count of linked list elements
+ */
+rsRetVal llGetNumElts(linkedList_t *pThis, int *piCnt)
+{
+ DEFiRet;
+
+ assert(pThis != NULL);
+ assert(piCnt != NULL);
+
+ *piCnt = pThis->iNumElts;
+
+ return iRet;
+}
+
+
+/* execute a function on all list members. The functions receives a
+ * user-supplied parameter, which may be either a simple value
+ * or a pointer to a structure with more data. If the user-supplied
+ * function does not return RS_RET_OK, this function here terminates.
+ * rgerhards, 2007-08-02
+ */
+rsRetVal llExecFunc(linkedList_t *pThis, rsRetVal (*pFunc)(void*, void*), void* pParam)
+{
+ DEFiRet;
+ rsRetVal iRetLL;
+ void *pData;
+ linkedListCookie_t llCookie = NULL;
+
+ assert(pThis != NULL);
+ assert(pFunc != NULL);
+
+ while((iRetLL = llGetNextElt(pThis, &llCookie, (void**)&pData)) == RS_RET_OK) {
+ CHKiRet(pFunc(pData, pParam));
+ }
+
+ if(iRetLL != RS_RET_END_OF_LINKEDLIST)
+ iRet = iRetLL;
+
+finalize_it:
+ return iRet;
+}
+
+
/*
* vi:set ai:
*/
diff --git a/linkedlist.h b/linkedlist.h
index da38e352..ac67a01b 100644
--- a/linkedlist.h
+++ b/linkedlist.h
@@ -58,5 +58,12 @@ rsRetVal llGetNextElt(linkedList_t *pThis, linkedListCookie_t *ppElt, void **ppU
rsRetVal llAppend(linkedList_t *pThis, void *pKey, void *pData);
rsRetVal llFind(linkedList_t *pThis, void *pKey, void **ppData);
rsRetVal llGetKey(llElt_t *pThis, void **ppData);
+rsRetVal llGetNumElts(linkedList_t *pThis, int *piCnt);
+rsRetVal llExecFunc(linkedList_t *pThis, rsRetVal (*pFunc)(void*, void*), void* pParam);
+/* use the macro below to define a function that will be executed by
+ * llExecFunc()
+ */
+#define DEFFUNC_llExecFunc(funcName)\
+ static rsRetVal funcName(void __attribute__((unused)) *pData, void __attribute__((unused)) *pParam)
#endif /* #ifndef LINKEDLIST_H_INCLUDED */