Hi Martin,
anbei ein paar Vorschläge zur Ergänzung der GWEN_LIST Funktionen. Gerade
neulich beim DeleteUser Programmieren ist mir aufgefallen, dass eine
generische Funktion zum Suchen nach einem Element in der Liste gar nicht
vorhanden ist, aber im Prinzip schon benutzt wird (z.B. in GWEN_List_Remove).
Hab deshalb den existierenden etwas umsortiert und ein paar Funktionen
hinzugefügt. Sieht das für dich okay aus?
Gruß
Christian
Index: src/base/list.c
===================================================================
--- src/base/list.c (Revision 1166)
+++ src/base/list.c (Arbeitskopie)
@@ -319,6 +319,9 @@
return l->listPtr->size;
}
+int GWEN_List_IsEmpty(const GWEN_LIST *l) {
+ return GWEN_List_GetSize(l) == 0;
+}
void GWEN_List_PopBack(GWEN_LIST *l){
@@ -529,8 +532,8 @@
-void GWEN_List_Remove(GWEN_LIST *l, const void *p) {
- GWEN_LIST_ITERATOR *li;
+GWEN_LIST_ITERATOR *GWEN_List_FindIter(GWEN_LIST *l, const void *p) {
+ GWEN_LIST_ITERATOR *li;
li=GWEN_List_First(l);
if (li) {
@@ -539,17 +542,37 @@
d=GWEN_ListIterator_Data(li);
while(d) {
if (d==p) {
- GWEN_List_Erase(l, li);
- break;
+ return li;
}
d=GWEN_ListIterator_Next(li);
}
GWEN_ListIterator_free(li);
}
+ return 0;
}
+const void *GWEN_List_Contains(GWEN_LIST *l, const void *p) {
+ GWEN_LIST_ITERATOR *li;
+ li = GWEN_List_FindIter(l, p);
+ if (li) {
+ GWEN_ListIterator_free(li);
+ return p;
+ }
+ return 0;
+}
+void GWEN_List_Remove(GWEN_LIST *l, const void *p) {
+ GWEN_LIST_ITERATOR *li;
+
+ li = GWEN_List_FindIter(l, p);
+ if (li) {
+ GWEN_List_Erase(l, li);
+ }
+}
+
+
+
GWEN_LIST_ITERATOR *GWEN_List_First(const GWEN_LIST *l){
GWEN_LIST_ITERATOR *li;
@@ -778,12 +801,16 @@
-unsigned int GWEN_ConstList_GetSize(GWEN_CONSTLIST *l){
+unsigned int GWEN_ConstList_GetSize(const GWEN_CONSTLIST *l){
return GWEN_List_GetSize(l);
}
+int GWEN_ConstList_IsEmpty(const GWEN_LIST *l) {
+ return GWEN_ConstList_GetSize(l) == 0;
+}
+
void GWEN_ConstList_PopBack(GWEN_CONSTLIST *l){
GWEN_List_PopBack(l);
}
@@ -832,6 +859,45 @@
+GWEN_CONSTLIST_ITERATOR *GWEN_ConstList_FindIter(const GWEN_CONSTLIST *l, const void *p) {
+ GWEN_CONSTLIST_ITERATOR *li;
+
+ li=GWEN_ConstList_First(l);
+ if (li) {
+ const void *d;
+
+ d=GWEN_ConstListIterator_Data(li);
+ while(d) {
+ if (d==p) {
+ return li;
+ }
+ d=GWEN_ConstListIterator_Next(li);
+ }
+ GWEN_ConstListIterator_free(li);
+ }
+ return 0;
+}
+
+const void *GWEN_ConstList_Contains(const GWEN_CONSTLIST *l, const void *p) {
+ GWEN_CONSTLIST_ITERATOR *li;
+
+ li = GWEN_ConstList_FindIter(l, p);
+ if (li) {
+ GWEN_ConstListIterator_free(li);
+ return p;
+ }
+ return 0;
+}
+
+void GWEN_ConstList_Remove(GWEN_CONSTLIST *l, const void *p) {
+ GWEN_CONSTLIST_ITERATOR *li;
+
+ li = GWEN_ConstList_FindIter(l, p);
+ if (li) {
+ GWEN_ConstList_Erase(l, li);
+ }
+}
+
GWEN_CONSTLIST_ITERATOR *GWEN_ConstList_First(const GWEN_CONSTLIST *l){
return GWEN_List_First(l);
}
Index: src/base/list.h
===================================================================
--- src/base/list.h (Revision 1166)
+++ src/base/list.h (Arbeitskopie)
@@ -168,9 +168,14 @@
GWENHYWFAR_API
void GWEN_List_Erase(GWEN_LIST *l, GWEN_LIST_ITERATOR *it);
-
+/**
+ * Searches for the first occurrence of the "element" pointer and
+ * erases that element from the list. (The element itself is not
+ * freed.) I.e. this function calls GWEN_List_Erase on the first
+ * occurrence found of "element".
+ */
GWENHYWFAR_API
-void GWEN_List_Remove(GWEN_LIST *l, const void *p);
+void GWEN_List_Remove(GWEN_LIST *l, const void *element);
/** Returns the size of this list, i.e. the number of elements in this
@@ -181,7 +186,12 @@
GWENHYWFAR_API
unsigned int GWEN_List_GetSize(const GWEN_LIST *l);
+/** Returns nonzero (TRUE) if this list is empty, and zero (FALSE) if
+ * this list is not empty. */
GWENHYWFAR_API
+int GWEN_List_IsEmpty(const GWEN_LIST *l);
+
+GWENHYWFAR_API
GWEN_REFPTR_INFO *GWEN_List_GetRefPtrInfo(const GWEN_LIST *l);
GWENHYWFAR_API
@@ -208,7 +218,23 @@
GWENHYWFAR_API
void GWEN_List_Clear(GWEN_LIST *l);
+/**
+ * Finds the LIST_ITERATOR position of the given element. The
+ * returned LIST_ITERATOR will be owned by the caller and must be
+ * freed when no longer in use. If the list does not contain the
+ * element, NULL will be returned.
+ */
+GWENHYWFAR_API
+GWEN_LIST_ITERATOR *GWEN_List_FindIter(GWEN_LIST *l, const void *element);
+/**
+ * Searches whether the list contains the given element. If it does,
+ * the pointer to the element is returned. Otherwise, NULL is
+ * returned.
+ */
+GWENHYWFAR_API
+const void *GWEN_List_Contains(GWEN_LIST *l, const void *element);
+
/** Traverses the list, calling the callback function 'func' on
* each list element. Traversal will stop when 'func' returns a
* non-NULL value, and the routine will return with that
@@ -337,8 +363,13 @@
* This number is counted in the list metadata, so this is a cheap
* operation. */
GWENHYWFAR_API
-unsigned int GWEN_ConstList_GetSize(GWEN_CONSTLIST *l);
+unsigned int GWEN_ConstList_GetSize(const GWEN_CONSTLIST *l);
+/** Returns nonzero (TRUE) if this list is empty, and zero (FALSE) if
+ * this list is not empty. */
+GWENHYWFAR_API
+int GWEN_ConstList_IsEmpty(const GWEN_LIST *l);
+
/**
* Removes the list's last element from the list. (The element is not
* freed.)
@@ -377,6 +408,32 @@
GWEN_CONSTLIST_FOREACH_CB func,
void *user_data);
+/**
+ * Finds the LIST_ITERATOR position of the given element. The
+ * returned LIST_ITERATOR will be owned by the caller and must be
+ * freed when no longer in use. If the list does not contain the
+ * element, NULL will be returned.
+ */
+GWENHYWFAR_API
+GWEN_CONSTLIST_ITERATOR *GWEN_ConstList_FindIter(const GWEN_CONSTLIST *l, const void *element);
+
+/**
+ * Searches whether the list contains the given element. If it does,
+ * the pointer to the element is returned. Otherwise, NULL is
+ * returned.
+ */
+GWENHYWFAR_API
+const void *GWEN_ConstList_Contains(const GWEN_CONSTLIST *l, const void *element);
+
+/**
+ * Searches for the first occurrence of the "element" pointer and
+ * erases that element from the list. (The element itself is not
+ * freed.) I.e. this function calls GWEN_List_Erase on the first
+ * occurrence found of "element".
+ */
+GWENHYWFAR_API
+void GWEN_ConstList_Remove(GWEN_CONSTLIST *l, const void *element);
+
/** Return an iterator pointing to the first element in the list */
GWENHYWFAR_API
GWEN_CONSTLIST_ITERATOR *GWEN_ConstList_First(const GWEN_CONSTLIST *l);
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Aqbanking-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/aqbanking-devel