list.c

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

Generated on Wed Jul 9 13:12:28 2008 for gwenhywfar by  doxygen 1.5.6