00001 /* 00002 * lib-gmapkernel : Un noyau de 3-G-cartes et des opérations. 00003 * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC 00004 * http://www.sic.sp2mi.univ-poitiers.fr/ 00005 * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS, 00006 * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/ 00007 * 00008 * This file is part of lib-gmapkernel 00009 * 00010 * This program is free software: you can redistribute it and/or modify 00011 * it under the terms of the GNU Lesser General Public License as published by 00012 * the Free Software Foundation, either version 3 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public License 00021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00022 */ 00023 00024 //****************************************************************************** 00040 //****************************************************************************** 00041 #include "attribute.hh" 00042 00043 #include <cassert> 00044 //****************************************************************************** 00045 INLINE 00046 CEmbedding* CEmbedding::getPrev() const 00047 { 00048 return FPrev; 00049 } 00050 //****************************************************************************** 00051 INLINE 00052 void CEmbedding::setPrev(CEmbedding* AEmbedding) 00053 { 00054 FPrev = AEmbedding; 00055 } 00056 //****************************************************************************** 00057 INLINE 00058 CEmbedding* CEmbedding::getNext() const 00059 { 00060 return FNext; 00061 } 00062 //****************************************************************************** 00063 INLINE 00064 void CEmbedding::setNext(CEmbedding* AEmbedding) 00065 { 00066 FNext = AEmbedding; 00067 } 00068 //****************************************************************************** 00069 INLINE 00070 CAttribute* CEmbedding::getFirstAttribute() const 00071 { 00072 return FFirstAttribute; 00073 } 00074 //****************************************************************************** 00075 INLINE 00076 void CEmbedding::setFirstAttribute(CAttribute* AAttribute) 00077 { 00078 FFirstAttribute = AAttribute; 00079 } 00080 //****************************************************************************** 00081 INLINE 00082 CEmbedding::CEmbedding(TOrbit AOrbit) : 00083 FFirstAttribute(NULL), 00084 FId (AOrbit), 00085 FPrev (NULL), 00086 FNext (NULL) 00087 { 00088 } 00089 //****************************************************************************** 00090 INLINE 00091 CEmbedding::CEmbedding(const CEmbedding& AEmbedding) : 00092 FFirstAttribute(NULL), 00093 FId (AEmbedding.FId), 00094 FPrev (NULL), 00095 FNext (NULL) 00096 00097 { 00098 CAttribute* A = AEmbedding.getFirstAttribute(); 00099 00100 while ( A!=NULL ) 00101 { 00102 addAttribute(A->copy()); 00103 A = A->getNext(); 00104 } 00105 } 00106 //****************************************************************************** 00107 INLINE 00108 CEmbedding::~CEmbedding() 00109 { 00110 CAttribute* A = getFirstAttribute(); 00111 CAttribute* tmp = NULL; 00112 00113 while ( A!=NULL ) 00114 { 00115 tmp = A; 00116 A = A->getNext(); 00117 tmp->destroy(); 00118 } 00119 } 00120 //****************************************************************************** 00121 INLINE 00122 TOrbit CEmbedding::getOrbit() const 00123 { 00124 return FId; 00125 } 00126 //****************************************************************************** 00127 INLINE 00128 CAttribute* CEmbedding::getAttribute(TAttributeId AAttribType) const 00129 { 00130 CAttribute* A = getFirstAttribute(); 00131 00132 while ( A!=NULL ) 00133 { 00134 if ( A->getType()==AAttribType ) 00135 return A; // On alpha trouvé l'attribut 00136 00137 A = A->getNext(); 00138 } 00139 00140 return NULL; // Il n'existe pas d'attribut de ce type 00141 } 00142 //****************************************************************************** 00143 INLINE 00144 void CEmbedding::addAttribute(CAttribute* AAttribute) 00145 { 00146 assert( AAttribute!=NULL ); 00147 assert( AAttribute->getPrev()==NULL && AAttribute->getNext()==NULL ); 00148 assert( getAttribute(AAttribute->getType())==NULL ); 00149 00150 // Insertion en tête de la liste 00151 if ( getFirstAttribute()!=NULL ) 00152 // Si la liste des attributs n'est pas vide on modifie le chaînage : 00153 { 00154 getFirstAttribute()->setPrev(AAttribute); 00155 AAttribute->setNext(getFirstAttribute()); 00156 } 00157 00158 setFirstAttribute(AAttribute); // Le premier attribut est AAttribute 00159 } 00160 //****************************************************************************** 00167 INLINE 00168 CEmbedding* CEmbedding::copy() const 00169 { 00170 return new CEmbedding(*this); 00171 } 00172 //****************************************************************************** 00177 INLINE 00178 void CEmbedding::destroy() 00179 { 00180 delete this; 00181 } 00182 //****************************************************************************** 00189 INLINE 00190 CAttribute* CEmbedding::removeAttribute(CAttribute* AAttribute) 00191 { 00192 assert( AAttribute!=NULL ); 00193 assert( getAttribute(AAttribute->getType())==AAttribute ); 00194 00195 if ( getFirstAttribute()==AAttribute ) 00196 // Si l'attribut à enlever est le premier : 00197 { 00198 assert( AAttribute->getPrev()==NULL ); 00199 // On décale le premier attribut : 00200 setFirstAttribute(AAttribute->getNext()); 00201 } 00202 else 00203 { 00204 assert( AAttribute->getPrev()!=NULL ); 00205 // Sinon on modifie le chaînage next : 00206 AAttribute->getPrev()->setNext(AAttribute->getNext()); 00207 } 00208 00209 if ( AAttribute->getNext()!=NULL ) 00210 // Si l'attribut supprimé n'est pas le dernier de la liste, 00211 // on modifie le chaînage prev : 00212 AAttribute->getNext()->setPrev(AAttribute->getPrev()); 00213 00214 return AAttribute; 00215 } 00216 //****************************************************************************** 00222 INLINE 00223 CAttribute* CEmbedding::removeAttribute(TAttributeId AAttribType) 00224 { 00225 CAttribute* A = getAttribute(AAttribType); 00226 00227 if (A != NULL) 00228 return removeAttribute(A); 00229 00230 return NULL; 00231 } 00232 //****************************************************************************** 00238 INLINE 00239 void CEmbedding::deleteAttribute(CAttribute* AAttribute) 00240 { 00241 assert( AAttribute!=NULL ); 00242 00243 removeAttribute(AAttribute); // Suppression l'attribut de la liste. 00244 AAttribute->destroy(); // Appel de la méthode destroy() sur l'instance. 00245 } 00246 //****************************************************************************** 00252 INLINE 00253 void CEmbedding::deleteAttribute(TAttributeId AAttribType) 00254 { 00255 CAttribute* A = removeAttribute(AAttribType); 00256 00257 if (A != NULL) 00258 A->destroy(); 00259 } 00260 //****************************************************************************** 00267 INLINE 00268 void CEmbedding::mergeAttribute(CEmbedding* AEmbedding) 00269 { 00270 assert( FId==AEmbedding->FId ); // la précondition 00271 00272 CAttribute* A = AEmbedding->getFirstAttribute(); 00273 CAttribute* tmp = NULL; 00274 00275 while (A != NULL) // Parcours de chaque attribut de AEmbedding 00276 { 00277 tmp = A; 00278 A = A->getNext(); 00279 00280 if ( getAttribute(tmp->getType())==NULL ) 00281 // Si l'attribut courant du parcours n'est pas présent dans les 00282 // attributs de l'instance... 00283 { 00284 // On enlève cet attribut de AEmbedding : 00285 AEmbedding->removeAttribute(tmp); 00286 tmp->setPrev(NULL); 00287 tmp->setNext(NULL); 00288 // Et on l'ajoute dans les attributs de l'instance : 00289 addAttribute(tmp); 00290 } 00291 } 00292 } 00293 //****************************************************************************** 00294 // Accesseur pour tester si la liste des attributs de l'instance est vide 00295 INLINE 00296 bool CEmbedding::isEmpty() const 00297 { 00298 return getFirstAttribute() == NULL; 00299 } 00300 //******************************************************************************