1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 * Auteur : Ivan DUTKA-MALEN - EDF R&D
24 * Date : Septembre 2003
30 #include "Batch_Versatile.hxx"
31 #include "Batch_InvalidKeyException.hxx"
32 #include "Batch_Parametre.hxx"
34 // Definition des membres constants statiques
35 // Definition des noms globaux pour les clefs en tant que references
36 // TODO : supprimer les declarations statiques des clefs de la map
37 def_static_MapKey(ACCOUNT);
38 def_static_MapKey(ARGUMENTS);
39 def_static_MapKey(CHECKPOINT);
40 def_static_MapKey(CKPTINTERVAL);
41 def_static_MapKey(CREATIONTIME);
42 def_static_MapKey(EGROUP);
43 def_static_MapKey(ELIGIBLETIME);
44 def_static_MapKey(ENDTIME);
45 def_static_MapKey(EUSER);
46 def_static_MapKey(EXECUTABLE);
47 def_static_MapKey(EXECUTIONHOST);
48 def_static_MapKey(EXITCODE);
49 def_static_MapKey(HOLD);
50 def_static_MapKey(ID);
51 def_static_MapKey(INFILE);
52 def_static_MapKey(MAIL);
53 def_static_MapKey(MAXCPUTIME);
54 def_static_MapKey(MAXDISKSIZE);
55 def_static_MapKey(MAXRAMSIZE);
56 def_static_MapKey(MAXWALLTIME);
57 def_static_MapKey(MODIFICATIONTIME);
58 def_static_MapKey(NAME);
59 def_static_MapKey(NBPROC);
60 def_static_MapKey(OUTFILE);
61 def_static_MapKey(PID);
62 def_static_MapKey(QUEUE);
63 def_static_MapKey(QUEUEDTIME);
64 def_static_MapKey(SERVER);
65 def_static_MapKey(STARTTIME);
66 def_static_MapKey(STATE);
67 def_static_MapKey(TEXT);
68 def_static_MapKey(TMPDIR);
69 def_static_MapKey(USEDCPUTIME);
70 def_static_MapKey(USEDDISKSIZE);
71 def_static_MapKey(USEDRAMSIZE);
72 def_static_MapKey(USEDWALLTIME);
73 def_static_MapKey(USER);
74 def_static_MapKey(WORKDIR);
78 // Constructeur standard
79 // La map interne TypeMap possede les memes clefs que la map principale, mais les
80 // valeurs associees contiennent le type des clefs de la map principale ainsi que
81 // le nombre de valeurs autorisees dans l'objet Versatile (0=nombre quelconque,
82 // sinon valeur precisee)
83 Parametre::Parametre() : map< string, Versatile >()
85 TypeMap[ACCOUNT].type = STRING;
86 TypeMap[ACCOUNT].maxelem = 1;
88 TypeMap[ARGUMENTS].type = STRING;
89 TypeMap[ARGUMENTS].maxelem = 0;
91 TypeMap[CHECKPOINT].type = LONG;
92 TypeMap[CHECKPOINT].maxelem = 1;
94 TypeMap[CKPTINTERVAL].type = LONG;
95 TypeMap[CKPTINTERVAL].maxelem = 1;
97 TypeMap[CREATIONTIME].type = LONG;
98 TypeMap[CREATIONTIME].maxelem = 1;
100 TypeMap[EGROUP].type = STRING;
101 TypeMap[EGROUP].maxelem = 1;
103 TypeMap[ELIGIBLETIME].type = LONG;
104 TypeMap[ELIGIBLETIME].maxelem = 1;
106 TypeMap[ENDTIME].type = LONG;
107 TypeMap[ENDTIME].maxelem = 1;
109 TypeMap[EUSER].type = STRING;
110 TypeMap[EUSER].maxelem = 1;
112 TypeMap[EXECUTABLE].type = STRING;
113 TypeMap[EXECUTABLE].maxelem = 1;
115 TypeMap[EXECUTIONHOST].type = STRING;
116 TypeMap[EXECUTIONHOST].maxelem = 0;
118 TypeMap[EXITCODE].type = LONG;
119 TypeMap[EXITCODE].maxelem = 1;
121 TypeMap[HOLD].type = LONG;
122 TypeMap[HOLD].maxelem = 1;
124 TypeMap[ID].type = STRING;
125 TypeMap[ID].maxelem = 1;
127 TypeMap[INFILE].type = COUPLE;
128 TypeMap[INFILE].maxelem = 0;
130 TypeMap[MAIL].type = STRING;
131 TypeMap[MAIL].maxelem = 1;
133 TypeMap[MAXCPUTIME].type = LONG;
134 TypeMap[MAXCPUTIME].maxelem = 1;
136 TypeMap[MAXDISKSIZE].type = LONG;
137 TypeMap[MAXDISKSIZE].maxelem = 1;
139 TypeMap[MAXRAMSIZE].type = LONG;
140 TypeMap[MAXRAMSIZE].maxelem = 1;
142 TypeMap[MAXWALLTIME].type = LONG;
143 TypeMap[MAXWALLTIME].maxelem = 1;
145 TypeMap[MODIFICATIONTIME].type = LONG;
146 TypeMap[MODIFICATIONTIME].maxelem = 1;
148 TypeMap[NAME].type = STRING;
149 TypeMap[NAME].maxelem = 1;
151 TypeMap[NBPROC].type = LONG;
152 TypeMap[NBPROC].maxelem = 1;
154 TypeMap[OUTFILE].type = COUPLE;
155 TypeMap[OUTFILE].maxelem = 0;
157 TypeMap[PID].type = LONG;
158 TypeMap[PID].maxelem = 1;
160 TypeMap[QUEUE].type = STRING;
161 TypeMap[QUEUE].maxelem = 1;
163 TypeMap[QUEUEDTIME].type = LONG;
164 TypeMap[QUEUEDTIME].maxelem = 1;
166 TypeMap[SERVER].type = STRING;
167 TypeMap[SERVER].maxelem = 1;
169 TypeMap[STARTTIME].type = LONG;
170 TypeMap[STARTTIME].maxelem = 1;
172 TypeMap[STATE].type = STRING;
173 TypeMap[STATE].maxelem = 1;
175 TypeMap[TEXT].type = STRING;
176 TypeMap[TEXT].maxelem = 1;
178 TypeMap[TMPDIR].type = STRING;
179 TypeMap[TMPDIR].maxelem = 1;
181 TypeMap[USEDCPUTIME].type = LONG;
182 TypeMap[USEDCPUTIME].maxelem = 1;
184 TypeMap[USEDDISKSIZE].type = LONG;
185 TypeMap[USEDDISKSIZE].maxelem = 1;
187 TypeMap[USEDRAMSIZE].type = LONG;
188 TypeMap[USEDRAMSIZE].maxelem = 1;
190 TypeMap[USEDWALLTIME].type = LONG;
191 TypeMap[USEDWALLTIME].maxelem = 1;
193 TypeMap[USER].type = STRING;
194 TypeMap[USER].maxelem = 1;
196 TypeMap[WORKDIR].type = STRING;
197 TypeMap[WORKDIR].maxelem = 1;
200 // Operateur de recherche dans la map
201 // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de
202 // la valeur associée à la clef car il retourne une reference non constante
203 Versatile & Parametre::operator [] (const string & mk)
205 // On controle que la clef est valide
206 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
208 // On recherche la valeur associee...
209 Versatile & V = map< string, Versatile >::operator [] (mk);
211 // ... et on l'initialise systematiquement
212 // ATTENTION : si un probleme de type survient (ie, on stocke une valeur d'un type
213 // different de celui inscrit dans TypeMap) une exception TypeMismatchException est
216 V.setType(TypeMap[mk].type);
217 V.setMaxSize(TypeMap[mk].maxelem);
222 // Operateur de recherche dans la map
223 // Cet operateur agit sur les objets CONSTANTS
224 const Versatile & Parametre::operator [] (const string & mk) const
226 // On controle que la clef est valide
227 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
229 // On recherche la valeur associee
230 Parametre::const_iterator it = find(mk);
231 if (it == end()) throw InvalidKeyException(mk.c_str());
232 const Versatile & V = (*it).second;
237 // Operateur d'affectation
238 Parametre & Parametre::operator =(const Parametre & PM)
240 // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
241 if (this == &PM) return *this;
243 // On efface toute la map
244 erase(begin(), end());
246 // On recopie la map interne
247 // Meme si cela ne sert a rien pour le moment car les maps internes sont identiques,
248 // il n'est pas exclu que dans un avenir proche elles puissent etre differentes
249 (*this).TypeMap = PM.TypeMap;
251 // On recree la structure interne de la map avec les valeurs de celle passee en argument
252 Parametre::const_iterator it;
253 for(it=PM.begin(); it!=PM.end(); it++)
254 insert(make_pair( (*it).first ,
255 Versatile( (*it).second)
261 // Constructeur par recopie
262 Parametre::Parametre(const Parametre & PM)
264 // inutile car l'objet est vierge : il vient d'etre cree
265 // On efface toute la map
266 // erase(begin(), end());
268 // On recopie la map interne
269 (*this).TypeMap = PM.TypeMap;
271 // On cree la structure interne de la map avec les valeurs de celle passee en argument
272 Parametre::const_iterator it;
279 Versatile( (*it).second)
283 // map< string, TypeParam > Parametre::getTypeMap() const