gwenhywfar
4.3.1
|
00001 /*************************************************************************** 00002 begin : Sat Nov 15 2003 00003 copyright : (C) 2003 by Martin Preuss 00004 email : martin@libchipcard.de 00005 00006 *************************************************************************** 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * 00021 * MA 02111-1307 USA * 00022 * * 00023 ***************************************************************************/ 00024 00025 00026 #ifdef HAVE_CONFIG_H 00027 # include <config.h> 00028 #endif 00029 00030 #define DISABLE_DEBUGLOG 00031 00032 00033 #include "list_p.h" 00034 #include <gwenhywfar/misc.h> 00035 #include <gwenhywfar/debug.h> 00036 00037 00038 GWEN_INHERIT_FUNCTIONS(GWEN_LIST) 00039 00040 00041 00042 GWEN_LIST_ENTRY *GWEN_ListEntry_new(void){ 00043 GWEN_LIST_ENTRY *le; 00044 00045 GWEN_NEW_OBJECT(GWEN_LIST_ENTRY, le); 00046 le->usage=1; 00047 return le; 00048 } 00049 00050 00051 00052 void GWEN_ListEntry_free(GWEN_LIST_ENTRY *le){ 00053 if (le) { 00054 if (le->usage) { 00055 le->usage--; 00056 if (le->usage==0) { 00057 /* unlink */ 00058 le->previous=0; 00059 le->next=0; 00060 DBG_VERBOUS(GWEN_LOGDOMAIN, "Freeing entry"); 00061 GWEN_RefPtr_free(le->dataPtr); 00062 /* really free */ 00063 GWEN_FREE_OBJECT(le); 00064 } 00065 } 00066 } 00067 } 00068 00069 00070 00071 GWEN__LISTPTR *GWEN__ListPtr_new(void){ 00072 GWEN__LISTPTR *lp; 00073 00074 GWEN_NEW_OBJECT(GWEN__LISTPTR, lp); 00075 lp->refCount=1; 00076 return lp; 00077 } 00078 00079 00080 00081 void GWEN__ListPtr_free(GWEN__LISTPTR *lp){ 00082 if (lp) { 00083 assert(lp->refCount); 00084 if (--(lp->refCount)==0) { 00085 GWEN__ListPtr_Clear(lp); 00086 GWEN_FREE_OBJECT(lp); 00087 } 00088 } 00089 } 00090 00091 00092 00093 void GWEN__ListPtr_Attach(GWEN__LISTPTR *lp){ 00094 assert(lp); 00095 assert(lp->refCount); 00096 lp->refCount++; 00097 } 00098 00099 00100 00101 void GWEN__ListPtr_Clear(GWEN__LISTPTR *lp){ 00102 GWEN_LIST_ENTRY *le; 00103 00104 assert(lp); 00105 le=lp->first; 00106 while(le) { 00107 GWEN_LIST_ENTRY *nle; 00108 00109 nle=le->next; 00110 GWEN_ListEntry_free(le); 00111 le=nle; 00112 } /* while */ 00113 lp->first=0; 00114 lp->last=0; 00115 lp->size=0; 00116 } 00117 00118 00119 00120 GWEN__LISTPTR *GWEN__ListPtr_dup(GWEN__LISTPTR *lp){ 00121 GWEN__LISTPTR *nlp; 00122 GWEN_LIST_ENTRY *le; 00123 00124 nlp=GWEN__ListPtr_new(); 00125 assert(lp); 00126 le=lp->first; 00127 while(le) { 00128 GWEN_LIST_ENTRY *nle; 00129 00130 nle=GWEN_ListEntry_new(); 00131 if (le->dataPtr) 00132 nle->dataPtr=GWEN_RefPtr_dup(le->dataPtr); 00133 /* push back */ 00134 nle->previous=nlp->last; 00135 if (nlp->last) 00136 nlp->last->next=nle; 00137 nlp->last=nle; 00138 if (!(nlp->first)) 00139 nlp->first=nle; 00140 nlp->size++; 00141 nle->linkCount=le->linkCount; 00142 00143 le=le->next; 00144 } /* while */ 00145 00146 return nlp; 00147 } 00148 00149 00150 00151 00152 00153 00154 00155 00156 GWEN_LIST *GWEN_List_new(void){ 00157 GWEN_LIST *l; 00158 00159 GWEN_NEW_OBJECT(GWEN_LIST, l); 00160 GWEN_INHERIT_INIT(GWEN_LIST, l); 00161 l->listPtr=GWEN__ListPtr_new(); 00162 return l; 00163 } 00164 00165 00166 00167 void GWEN_List_free(GWEN_LIST *l){ 00168 if (l) { 00169 GWEN_INHERIT_FINI(GWEN_LIST, l); 00170 GWEN__ListPtr_free(l->listPtr); 00171 GWEN_RefPtrInfo_free(l->refPtrInfo); 00172 GWEN_FREE_OBJECT(l); 00173 } 00174 } 00175 00176 00177 00178 GWEN_LIST *GWEN_List_dup(const GWEN_LIST *l){ 00179 GWEN_LIST *nl; 00180 00181 assert(l); 00182 assert(l->listPtr); 00183 GWEN_NEW_OBJECT(GWEN_LIST, nl); 00184 GWEN_INHERIT_INIT(GWEN_LIST, nl); 00185 nl->listPtr=l->listPtr; 00186 GWEN__ListPtr_Attach(nl->listPtr); 00187 return nl; 00188 } 00189 00190 00191 00192 GWEN_REFPTR_INFO *GWEN_List_GetRefPtrInfo(const GWEN_LIST *l){ 00193 assert(l); 00194 return l->refPtrInfo; 00195 } 00196 00197 00198 00199 void GWEN_List_SetRefPtrInfo(GWEN_LIST *l, GWEN_REFPTR_INFO *rpi){ 00200 assert(l); 00201 if (rpi) 00202 GWEN_RefPtrInfo_Attach(rpi); 00203 GWEN_RefPtrInfo_free(l->refPtrInfo); 00204 l->refPtrInfo=rpi; 00205 } 00206 00207 00208 00209 void GWEN_List_PushBackRefPtr(GWEN_LIST *l, GWEN_REFPTR *rp){ 00210 GWEN_LIST_ENTRY *le; 00211 GWEN__LISTPTR *lp; 00212 00213 if (l->listPtr->refCount>1) { 00214 GWEN__LISTPTR *nlp; 00215 00216 /* only copy the list if someone else is using it */ 00217 nlp=GWEN__ListPtr_dup(l->listPtr); 00218 GWEN__ListPtr_free(l->listPtr); 00219 l->listPtr=nlp; 00220 } 00221 lp=l->listPtr; 00222 00223 le=GWEN_ListEntry_new(); 00224 le->dataPtr=rp; 00225 le->previous=lp->last; 00226 if (lp->last) 00227 lp->last->next=le; 00228 lp->last=le; 00229 if (!(lp->first)) 00230 lp->first=le; 00231 lp->size++; 00232 le->linkCount=1; 00233 } 00234 00235 00236 00237 void GWEN_List_PushBack(GWEN_LIST *l, void *p){ 00238 GWEN_List_PushBackRefPtr(l, GWEN_RefPtr_new(p, l->refPtrInfo)); 00239 } 00240 00241 00242 00243 void GWEN_List_PushFrontRefPtr(GWEN_LIST *l, GWEN_REFPTR *rp){ 00244 GWEN_LIST_ENTRY *le; 00245 GWEN__LISTPTR *lp; 00246 00247 if (l->listPtr->refCount>1) { 00248 GWEN__LISTPTR *nlp; 00249 00250 /* only copy the list if someone else is using it */ 00251 nlp=GWEN__ListPtr_dup(l->listPtr); 00252 GWEN__ListPtr_free(l->listPtr); 00253 l->listPtr=nlp; 00254 } 00255 lp=l->listPtr; 00256 00257 le=GWEN_ListEntry_new(); 00258 le->dataPtr=rp; 00259 le->next=lp->first; 00260 if (lp->first) 00261 lp->first->previous=le; 00262 lp->first=le; 00263 if (!(lp->last)) 00264 lp->last=le; 00265 lp->size++; 00266 le->linkCount=1; 00267 } 00268 00269 00270 00271 void GWEN_List_PushFront(GWEN_LIST *l, void *p){ 00272 GWEN_List_PushFrontRefPtr(l, GWEN_RefPtr_new(p, l->refPtrInfo)); 00273 } 00274 00275 00276 00277 void *GWEN_List_GetFront(const GWEN_LIST *l){ 00278 assert(l); 00279 assert(l->listPtr); 00280 if (l->listPtr->first) 00281 return GWEN_RefPtr_GetData(l->listPtr->first->dataPtr); 00282 return 0; 00283 } 00284 00285 00286 00287 GWEN_REFPTR *GWEN_List_GetFrontRefPtr(const GWEN_LIST *l){ 00288 assert(l); 00289 assert(l->listPtr); 00290 if (l->listPtr->first) 00291 return l->listPtr->first->dataPtr; 00292 return 0; 00293 } 00294 00295 00296 00297 void *GWEN_List_GetBack(const GWEN_LIST *l){ 00298 assert(l); 00299 assert(l->listPtr); 00300 if (l->listPtr->last) 00301 return GWEN_RefPtr_GetData(l->listPtr->last->dataPtr); 00302 return 0; 00303 } 00304 00305 00306 00307 GWEN_REFPTR *GWEN_List_GetBackRefPtr(const GWEN_LIST *l){ 00308 assert(l); 00309 assert(l->listPtr); 00310 if (l->listPtr->last) 00311 return l->listPtr->last->dataPtr; 00312 return 0; 00313 } 00314 00315 00316 00317 unsigned int GWEN_List_GetSize(const GWEN_LIST *l){ 00318 assert(l); 00319 assert(l->listPtr); 00320 return l->listPtr->size; 00321 } 00322 00323 int GWEN_List_IsEmpty(const GWEN_LIST *l) { 00324 return GWEN_List_GetSize(l) == 0; 00325 } 00326 00327 00328 void GWEN_List_PopBack(GWEN_LIST *l){ 00329 GWEN_LIST_ENTRY *le; 00330 GWEN__LISTPTR *lp; 00331 00332 assert(l); 00333 assert(l->listPtr); 00334 if (l->listPtr->last==0) 00335 return; 00336 if (l->listPtr->refCount>1) { 00337 GWEN__LISTPTR *nlp; 00338 00339 /* only copy the list if someone else is using it */ 00340 nlp=GWEN__ListPtr_dup(l->listPtr); 00341 GWEN__ListPtr_free(l->listPtr); 00342 l->listPtr=nlp; 00343 } 00344 lp=l->listPtr; 00345 00346 le=lp->last; 00347 if (le) { 00348 le->linkCount=0; 00349 lp->last=le->previous; 00350 if (le->previous) { 00351 le->previous->next=0; 00352 } 00353 else { 00354 lp->last=0; 00355 lp->first=0; 00356 } 00357 GWEN_ListEntry_free(le); 00358 lp->size--; 00359 } 00360 } 00361 00362 00363 00364 void GWEN_List_PopFront(GWEN_LIST *l){ 00365 GWEN_LIST_ENTRY *le; 00366 GWEN__LISTPTR *lp; 00367 00368 assert(l); 00369 assert(l->listPtr); 00370 if (l->listPtr->first==0) 00371 return; 00372 if (l->listPtr->refCount>1) { 00373 GWEN__LISTPTR *nlp; 00374 00375 /* only copy the list if someone else is using it */ 00376 nlp=GWEN__ListPtr_dup(l->listPtr); 00377 GWEN__ListPtr_free(l->listPtr); 00378 l->listPtr=nlp; 00379 } 00380 lp=l->listPtr; 00381 00382 le=lp->first; 00383 if (le) { 00384 le->linkCount=0; 00385 lp->first=le->next; 00386 if (le->next) { 00387 le->next->previous=0; 00388 } 00389 else { 00390 lp->first=0; 00391 lp->last=0; 00392 } 00393 GWEN_ListEntry_free(le); 00394 lp->size--; 00395 } 00396 } 00397 00398 00399 00400 void GWEN_List_Clear(GWEN_LIST *l){ 00401 /* GWEN__LISTPTR *lp; */ 00402 00403 assert(l); 00404 if (l->listPtr->refCount>1) { 00405 GWEN__LISTPTR *nlp; 00406 00407 /* only copy the list if someone else is using it */ 00408 nlp=GWEN__ListPtr_dup(l->listPtr); 00409 GWEN__ListPtr_free(l->listPtr); 00410 l->listPtr=nlp; 00411 } 00412 else 00413 GWEN__ListPtr_Clear(l->listPtr); 00414 } 00415 00416 00417 00418 void *GWEN_List_ForEach(GWEN_LIST *l, 00419 GWEN_LIST_FOREACH_CB fn, void *user_data){ 00420 GWEN_LIST_ITERATOR *it; 00421 void *el; 00422 assert(l); 00423 00424 it=GWEN_List_First(l); 00425 if (!it) 00426 return 0; 00427 el=GWEN_ListIterator_Data(it); 00428 while(el) { 00429 el=fn(el, user_data); 00430 if (el) { 00431 GWEN_ListIterator_free(it); 00432 return el; 00433 } 00434 el=GWEN_ListIterator_Next(it); 00435 } 00436 GWEN_ListIterator_free(it); 00437 return 0; 00438 } 00439 00440 00441 00442 void GWEN_List_Unshare(GWEN_LIST *l) { 00443 if (l->listPtr->refCount>1) { 00444 GWEN__LISTPTR *nlp; 00445 00446 /* only copy the list if someone else is using it */ 00447 nlp=GWEN__ListPtr_dup(l->listPtr); 00448 GWEN__ListPtr_free(l->listPtr); 00449 l->listPtr=nlp; 00450 } 00451 } 00452 00453 00454 00455 void GWEN_List_Erase(GWEN_LIST *l, GWEN_LIST_ITERATOR *it){ 00456 GWEN_LIST_ENTRY *current; 00457 GWEN__LISTPTR *lp; 00458 00459 assert(l); 00460 assert(l->listPtr); 00461 if (l->listPtr->refCount>1) { 00462 GWEN_LIST_ENTRY *tle; 00463 GWEN__LISTPTR *nlp; 00464 int i; 00465 00466 /* find the position of the iterator within current list */ 00467 tle=it->current; 00468 assert(tle); 00469 i=0; 00470 while(tle->previous) { 00471 i++; 00472 tle=tle->previous; 00473 } 00474 00475 /* copy the list */ 00476 nlp=GWEN__ListPtr_dup(l->listPtr); 00477 GWEN__ListPtr_free(l->listPtr); 00478 l->listPtr=nlp; 00479 00480 /* seek and set the iterator position */ 00481 tle=l->listPtr->first; 00482 assert(tle); 00483 while(tle && i--) { 00484 tle=tle->next; 00485 } 00486 assert(tle); 00487 it->current=tle; 00488 } 00489 lp=l->listPtr; 00490 00491 assert(it); 00492 if (it->current) { 00493 current=it->current; 00494 if (it->current->linkCount==1) { 00495 /* unlink from list */ 00496 if (lp->first==current) 00497 lp->first=current->next; 00498 if (lp->last==current) 00499 lp->last=current->previous; 00500 00501 /* unlink from next */ 00502 if (current->next) { 00503 it->current=current->next; 00504 current->next->usage++; 00505 current->next->previous=current->previous; 00506 } 00507 else 00508 it->current=0; 00509 /* unlink from previous */ 00510 if (current->previous) 00511 current->previous->next=current->next; 00512 /* free */ 00513 current->usage--; 00514 GWEN_ListEntry_free(current); 00515 lp->size--; 00516 } 00517 else { 00518 /* move iterator forwards even if the current entry has not 00519 * been deleted. Thus making the return condition clear to the 00520 * caller. 00521 */ 00522 if (current->next) { 00523 it->current=current->next; 00524 current->next->usage++; 00525 } 00526 else 00527 it->current=0; 00528 current->usage--; 00529 it->current->linkCount--; 00530 } 00531 } 00532 } 00533 00534 00535 00536 GWEN_LIST_ITERATOR *GWEN_List_FindIter(GWEN_LIST *l, const void *p) { 00537 GWEN_LIST_ITERATOR *li; 00538 00539 li=GWEN_List_First(l); 00540 if (li) { 00541 void *d; 00542 00543 d=GWEN_ListIterator_Data(li); 00544 while(d) { 00545 if (d==p) { 00546 return li; 00547 } 00548 d=GWEN_ListIterator_Next(li); 00549 } 00550 GWEN_ListIterator_free(li); 00551 } 00552 return 0; 00553 } 00554 00555 00556 00557 const void *GWEN_List_Contains(GWEN_LIST *l, const void *p) { 00558 GWEN_LIST_ITERATOR *li; 00559 00560 li = GWEN_List_FindIter(l, p); 00561 if (li) { 00562 GWEN_ListIterator_free(li); 00563 return p; 00564 } 00565 return 0; 00566 } 00567 00568 00569 00570 void GWEN_List_Remove(GWEN_LIST *l, const void *p) { 00571 GWEN_LIST_ITERATOR *li; 00572 00573 li = GWEN_List_FindIter(l, p); 00574 if (li) { 00575 GWEN_List_Erase(l, li); 00576 GWEN_ListIterator_free(li); 00577 } 00578 } 00579 00580 00581 00582 GWEN_LIST_ITERATOR *GWEN_List_First(const GWEN_LIST *l){ 00583 GWEN_LIST_ITERATOR *li; 00584 00585 assert(l); 00586 assert(l->listPtr); 00587 if (l->listPtr->first==0) 00588 return 0; 00589 li=GWEN_ListIterator_new(l); 00590 li->current=l->listPtr->first; 00591 if (li->current) { 00592 li->current->usage++; 00593 } 00594 return li; 00595 } 00596 00597 00598 00599 GWEN_LIST_ITERATOR *GWEN_List_Last(const GWEN_LIST *l){ 00600 GWEN_LIST_ITERATOR *li; 00601 00602 assert(l); 00603 assert(l->listPtr); 00604 if (l->listPtr->last==0) 00605 return 0; 00606 li=GWEN_ListIterator_new(l); 00607 li->current=l->listPtr->last; 00608 if (li->current) 00609 li->current->usage++; 00610 return li; 00611 } 00612 00613 00614 00615 void GWEN_List_Dump(const GWEN_LIST *l, FILE *f, unsigned int indent){ 00616 GWEN_LIST_ENTRY *le; 00617 unsigned int i; 00618 00619 fprintf(f, "List contains %d entries\n", l->listPtr->size); 00620 le=l->listPtr->first; 00621 while(le) { 00622 for (i=0; i<indent; i++) fprintf(f, " "); 00623 fprintf(f, "List entry %p\n", (void*)le); 00624 for (i=0; i<indent; i++) fprintf(f, " "); 00625 fprintf(f, " Usage : %d\n", le->usage); 00626 for (i=0; i<indent; i++) fprintf(f, " "); 00627 fprintf(f, " Previous: %p\n", (void*)le->previous); 00628 for (i=0; i<indent; i++) fprintf(f, " "); 00629 fprintf(f, " Next : %p\n", (void*)le->next); 00630 for (i=0; i<indent; i++) fprintf(f, " "); 00631 fprintf(f, " Data : %p\n", (void*)GWEN_RefPtr_GetData(le->dataPtr)); 00632 le=le->next; 00633 } /* while */ 00634 } 00635 00636 00637 00638 00639 GWEN_LIST_ITERATOR *GWEN_ListIterator_new(const GWEN_LIST *l){ 00640 GWEN_LIST_ITERATOR *li; 00641 00642 GWEN_NEW_OBJECT(GWEN_LIST_ITERATOR, li); 00643 li->list=l; 00644 return li; 00645 } 00646 00647 00648 00649 void GWEN_ListIterator_free(GWEN_LIST_ITERATOR *li){ 00650 if (li) { 00651 if (li->current) 00652 GWEN_ListEntry_free(li->current); 00653 GWEN_FREE_OBJECT(li); 00654 } 00655 } 00656 00657 00658 00659 void *GWEN_ListIterator_Previous(GWEN_LIST_ITERATOR *li){ 00660 GWEN_REFPTR *rp; 00661 00662 assert(li); 00663 rp=GWEN_ListIterator_PreviousRefPtr(li); 00664 if (!rp) 00665 return 0; 00666 return GWEN_RefPtr_GetData(rp); 00667 } 00668 00669 00670 00671 GWEN_REFPTR *GWEN_ListIterator_PreviousRefPtr(GWEN_LIST_ITERATOR *li){ 00672 GWEN_LIST_ENTRY *le; 00673 00674 assert(li); 00675 00676 le=li->current; 00677 if (le) 00678 le=le->previous; 00679 if (li->current) 00680 GWEN_ListEntry_free(li->current); 00681 li->current=le; 00682 if (le) { 00683 le->usage++; 00684 return le->dataPtr; 00685 } 00686 return 0; 00687 } 00688 00689 00690 00691 void *GWEN_ListIterator_Next(GWEN_LIST_ITERATOR *li){ 00692 GWEN_REFPTR *rp; 00693 00694 assert(li); 00695 rp=GWEN_ListIterator_NextRefPtr(li); 00696 if (!rp) 00697 return 0; 00698 return GWEN_RefPtr_GetData(rp); 00699 } 00700 00701 00702 00703 GWEN_REFPTR *GWEN_ListIterator_NextRefPtr(GWEN_LIST_ITERATOR *li){ 00704 GWEN_LIST_ENTRY *le; 00705 00706 assert(li); 00707 00708 le=li->current; 00709 if (le) 00710 le=le->next; 00711 if (li->current) 00712 GWEN_ListEntry_free(li->current); 00713 li->current=le; 00714 if (le) { 00715 le->usage++; 00716 return le->dataPtr; 00717 } 00718 return 0; 00719 } 00720 00721 00722 00723 void *GWEN_ListIterator_Data(GWEN_LIST_ITERATOR *li){ 00724 assert(li); 00725 00726 if (li->current) 00727 return GWEN_RefPtr_GetData(li->current->dataPtr); 00728 return 0; 00729 } 00730 00731 00732 00733 GWEN_REFPTR *GWEN_ListIterator_DataRefPtr(GWEN_LIST_ITERATOR *li){ 00734 assert(li); 00735 00736 if (li->current) 00737 return li->current->dataPtr; 00738 return 0; 00739 } 00740 00741 00742 00743 void GWEN_ListIterator_IncLinkCount(GWEN_LIST_ITERATOR *li){ 00744 assert(li); 00745 00746 if (li->current) 00747 li->current->linkCount++; 00748 } 00749 00750 00751 00752 unsigned int GWEN_ListIterator_GetLinkCount(const GWEN_LIST_ITERATOR *li){ 00753 assert(li); 00754 00755 assert(li->current); 00756 return li->current->linkCount; 00757 } 00758 00759 00760 00761 00762 00763 00764 00765 00766 /* __________________________________________________________________________ 00767 * AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 00768 * ConstList 00769 * YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY 00770 */ 00771 00772 00773 00774 GWEN_CONSTLIST *GWEN_ConstList_new(void){ 00775 return GWEN_List_new(); 00776 } 00777 00778 00779 00780 void GWEN_ConstList_free(GWEN_CONSTLIST *l){ 00781 GWEN_List_free(l); 00782 } 00783 00784 00785 00786 void GWEN_ConstList_PushBack(GWEN_CONSTLIST *l, const void *p){ 00787 GWEN_List_PushBack(l, (void*)p); 00788 } 00789 00790 00791 00792 void GWEN_ConstList_PushFront(GWEN_CONSTLIST *l, const void *p){ 00793 GWEN_List_PushFront(l, (void*)p); 00794 } 00795 00796 00797 00798 const void *GWEN_ConstList_GetFront(const GWEN_CONSTLIST *l){ 00799 return GWEN_List_GetFront(l); 00800 } 00801 00802 00803 00804 const void *GWEN_ConstList_GetBack(const GWEN_CONSTLIST *l){ 00805 return GWEN_List_GetBack(l); 00806 } 00807 00808 00809 00810 unsigned int GWEN_ConstList_GetSize(const GWEN_CONSTLIST *l){ 00811 return GWEN_List_GetSize(l); 00812 } 00813 00814 int GWEN_ConstList_IsEmpty(const GWEN_LIST *l) { 00815 return GWEN_ConstList_GetSize(l) == 0; 00816 } 00817 00818 00819 00820 void GWEN_ConstList_PopBack(GWEN_CONSTLIST *l){ 00821 GWEN_List_PopBack(l); 00822 } 00823 00824 00825 00826 void GWEN_ConstList_PopFront(GWEN_CONSTLIST *l){ 00827 GWEN_List_PopFront(l); 00828 } 00829 00830 00831 00832 void GWEN_ConstList_Erase(GWEN_CONSTLIST *l, GWEN_CONSTLIST_ITERATOR *it){ 00833 GWEN_List_Erase(l, it); 00834 } 00835 00836 00837 00838 void GWEN_ConstList_Clear(GWEN_CONSTLIST *l){ 00839 GWEN_List_Clear(l); 00840 } 00841 00842 00843 const void *GWEN_ConstList_ForEach(GWEN_CONSTLIST *l, 00844 GWEN_CONSTLIST_FOREACH_CB fn, 00845 void *user_data){ 00846 GWEN_LIST_ITERATOR *it; 00847 const void *el; 00848 assert(l); 00849 00850 it = GWEN_List_First(l); 00851 if (!it) 00852 return 0; 00853 el = GWEN_ListIterator_Data(it); 00854 while(el) { 00855 el = fn(el, user_data); 00856 if (el) { 00857 GWEN_ListIterator_free(it); 00858 return el; 00859 } 00860 el = GWEN_ListIterator_Next(it); 00861 } 00862 GWEN_ListIterator_free(it); 00863 return 0; 00864 } 00865 00866 00867 00868 GWEN_CONSTLIST_ITERATOR *GWEN_ConstList_FindIter(const GWEN_CONSTLIST *l, const void *p) { 00869 GWEN_CONSTLIST_ITERATOR *li; 00870 00871 li=GWEN_ConstList_First(l); 00872 if (li) { 00873 const void *d; 00874 00875 d=GWEN_ConstListIterator_Data(li); 00876 while(d) { 00877 if (d==p) { 00878 return li; 00879 } 00880 d=GWEN_ConstListIterator_Next(li); 00881 } 00882 GWEN_ConstListIterator_free(li); 00883 } 00884 return 0; 00885 } 00886 00887 const void *GWEN_ConstList_Contains(const GWEN_CONSTLIST *l, const void *p) { 00888 GWEN_CONSTLIST_ITERATOR *li; 00889 00890 li = GWEN_ConstList_FindIter(l, p); 00891 if (li) { 00892 GWEN_ConstListIterator_free(li); 00893 return p; 00894 } 00895 return 0; 00896 } 00897 00898 void GWEN_ConstList_Remove(GWEN_CONSTLIST *l, const void *p) { 00899 GWEN_CONSTLIST_ITERATOR *li; 00900 00901 li = GWEN_ConstList_FindIter(l, p); 00902 if (li) { 00903 GWEN_ConstList_Erase(l, li); 00904 } 00905 } 00906 00907 GWEN_CONSTLIST_ITERATOR *GWEN_ConstList_First(const GWEN_CONSTLIST *l){ 00908 return GWEN_List_First(l); 00909 } 00910 00911 00912 00913 GWEN_CONSTLIST_ITERATOR *GWEN_ConstList_Last(const GWEN_CONSTLIST *l){ 00914 return GWEN_List_Last(l); 00915 } 00916 00917 00918 00919 GWEN_CONSTLIST_ITERATOR *GWEN_ConstListIterator_new(const GWEN_CONSTLIST *l){ 00920 return GWEN_ListIterator_new(l); 00921 } 00922 00923 00924 00925 void GWEN_ConstListIterator_free(GWEN_CONSTLIST_ITERATOR *li){ 00926 GWEN_ListIterator_free(li); 00927 } 00928 00929 00930 00931 const void *GWEN_ConstListIterator_Previous(GWEN_CONSTLIST_ITERATOR *li){ 00932 return GWEN_ListIterator_Previous(li); 00933 } 00934 00935 00936 00937 const void *GWEN_ConstListIterator_Next(GWEN_CONSTLIST_ITERATOR *li){ 00938 return GWEN_ListIterator_Next(li); 00939 } 00940 00941 00942 00943 const void *GWEN_ConstListIterator_Data(GWEN_CONSTLIST_ITERATOR *li){ 00944 return GWEN_ListIterator_Data(li); 00945 } 00946 00947 00948 00949 00950 00951