00001 /**************************************************************** 00002 * Fulguro 00003 * Copyright (C) 2004 Christophe Clienti 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the 00017 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 * Boston, MA 02111-1307, USA. 00019 ***************************************************************/ 00020 00021 #include <stdio.h> 00022 #include <stdlib.h> 00023 #include <flgrCoreMalloc.h> 00024 #include <flgrCoreDispatch.h> 00025 #include "flgrDataToolsList.h" 00026 00037 00038 00042 00043 int flgr_list_is_empty(FLGR_List *list) { 00044 00045 00046 if((list->start == NULL) && (list->end == NULL)) { 00047 return 1; 00048 }else { 00049 return 0; 00050 } 00051 } 00052 00054 00058 00059 int flgr_list_size(FLGR_List *list) { 00060 00061 00062 return list->nbelt; 00063 } 00064 00066 00069 00070 FLGR_List *flgr_list_create() { 00071 FLGR_List *list=flgr_malloc(sizeof(FLGR_List)); 00072 00073 00074 list->start = list->end = NULL; 00075 list->nbelt = 0; 00076 return list; 00077 } 00078 00080 00085 00086 void flgr_list_add_head(FLGR_List *list,void *elt) { 00087 TLink *p; 00088 00089 00090 00091 p = (TLink *) flgr_malloc(sizeof(TLink)); 00092 p->elt = elt; 00093 p->previous = NULL; 00094 00095 if(list->nbelt == 0) { 00096 p->next = NULL; 00097 list->start = list->end = p; 00098 list->nbelt = 1; 00099 }else { 00100 list->start->previous = p; 00101 p->next = list->start; 00102 list->start = p; 00103 list->nbelt++; 00104 } 00105 } 00106 00108 00113 00114 void flgr_list_add_tail(FLGR_List *list,void *elt) { 00115 TLink *p; 00116 00117 00118 00119 p = (TLink *) flgr_malloc(sizeof(TLink)); 00120 p->elt = elt; 00121 p->next = NULL; 00122 00123 if(list->nbelt == 0) { 00124 list->start = list->end = p; 00125 p->previous = NULL; 00126 list->nbelt = 1; 00127 }else { 00128 p->previous = list->end; 00129 list->end->next = p; 00130 list->end = p; 00131 p->next = NULL; 00132 list->nbelt++; 00133 } 00134 } 00135 00137 00141 00142 void flgr_list_del_head(FLGR_List *list) { 00143 TLink *p; 00144 00145 00146 00147 if(list->nbelt != 0) { 00148 p = list->start; 00149 if(list->nbelt == 1) { 00150 list->start = list->end = NULL; 00151 list->nbelt = 0; 00152 }else { 00153 list->start = list->start->next; 00154 list->start->previous = NULL; 00155 list->nbelt--; 00156 } 00157 flgr_free(p); 00158 } 00159 } 00160 00162 00166 00167 void flgr_list_del_tail(FLGR_List *list) { 00168 TLink *p; 00169 00170 00171 00172 if(list->nbelt != 0) { 00173 p = list->end; 00174 if(list->nbelt == 1) { 00175 list->start = list->end = NULL; 00176 list->nbelt = 0; 00177 }else { 00178 list->end = list->end->previous; 00179 list->end->next = NULL; 00180 list->nbelt--; 00181 } 00182 flgr_free(p); 00183 } 00184 } 00185 00187 00191 00192 void flgr_list_destroy(FLGR_List *list) { 00193 00194 00195 while(list->nbelt != 0) { 00196 flgr_list_del_head(list); 00197 } 00198 flgr_free(list); 00199 } 00200 00202 00206 00207 void *flgr_list_get_head(FLGR_List *list) { 00208 00209 00210 return list->start->elt; 00211 } 00212 00214 00218 00219 void *flgr_list_get_tail(FLGR_List *list) { 00220 00221 00222 return list->end->elt; 00223 } 00224 00225 00227 00232 00233 void flgr_list_stack_push(FLGR_List *list,void *elt) { 00234 00235 00236 flgr_list_add_head(list,elt); 00237 } 00238 00239 00241 00245 00246 void *flgr_list_stack_pop(FLGR_List *list) { 00247 void *elt=flgr_list_get_head(list); 00248 00249 00250 flgr_list_del_head(list); 00251 return elt; 00252 } 00253 00254 00256 00261 00262 void flgr_list_queue_add(FLGR_List *list,void *elt) { 00263 00264 00265 flgr_list_add_head(list,elt); 00266 } 00267 00268 00270 00274 00275 void *flgr_list_queue_get(FLGR_List *list) { 00276 void *elt=flgr_list_get_tail(list); 00277 00278 00279 flgr_list_del_tail(list); 00280 return elt; 00281 } 00282 00283