Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsnDoubleList.cxx

Go to the documentation of this file.
00001 /*
00002  * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software
00003  * 
00004  * The Software has been developped within the Siames Project. 
00005  * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights
00006  * 
00007  * The Software has been registered with the Agence pour la Protection des
00008  * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200
00009  *  
00010  * This file may be distributed under the terms of the Q Public License
00011  * version 1.0 as defined by Trolltech AS of Norway and appearing in the file
00012  * LICENSE.QPL included in the packaging of this file.
00013  *
00014  * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 
00015  * for the software may use this file in accordance with that specific license
00016  *
00017  */
00018 #include <PsnDoubleList.h>
00019 
00020 #include "PsnReferenceObjectHandle.h"
00021 
00022 PsnDoubleList::PsnDoubleList() {
00023   _startOfSuperList=NULL;
00024   _lastOfSuperList=NULL;
00025   _start=NULL;
00026   _last=NULL;
00027 }
00028 
00029  
00030 bool PsnDoubleList::push_front(PsnReferenceObjectHandle * M) {
00031  PsnDoubleListElement * elem=new PsnDoubleListElement(M);
00032 
00033  //1 Gestion de la liste complète
00034  //chainage dans le sens suivant;
00035  elem->nextInSuperList=_startOfSuperList;
00036  //chainage dans le sens précédent
00037  elem->previousInSuperList=NULL;
00038  if (_startOfSuperList!=NULL) {//la liste n'est pas vide
00039      _startOfSuperList->previousInSuperList=elem;
00040  }
00041  else {
00042    _lastOfSuperList=elem;
00043  }
00044  _startOfSuperList=elem;
00045  return false ;
00046 }
00047 
00048 bool PsnDoubleList::push_back(PsnReferenceObjectHandle * M) {
00049  PsnDoubleListElement * elem=new PsnDoubleListElement(M);
00050 
00051  //1 Gestion de la liste complète
00052  //chainage dans le sens prec;
00053  elem->previousInSuperList=_lastOfSuperList;
00054  //chainage dans le sens suivant
00055  elem->nextInSuperList=NULL;
00056  if (_lastOfSuperList!=NULL) {//la liste n'est pas vide
00057      _lastOfSuperList->nextInSuperList=elem;
00058  }
00059  else {
00060    _startOfSuperList=elem;
00061  }
00062  _lastOfSuperList=elem;
00063  return false;
00064 }
00065 
00066 bool PsnDoubleList::insert(PsnReferenceObjectHandle * M) {
00067    PsnDoubleListElement * elem=new PsnDoubleListElement(M);
00068    PsnDoubleListElement * pcour=_startOfSuperList;
00069    PsnDoubleListElement * prec=NULL;
00070    enum{ON_BOUCLE,FIN_LISTE,PLACE_TROUVEE} etatBoucle;
00071    etatBoucle=ON_BOUCLE;
00072    
00073    while(etatBoucle==ON_BOUCLE) {
00074       if (pcour==NULL) {
00075          etatBoucle=FIN_LISTE;
00076       }
00077       else {
00078          if (*pcour->listeElem >= *M) 
00079             {
00080                etatBoucle=PLACE_TROUVEE;
00081             }
00082          else 
00083             {
00084                prec=pcour;
00085                pcour=pcour->nextInSuperList;
00086             }
00087       }
00088    }
00089    /* ici on sait que 
00090     * si prec != NULL , *prec->listeElem < *M 
00091     * soit pcour == NULL ou *M <= *pcour->listeElem
00092     * Il faut donc refaire le chainage
00093     */
00094    elem->nextInSuperList=pcour;
00095    elem->previousInSuperList=prec;
00096    if (prec==NULL) {//insertion de l'élément au début
00097       if (pcour!=NULL) {//la liste n'est pas vide
00098          pcour->previousInSuperList=elem;
00099       }
00100       else {
00101            _lastOfSuperList=elem;
00102       } 
00103       _startOfSuperList=elem;
00104    }
00105    else {
00106       prec->nextInSuperList=elem;
00107       if (pcour==NULL) {//on ajoute à la fin
00108          _lastOfSuperList=elem;
00109       } 
00110       else {
00111          pcour->previousInSuperList=elem;
00112       }
00113    }
00114    return false;
00115 }
00116 
00117 bool PsnDoubleList::remove(PsnReferenceObjectHandle * M) {
00118   PsnDoubleListElement * elem=findInSuperList(M);
00119   if(elem!=NULL) {//l'objet n'est pas déjà détruit
00120     if(elem->nextInActiveList!=NULL||elem->previousInActiveList!=NULL||_start==elem) {
00121       //l'objet est encore dans la liste des objets à exécuter : on ne le détruit pas
00122       return true;
00123      }
00124     else {
00125       PsnDoubleListElement * prec=elem->previousInSuperList;
00126       PsnDoubleListElement * suiv=elem->nextInSuperList;
00127       if(prec!=NULL) {
00128         prec->nextInSuperList=suiv;
00129       }
00130       else {//l'élément détruit était en tete
00131         _startOfSuperList=suiv;
00132       }
00133       if(suiv!=NULL) {
00134         suiv->previousInSuperList=prec;
00135       }
00136       else {//l'élement détruit était en queue
00137         _lastOfSuperList=prec;
00138       }
00139       delete elem;
00140     }
00141   }
00142   return false;
00143 }
00144 
00145 
00146 bool PsnDoubleList::activate(PsnReferenceObjectHandle * M, PsnDoubleListElement ** elemExecPrec) 
00147 {
00148   PsnDoubleListElement * pcour=_startOfSuperList;
00149   PsnDoubleListElement * resul=NULL;
00150   PsnDoubleListElement * execSuiv=_start;
00151   PsnDoubleListElement * execPrec=NULL;
00152   //on commence par chercher M dans la liste complète en gardant la trace du dernier élément qui appartient à la liste des exécutables.
00153   while((pcour!=NULL)&&(resul==NULL)) 
00154      {
00155         if(pcour->listeElem==M) 
00156            {
00157               resul=pcour;
00158            }
00159         else 
00160            {
00161               if( pcour->nextInActiveList != NULL ) 
00162                  {//l'élément courant est dans la liste des exec
00163                     execPrec = pcour ;
00164                     execSuiv = pcour->nextInActiveList;
00165                  }
00166               else 
00167                  {  // pcour is the last one of the active list
00168                     // or is not present in the active list
00169                     if ( pcour->previousInActiveList != NULL )
00170                        {
00171                           // pcour is in active list
00172                           execSuiv = NULL;
00173                           execPrec = pcour;  
00174                        }
00175                     else
00176                        {
00177                           // pcour is either the only element in the active list
00178                           // or is not in the active list
00179                           if ( pcour == _start )
00180                              { 
00181                                 //pcour is the only element in the active list
00182                                 execSuiv = NULL;
00183                                 execPrec = pcour;
00184                              }
00185                            else
00186                               {
00187                                  // nothing to do
00188                               }
00189                        }
00190                  }
00191               pcour = pcour->nextInSuperList;
00192            }
00193      }
00194   //rendu ici, pcour contient un pointeur sur l'élément ou NULL si l'élément n'est pas dans la liste
00195   //execPrec, le précédant de pcour dans la liste des exécutables
00196   //execSuiv, le suivant de pcour dans la liste des exécutables
00197   if (pcour==NULL) { 
00198     if(elemExecPrec!=NULL) *elemExecPrec=execPrec;
00199     return false;
00200   }
00201   else {
00202     if (execPrec==NULL) {//premier dans la liste des executables
00203       _start=pcour;
00204     }
00205     else {
00206       execPrec->nextInActiveList=pcour;
00207     }
00208     if(execSuiv==NULL) {//dernier dans la liste des executables
00209       _last=pcour;
00210     }
00211     else {
00212       execSuiv->previousInActiveList=pcour;
00213     }
00214     pcour->previousInActiveList=execPrec;
00215     pcour->nextInActiveList=execSuiv;
00216     if(elemExecPrec!=NULL) *elemExecPrec=execPrec;
00217     return true ;
00218   }
00219 }
00220 
00221 bool PsnDoubleList::suspend(PsnReferenceObjectHandle * M) {
00222   PsnDoubleListElement * elem=find(M);
00223   if(elem!=NULL) {//l'objet n'est pas déjà détruit ou est un entité
00224       PsnDoubleListElement * prec=elem->previousInActiveList;
00225       PsnDoubleListElement * suiv=elem->nextInActiveList;
00226       if(prec!=NULL) {
00227         prec->nextInActiveList=suiv;
00228       }
00229       else {//l'élément détruit était en tete
00230         _start=suiv;
00231       };
00232       if(suiv!=NULL) {
00233         suiv->previousInActiveList=prec;
00234       }
00235       else {
00236         _last=prec;
00237       };
00238       //l'élément n'appartient plus à la liste des modules à exécuter
00239       elem->previousInActiveList=NULL;
00240       elem->nextInActiveList=NULL;
00241       return false;
00242   }
00243   else {
00244     return true;
00245   }
00246 }
00247 
00248 PsnDoubleListElement * PsnDoubleList::findInSuperList(PsnReferenceObjectHandle * p) {
00249   PsnDoubleListElement * pcour=_startOfSuperList;
00250   PsnDoubleListElement * resul=NULL;
00251   while((pcour!=NULL)&&(resul==NULL)) {
00252     if(pcour->listeElem==p) {
00253       resul=pcour;
00254     }
00255     pcour=pcour->nextInSuperList;
00256   }
00257   return resul;
00258 }
00259 
00260 PsnDoubleListElement * PsnDoubleList::find(PsnReferenceObjectHandle * p) {
00261   PsnDoubleListElement * pcour=_start;
00262   PsnDoubleListElement * resul=NULL;
00263   while((pcour!=NULL)&&(resul==NULL)) {
00264     if(pcour->listeElem==p) {
00265       resul=pcour;
00266     }
00267     pcour=pcour->nextInActiveList;
00268   }
00269   return resul;
00270 }
00271 
00272 PsnDoubleListElement * PsnDoubleList::superListBegin() {
00273   return _startOfSuperList;
00274 }
00275 
00276 PsnDoubleListElement * PsnDoubleList::superListNext(PsnDoubleListElement * pcour) {
00277   if(pcour == NULL) {
00278     cerr<<"PsnDoubleList::superListNext WARNING:Suivant de NULL inexistant"<<endl;
00279     return NULL;
00280   }
00281   else {
00282     return pcour->nextInSuperList;
00283   }
00284 }
00285 
00286 PsnDoubleListElement * PsnDoubleList::begin() {
00287   return _start;
00288 }
00289 
00290 PsnDoubleListElement * PsnDoubleList::next(PsnDoubleListElement * pcour){
00291   if(pcour == NULL) {
00292     cerr<<"PsnDoubleList::next WARNING:Suivant de NULL inexistant"<<endl;
00293     return NULL;
00294   }
00295   else {
00296     return pcour->nextInActiveList;
00297   }
00298 }
00299 

logo OpenMask

Documentation generated on Mon Nov 25 15:25:00 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001