Package medite :: Package Donnees :: Module arbre
[hide private]
[frames] | no frames]

Source Code for Module medite.Donnees.arbre

  1  # -*- coding: iso-8859-1 -*- 
  2  # Copyright 20003 - 2008: Julien Bourdaillet (julien.bourdaillet@lip6.fr), Jean-Gabriel Ganascia (jean-gabriel.ganascia@lip6.fr) 
  3  # This file is part of MEDITE. 
  4  # 
  5  #    MEDITE is free software; you can redistribute it and/or modify 
  6  #    it under the terms of the GNU General Public License as published by 
  7  #    the Free Software Foundation; either version 2 of the License, or 
  8  #    (at your option) any later version. 
  9  # 
 10  #    MEDITE is distributed in the hope that it will be useful, 
 11  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  #    GNU General Public License for more details. 
 14  # 
 15  #    You should have received a copy of the GNU General Public License 
 16  #    along with Foobar; if not, write to the Free Software 
 17  #    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA 
 18  #---------------------------------------------------------------------------- 
 19  # Nom:          arbre.py 
 20  # Objet:        Classe qui regroupe les donnees d'un arbre 
 21  # 
 22  # Auteur:       Julien Bourdaillet 
 23  # 
 24  # Cree:         janvier 2005 
 25  #         
 26  #---------------------------------------------------------------------------- 
 27   
 28   
 29  # Arbre des versions 
30 -class Arbre:
31 # Constucteur de la classe
32 - def __init__(self, pListe=[]):
33 self.__listeVersions = pListe
34 #self.__nomDG = nomDG 35 36 # Methodes d'acces aux attributs prives
37 - def getListeVersions(self):
38 return self.__listeVersions
39 40 # renvoie une liste plate (ce n'est plus un arbre) de tous les Etats de l'arbre 41 # Chaque état est représenté par un couple (Etat,Version) où Version est la version 42 # mére de l'Etat
43 - def getListePlateEtats(self):
44 lEtats = [] 45 for version in self.getListeVersions(): 46 lEtats.extend(self.__getNode(version,version)) 47 return lEtats
48
49 - def __getNode(self,node, versionMere):
50 lEtats = [] 51 if isinstance(node,Etat): 52 lEtats.append((node,versionMere)) 53 for fils in node.getListeFils(): 54 lEtats.extend(self.__getNode(fils,versionMere)) 55 else: # Version 56 for fils in node.getListeFils(): 57 lEtats.extend(self.__getNode(fils,node)) 58 return lEtats
59
60 - def addVersion(self, version):
61 self.__listeVersions.append(version)
62
63 - def toString(self):
64 s = "Arbre [" 65 for v in self.__listeVersions: 66 s = s + v.toString() 67 s += "]" 68 return s
69 70 # Version
71 -class Version:
72 - def __init__(self, pNom, pListe=[]):
73 self.__nom = pNom 74 self.__listeVersionOREtats = pListe
75
76 - def getListeFils(self):
77 return self.__listeVersionOREtats
78
79 - def getNom(self):
80 return self.__nom
81
82 - def addFils(self, versionORetat):
83 self.__listeVersionOREtats.append(versionORetat)
84
85 - def toString(self):
86 s = "V "+self.getNom()+ " [" 87 for x in self.__listeVersionOREtats: 88 s = s + x.toString() + " / " 89 s += "]" 90 return s
91 92 # Etat d'un version
93 -class Etat:
94 - def __init__(self, pNom, pListe=[]):
95 self.__nom = pNom 96 self.__listeEtatsFils = pListe
97
98 - def getListeFils(self):
99 return self.__listeEtatsFils
100
101 - def getNom(self):
102 return self.__nom
103
104 - def addFils(self,etatFils):
105 self.__listeEtatsFils.append(etatFils)
106
107 - def toString(self):
108 s = "E "+self.getNom()+ " [" 109 for x in self.__listeEtatsFils: 110 s = s + x.toString() + " / " 111 s += "]" 112 return s
113