Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_MultiList.hpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 
00020 /**********************************************************************
00021  * File      : C_MultiList.h
00022  * Purpose   :
00023  * Version   :
00024  * Author(s) : Henry.Fauchery
00025  *
00026  * Creation  : 1998
00027  * Modif.    :
00028  *             - 1999
00029  *             - 2000 Xavier Bourvellec ( C++ convertion )
00030  *********************************************************************/
00031 
00032 #ifndef _C_MULTILIST_H_
00033 #define _C_MULTILIST_H_
00034 
00035 #include <cstdio>
00036 #include <cstdlib>
00037 
00038 /**********************************************************************
00039 Notes
00040 
00041 Following defines may help using this class:
00042 * defining DEBUG_MULTILIST allows tracing
00043   - if the list is correctly configured when used
00044   - print messages when entering / quitting methods
00045 
00046 * defining MLIST_ARGUMENTS_TESTING allows testing if Mlist methods were
00047 passed out-of-bounds argument, usefull when coredump stand around
00048 
00049 * defining MLIST_INTERNAL_COHERENCE test if list elements are placed in
00050   right list ( to detect internal errors when moving from one list to another )
00051 
00052 ************************************************************************/
00053 
00054 // Local debug flags
00055 // #define DEBUG_MULTILIST
00056 // #define MLIST_ARGUMENTS_TESTING
00057 // #define MLIST_INTERNAL_COHERENCE
00058 
00059 // !! DO NOT CHANGE THESE VALUES
00060 #define NULL_INDEX_ELEMENT        -1
00061 #define TST_OK                    1
00062 #define TST_ERROR                 NULL_INDEX_ELEMENT
00063 
00064 /************************************************************************************/
00065 /* C_MultiList class                                                                    */
00066 /* This class manage lists of elements, is able to move elements from one list to   */
00067 /* another.                                                                         */
00068 /* IT STORES POINTERS ON OBJECTS, NOT OBJECTS THEMSELVES                            */
00069 /*  i.e. using it like this :                                                       */
00070 /*  C_MultiList<long> testList                                                          */
00071 /*  will create a list management object of POINTERS to LONG, thus 'long *'         */
00072 /*                                                                                  */
00073 /* When instanciating a multilist object, you pass to its constructor the number of */
00074 /* lists, and the total number of elements. */
00075 /* You MUST then use 'initList' method to place all elements in the given list.     */
00076 /************************************************************************************/
00077 
00078 template <class Type>
00079 class C_MultiList
00080 {
00081 protected:
00082   /* single element structure */
00083   typedef struct s_element
00084   {
00085     long            currentList ;   /*                           */
00086     long            prevElement ;   /* index previous dial in same state   */
00087     Type *          payLoad;        /* payload */
00088     long            nextElement ;   /* index next dial in same state       */
00089   } struct_element ;
00090 
00091   /* list header structure */
00092   typedef struct s_listHeader
00093   {
00094     long     firstElement ; /* index of the first element in the list */
00095     long     lastElement ;  /* index of the last element  in the list */
00096     long     nbElements ;
00097   } struct_listHeader ;
00098 
00099   /* Object sizes */
00100   long firstListIndex;
00101   long lastListIndex;
00102 
00103   long nbLists;
00104   long nbElements;
00105 
00106   /* array of elements pointer */
00107   s_element *       elementList;
00108 
00109   /* array of list pointer */
00110   s_listHeader *    stateList;
00111 
00112   /* initDone flag */
00113   int initDone;
00114 
00115   /* private tool functions */
00116   inline int removeElement ( long );
00117   inline int initSingleElement ( long , long );
00118 
00119 public:
00120 
00121 
00122 // ----------------------------------------------
00123 // NAME: C_MultiList
00124 //
00125 // RETURN CODE :NONE
00126 // PARAMETERS:
00127 //          IN : first is the number of lists
00128 //               second is the number of elements to be stored
00129 //
00130 // ROLE: multi list constructor.
00131 //
00132 
00133   C_MultiList                           ( long , long );
00134   ~C_MultiList                          ( void );
00135 
00136 // ----------------------------------------------
00137 // NAME: initList
00138 //
00139 // RETURN CODE :return TST_ERROR if something went wrong ( like giving an out-of-bounds list index )
00140 // PARAMETERS:
00141 //          IN : the list index in which elements must be placed at start
00142 //
00143 // ROLE: initialize list : place all list elements in given list.
00144 //
00145   int initList          ( long );
00146 
00147 // ----------------------------------------------
00148 // NAME: moveToList
00149 //
00150 // RETURN CODE :return TST_ERROR if something went wrong ( like giving an out-of-bounds list index )
00151 // PARAMETERS:
00152 //          IN: first is list index, second is element index
00153 // ROLE: move a list element to given list
00154 //
00155 
00156   int moveToList        ( long , long );
00157 
00158 // ----------------------------------------------
00159 // NAME: getFirst
00160 //
00161 // RETURN CODE : element index
00162 // PARAMETERS:
00163 //          IN:   list index whose first elemetn must be returned
00164 // ROLE: give index of first list element from given list.
00165 //       THIS FUNCTION DO NOT REMOVE ELEMENT !!!
00166 //
00167 
00168   long  getFirst          ( long );
00169 
00170 // ----------------------------------------------
00171 // NAME: getNext
00172 //
00173 // RETURN CODE :element index following given one, or TST_ERROR if no next.
00174 // PARAMETERS:
00175 //          IN:   element index whose next ( element ) must be returned
00176 // ROLE:  return element index following given element
00177 //
00178 
00179   long  getNext           ( long );
00180 
00181 // ----------------------------------------------
00182 // NAME: isInState
00183 //
00184 // RETURN CODE : TST_OK if given element is containend in given list.
00185 // PARAMETERS:
00186 //          IN: first is list index, second is element index.
00187 // ROLE: verify that an element in containend in a particular list.
00188 //
00189 
00190   int   isInState         ( long , long ) ;
00191 
00192 // ----------------------------------------------
00193 // NAME: getCurrentList
00194 //
00195 // RETURN CODE : list index of given element
00196 // PARAMETERS:
00197 //          IN: element index.
00198 // ROLE: verify that an element in containend in a particular list.
00199 //
00200 
00201   long   getCurrentList         ( long ) ;
00202 
00203 // ----------------------------------------------// NAME: setElementPayload
00204 //
00205 // RETURN CODE : return object contained in element
00206 // PARAMETERS:
00207 //          IN:  relement index
00208 // ROLE  : return object contained in element given in parameter
00209 // NOTES : can be SLOW if objects stored in elements are not simple types
00210 
00211   Type *  getElementPayload ( long );
00212 
00213 // ----------------------------------------------
00214 // NAME: setElementPayload
00215 //
00216 // RETURN CODE :
00217 // PARAMETERS:
00218 //          IN: place object in list.
00219 // ROLE:
00220 //
00221   int     setElementPayload ( long , Type * );
00222 
00223 // ----------------------------------------------
00224 // NAME: getNbElements
00225 //
00226 // RETURN CODE :
00227 // PARAMETERS:
00228 //          IN: long list
00229 // ROLE: return number of elements in given list
00230 //
00231 
00232   long    getNbElements ( long );
00233 
00234 // ----------------------------------------------
00235 // NAME: dump
00236 //
00237 // RETURN CODE :
00238 // PARAMETERS:
00239 // ROLE: print list content
00240 //
00241   void  dump              ( void );
00242 }; /* class C_MultiList */
00243 
00244 #endif /* _C_MULTILIST_H_ */

Generated on Wed Mar 7 14:44:50 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002