Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

epList.h

Go to the documentation of this file.
00001 
00023 
00024 #ifndef _EPLIST_H_
00025 #define _EPLIST_H_
00026 
00027 #include "epDefs.h"
00028 #include "epUtils.h"
00029 
00031 #define epDir_t           int  
00032 #define _UNDETERMINED       0  
00033 #define _FIFO               1  
00034 #define _LIFO               2  
00035 
00036 #define _sUNDETERMINED     "<none>"
00037 #define _sFIFO             "<fifo>"
00038 #define _sLIFO             "<lifo>"
00039 
00040 
00041 #define searchDir_t       int
00042 #define _NORMAL             0
00043 #define _REVERSE            1
00044 
00045 // ne marche pas sur plusieurs lignes ?!?!?!
00046 #define _DIR_IS_VALID(dir) (((dir)==_UNDETERMINED) || ((dir)==_FIFO) || ((dir)==_LIFO)) 
00047 #define _DIR_TO_STRING(dir) ((dir)==_FIFO?_sFIFO:((dir)==_LIFO?_sLIFO:_sUNDETERMINED))
00048 
00050 struct epListElt_s {
00051   void *elt;                
00052   struct epListElt_s *prev, 
00053                      *next; 
00054 };
00055 
00057 typedef struct epList_s {
00058   epDir_t direction;        
00059   struct epListElt_s *head, 
00061                      *tail; 
00063   int numOfElements;        
00064   int (*elementDeallocatorFunction)(void *elt); 
00066   char *(*elementPrintFunction)(void *elt);     
00068 } epList_t;
00069 
00070 
00071 /* définition des messages d'erreur locaux */
00072 /*static _ERROR_MSG[] = {
00073   "aaa",
00074   "bbb"
00075 };
00076 */
00077 
00078 
00079 /*
00080    Create & initialize a new list.<br>
00081 
00082    <b>visibility :: <i>public</i></b>
00083 
00084    @remarks
00085             If no <i>element deallocator function</i> is passed in argument 
00086             (i.e. <b>NULL</b>), then the default <i>pointer deallocator 
00087             function</i> is applied.
00088 
00089    @param   direction                   the list direction
00090    @param   elementDeallocatorFunction  the function used to deallocate an 
00091                                         element
00092 
00093    @return  the created list (a pointer) or <b>NULL</b> if an error occurs.
00094  */
00095 epList_t *epList_create(const epDir_t direction, 
00096                         int (*elementDeallocatorFunction)(void *elt));
00097 
00098 /*
00099    Destroy the list and all the elements contained into.<br>
00100 
00101    <b>visibility :: <i>public</i></b>
00102 
00103    @remarks
00104             1. <b>REALLY DESTROY</b> the elements, using the
00105                <i>elementDeallocatorFunction</i> function.<br>
00106             2. The return value is always <b>0</b>.
00107 
00108    @param   list  the considered list
00109    @retval     0  if OK,
00110    @retval    -1  else. 
00111  */
00112 int epList_destroy(epList_t *list);
00113 
00114 /*
00115    Insert a next-element at the specified indice into the list.<br>
00116 
00117    <b>visibility :: <i>public</i></b>
00118 
00119    @remarks  
00120              1. if <i>_FIFO</i> or <i>_LIFO</i> direction is set, then 
00121                 <i>indice</i> is ignored (respectively insert at the 
00122                 end/beginning of the list).<br>
00123              2. if <i>indice</i> is superior to the number of list's elements,
00124                 then the new element is inserted at the list end. 
00125                 So the best way to insert a new element at the end is to
00126                 give the <i>infinite indice</i>.<br>
00127              3. <i>indice</i> varies from 0 to n-1, where n is the number of 
00128                 list's elements, and 0 the first inserted element.
00129 
00130    @param    list    the considered list
00131    @param    indice  the to-insert indice
00132    @param    elt     the to-insert element 
00133    @retval        0  if <b>OK</b>,
00134    @retval       -1  else.
00135  */
00136 int epList_put(epList_t *list, const int indice, const void *elt);
00137 
00138 /*
00139    Return the <i>indice</i>th element of the list and throw it out the list 
00140    <b>if</b> <i>removeFromList</i> is set (equal <true>).<br>
00141 
00142    <b>visibility :: <i>public</i></b>
00143 
00144    @remarks  
00145              1. if <i>_FIFO</i> or <i>_LIFO</i> direction is set, then 
00146                 <i>indice</i> is ignored and the first element is returned.<br>
00147              2. if <i>indice</i> is superior of n-1 (see <b>4.</b>) then an
00148                 error is generate & NULL is returned.<br>
00149              3. <i>removeFromList</i> <b>DON'T REMOVE</b> the element from
00150                 memory but only throw it out of the list.<br>
00151              4. <i>indice</i> varies from 0 to n-1, where n is the number of 
00152                 list's elements, and 0 the first inserted element.
00153 
00154    @param    list               the considered list
00155    @param    indice             the indice of the desired element
00156    @param    removeFromList     <true> or <false>
00157    @return   the wanted element, or <null> if an error occur.
00158  */
00159 void *epList_get(epList_t *list, const int indice, 
00160                  const boolean_t removeFromList);
00161 
00162 /*
00163    Return the <i>indice</i>th element of the list (in fact, it is only an 
00164    encapsulation of <i>epList_get(list, indice, <b>false</b>)</i>).<br>
00165 
00166    <b>visibility :: <i>public</i></b>
00167 
00168    @remarks  
00169              see the <i>epList_get</i> remarks.
00170 
00171    @param    list               the considered list
00172    @param    indice             the indice of the desired element
00173    @return   the wanted element, or <null> of an error occur.
00174  */
00175 void *epList_access(epList_t *list, const int indice);
00176 
00211 void *__epList_search(const epList_t *list, const searchDir_t direction, 
00212                       int from, int to, const void *criterion, 
00213                       boolean_t (*comparisonFunction)
00214                       (const void *element, const void *criterion),
00215                       int *indice);
00216 
00233 void *epList_search(const epList_t *list, const void *criterion, 
00234                     boolean_t (*comparisonFunction)
00235                     (const void *element, const void *criterion));
00236 
00253 void *epList_rsearch(const epList_t *list, const void *criterion, 
00254                      boolean_t (*comparisonFunction)
00255                      (const void *element, const void *criterion));
00256 
00257 /*
00258    Return the size of the list (the number of elements contained into).
00259 
00260    <b>visibility :: <i>public</i></b>
00261 
00262    @param   list      the considered list
00263    @return  its size,  or -1 if an error occur.
00264  */
00265 int epList_size(epList_t *list);
00266 
00267 /*
00268    Return <true> is the list is empty, <false> else.<br>
00269 
00270   <b>visibility :: <i>public</i></b>
00271 
00272   @remarks:
00273             With only a <true> or <false> value, we can't know if an error
00274             append(i.e. you give a NULL list in argument :-).<br>
00275             So if a such error append, -1 is return 
00276             (I know, its not proper!, I have to change it)<br>
00277 
00278   @param    list     the considered list
00279   @retval   <true>   if the list is empty,
00280   @retval   <false>  if not.
00281  */
00282 boolean_t epList_isEmpty(epList_t *list);
00283 
00284 /*
00285    Initialize the <i>elementPrintFunction</i> for the use of the
00286    <i>printIt</i> function.<br>
00287 
00288    <b>visibility :: <i>public</i></b>
00289 
00290    @remarks
00291              if you give a <b>NULL</b> eltPrintFunc, then only general list
00292              informations will be print on <i>printIt</i> function call.<br>
00293 
00294    @param    list                  the considered list
00295    @param    elementPrintFunction  the function to use
00296    @reval                      0  if <b>OK</b>,
00297    @retval                    -1  else.
00298  */
00299 int epList_setElementPrintFunction(
00300   epList_t *list,
00301   char *(*elementPrintFunction)(void *elt));
00302 
00317 int epList_printIt(epList_t *list, char *title);
00318 
00319 /*
00320    Print the elements of the list.
00321 
00322    <b>visibility :: <i>private</i></b>
00323 
00324    @warning
00325             1. some memory leaks may be encountered: if the 
00326                <i>elementPrintFunction</i> allocate a new string, 
00327                <i>printElements</i> don't free it.<br>
00328  
00329    @param   list   the considered list
00330    @return         <none>.
00331  */
00332 void epList_printElements(epList_t *list);
00333 
00334 #endif  /* _EPLIST_H_ */

Generated at Sun Nov 25 14:05:07 2001 for ExtendedPersonnalLibrary by doxygen1.2.1 written by Dimitri van Heesch, © 1997-2000