Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

lstallo.c

Go to the documentation of this file.
00001 /************************************************************************* 00002 * $Id: lstallo.c,v 1.1 2005/09/09 08:22:51 bellet Exp $ 00003 ************************************************************************** 00004 This software is governed by the CeCILL license under French law and 00005 abiding by the rules of distribution of free software. You can use, 00006 modify and/ or redistribute the software under the terms of the CeCILL 00007 license as circulated by CEA, CNRS and INRIA at the following URL 00008 "http://www.cecill.info". 00009 00010 As a counterpart to the access to the source code and rights to copy, 00011 modify and redistribute granted by the license, users are provided only 00012 with a limited warranty and the software's author, the holder of the 00013 economic rights, and the successive licensors have only limited 00014 liability. 00015 00016 In this respect, the user's attention is drawn to the risks associated 00017 with loading, using, modifying and/or developing or reproducing the 00018 software by the user in light of its specific status of free software, 00019 that may mean that it is complicated to manipulate, and that also 00020 therefore means that it is reserved for developers and experienced 00021 professionals having in-depth computer knowledge. Users are therefore 00022 encouraged to load and test the software's suitability as regards their 00023 requirements in conditions enabling the security of their systems and/or 00024 data to be ensured and, more generally, to use and operate it in the 00025 same conditions as regards security. 00026 00027 The fact that you are presently reading this means that you have had 00028 knowledge of the CeCILL license and that you accept its terms. 00029 00030 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 00031 l'Image). All rights reserved. See License.txt for details. 00032 00033 Version 1.0 05/09/2005 00034 *************************************************************************/ 00035 00036 #include <stdlib.h> 00037 #include "idliste.h" 00038 #include "idprint.h" 00039 /************************************************************************* 00040 * 00041 * Description : Allocation and destruction of LIST related objects 00042 * 00043 **************************************************************************/ 00044 00053 void 00054 _IdFreeElement(PLIST_ELEMENT p, int d) 00055 { 00056 if (p) { 00057 _IdFreeElement(p->Next, d); 00058 if (d) 00059 _IdFreeElement(p->Pred, d); 00060 free(p); 00061 } 00062 } 00063 00069 void 00070 _IdLstFree(PLIST * lst) 00071 { 00072 PLIST_ELEMENT p; 00073 int m; 00074 00075 if (*lst) { 00076 if (_IdLstPrivate(*lst)->_message) 00077 free((_IdLstPrivate(*lst)->_message)); 00078 _IdLstPrivate(*lst)->_message = 0; 00079 if (_IdLstPrivate(*lst)->_fichier) 00080 free((_IdLstPrivate(*lst)->_fichier)); 00081 _IdLstPrivate(*lst)->_fichier = 0; 00082 00083 if (IdLstNbElems(*lst) != 0) { 00084 p = IdLstList(*lst); 00085 m = 1; 00086 if (p->Next) 00087 if (p->Next->Pred == p) 00088 m = 0; 00089 00090 _IdFreeElement(p, m); 00091 } 00092 free(_IdLstPrivate(*lst)); 00093 *lst = 0; 00094 } 00095 } 00096 00103 PLIST_ELEMENT _IdLstAllocElement(void) 00104 { 00105 void *p = calloc(sizeof(LIST_ELEMENT), 1); 00106 00107 if (!p) 00108 IdErrPrintf 00109 ("Echec d'allocation d'element de liste. Memoire saturee."); 00110 return (PLIST_ELEMENT) p; 00111 } 00112 00120 PLIST 00121 IdLstAlloc(void) 00122 { 00123 PRIVATE_LIST *si; 00124 00125 si = (PRIVATE_LIST *) calloc(sizeof(PRIVATE_LIST), 1); 00126 if (si) { 00127 si->Type = LST; 00128 si->_message = 0; 00129 si->_fichier = 0; 00130 } else { 00131 IdErrPrintf 00132 ("Echec d'allocation 'partie privee' de liste."); 00133 } 00134 00135 return ((PLIST) & (si[1])); 00136 } 00137 00146 PLIST_ELEMENT 00147 IdLstSearchElemObj(PLIST pl, void *obj) 00148 { 00149 PLIST_ELEMENT el; 00150 el = IdLstFirst(pl); 00151 while (el) { 00152 if (el->Object == obj) { 00153 return ((PLIST_ELEMENT) el); 00154 } 00155 el = el->Next; 00156 } 00157 return (0); 00158 } 00159 00182 PLIST_ELEMENT 00183 IdLstFindElem(PLIST pl, 00184 int (*UserCompareFonc) (PLIST_ELEMENT, void *), 00185 void *key) 00186 { 00187 PLIST_ELEMENT el; 00188 el = IdLstFirst(pl); 00189 while (el) { 00190 if (UserCompareFonc(el, key) == 0) 00191 return (el); 00192 el = el->Next; 00193 } 00194 return (0); 00195 } 00196 00206 void 00207 _IdLstDestroyNoControl(PLIST * lst, 00208 VOID_FUNCTION_VOIDP_POINTER foncDestr) 00209 { 00210 PLIST_ELEMENT e; 00211 if (!*lst) 00212 return; 00213 e = IdLstFirst(*lst); 00214 while (e != NULL) { 00215 foncDestr(IdLstPtrObj(e)); 00216 e = IdLstNext(e); 00217 } 00218 _IdLstFree(lst); 00219 } 00220 00230 void 00231 IdLstClear(PLIST lst) 00232 { 00233 PLIST_ELEMENT e, suiv; 00234 if (!lst) 00235 return; 00236 e = IdLstFirst(lst); 00237 while (e != NULL) { 00238 suiv = IdLstNext(e); 00239 IdLstRemoveElem(lst, e); 00240 e = suiv; 00241 } 00242 } 00243 00255 void 00256 IdLstDestroyElemNoControl(PLIST lst, 00257 PLIST_ELEMENT elem, 00258 VOID_FUNCTION_VOIDP_POINTER foncDestr) 00259 { 00260 if (!lst) 00261 return; 00262 if (!elem) 00263 return; 00264 foncDestr(IdLstPtrObj(elem)); 00265 IdLstRemoveElem(lst, elem); 00266 } 00267 00275 PLIST 00276 IdLstCopy(PLIST lst) 00277 { 00278 PLIST_ELEMENT ed; 00279 PRIVATE_LIST *si; 00280 PLIST lstResult; 00281 int retCode; 00282 00283 if (!lst) 00284 return ((PLIST) NULL); 00285 00286 si = (PRIVATE_LIST *) calloc(sizeof(PRIVATE_LIST), 1); 00287 if (si) { 00288 si->Type = LST; 00289 si->_message = 0; 00290 si->_fichier = 0; 00291 } else { 00292 IdErrPrintf 00293 ("Echec allocation 'partie privee' de liste.\n"); 00294 return ((PLIST) NULL); 00295 } 00296 00297 lstResult = (PLIST) & (si[1]); 00298 00299 ed = IdLstFirst(lst); 00300 00301 while (ed != NULL) { 00302 retCode = IdLstAddLast(lstResult, IdLstPtrObj(ed)); 00303 if (!retCode) { 00304 IdErrPrintf 00305 ("Echec allocation 'Element' de liste.\n"); 00306 return ((PLIST) NULL); 00307 } 00308 ed = IdLstNext(ed); 00309 } 00310 00311 return (lstResult); 00312 } 00313

Generated on Wed Oct 19 09:28:34 2005 for SIMRI3D by doxygen 1.3.7