1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
25 * Auteur : Ivan DUTKA-MALEN - EDF R&D
26 * Date : Septembre 2003
31 #include "Batch_Versatile.hxx"
32 #include "Batch_InvalidKeyException.hxx"
33 #include "Batch_Parametre.hxx"
37 // Definition des membres constants statiques
38 // Definition des noms globaux pour les clefs en tant que references
39 // TODO : supprimer les declarations statiques des clefs de la map
40 def_static_MapKey(ACCOUNT);
41 def_static_MapKey(ARGUMENTS);
42 def_static_MapKey(CHECKPOINT);
43 def_static_MapKey(CKPTINTERVAL);
44 def_static_MapKey(CREATIONTIME);
45 def_static_MapKey(EGROUP);
46 def_static_MapKey(ELIGIBLETIME);
47 def_static_MapKey(ENDTIME);
48 def_static_MapKey(EUSER);
49 def_static_MapKey(EXECUTABLE);
50 def_static_MapKey(EXECUTIONHOST);
51 def_static_MapKey(EXITCODE);
52 def_static_MapKey(HOLD);
53 def_static_MapKey(ID);
54 def_static_MapKey(INFILE);
55 def_static_MapKey(MAIL);
56 def_static_MapKey(MAXCPUTIME);
57 def_static_MapKey(MAXDISKSIZE);
58 def_static_MapKey(MAXRAMSIZE);
59 def_static_MapKey(MAXWALLTIME);
60 def_static_MapKey(MODIFICATIONTIME);
61 def_static_MapKey(NAME);
62 def_static_MapKey(NBPROC);
63 def_static_MapKey(OUTFILE);
64 def_static_MapKey(PID);
65 def_static_MapKey(QUEUE);
66 def_static_MapKey(QUEUEDTIME);
67 def_static_MapKey(SERVER);
68 def_static_MapKey(STARTTIME);
69 def_static_MapKey(STATE);
70 def_static_MapKey(TEXT);
71 def_static_MapKey(TMPDIR);
72 def_static_MapKey(USEDCPUTIME);
73 def_static_MapKey(USEDDISKSIZE);
74 def_static_MapKey(USEDRAMSIZE);
75 def_static_MapKey(USEDWALLTIME);
76 def_static_MapKey(USER);
77 def_static_MapKey(WORKDIR);
78 def_static_MapKey(HOMEDIR);
82 // Constructeur standard
83 // La map interne TypeMap possede les memes clefs que la map principale, mais les
84 // valeurs associees contiennent le type des clefs de la map principale ainsi que
85 // le nombre de valeurs autorisees dans l'objet Versatile (0=nombre quelconque,
86 // sinon valeur precisee)
87 Parametre::Parametre() : map< string, Versatile >()
89 TypeMap[ACCOUNT].type = STRING;
90 TypeMap[ACCOUNT].maxelem = 1;
92 TypeMap[ARGUMENTS].type = STRING;
93 TypeMap[ARGUMENTS].maxelem = 0;
95 TypeMap[CHECKPOINT].type = LONG;
96 TypeMap[CHECKPOINT].maxelem = 1;
98 TypeMap[CKPTINTERVAL].type = LONG;
99 TypeMap[CKPTINTERVAL].maxelem = 1;
101 TypeMap[CREATIONTIME].type = LONG;
102 TypeMap[CREATIONTIME].maxelem = 1;
104 TypeMap[EGROUP].type = STRING;
105 TypeMap[EGROUP].maxelem = 1;
107 TypeMap[ELIGIBLETIME].type = LONG;
108 TypeMap[ELIGIBLETIME].maxelem = 1;
110 TypeMap[ENDTIME].type = LONG;
111 TypeMap[ENDTIME].maxelem = 1;
113 TypeMap[EUSER].type = STRING;
114 TypeMap[EUSER].maxelem = 1;
116 TypeMap[EXECUTABLE].type = STRING;
117 TypeMap[EXECUTABLE].maxelem = 1;
119 TypeMap[EXECUTIONHOST].type = STRING;
120 TypeMap[EXECUTIONHOST].maxelem = 0;
122 TypeMap[EXITCODE].type = LONG;
123 TypeMap[EXITCODE].maxelem = 1;
125 TypeMap[HOLD].type = LONG;
126 TypeMap[HOLD].maxelem = 1;
128 TypeMap[ID].type = STRING;
129 TypeMap[ID].maxelem = 1;
131 TypeMap[INFILE].type = COUPLE;
132 TypeMap[INFILE].maxelem = 0;
134 TypeMap[MAIL].type = STRING;
135 TypeMap[MAIL].maxelem = 1;
137 TypeMap[MAXCPUTIME].type = LONG;
138 TypeMap[MAXCPUTIME].maxelem = 1;
140 TypeMap[MAXDISKSIZE].type = LONG;
141 TypeMap[MAXDISKSIZE].maxelem = 1;
143 TypeMap[MAXRAMSIZE].type = LONG;
144 TypeMap[MAXRAMSIZE].maxelem = 1;
146 TypeMap[MAXWALLTIME].type = LONG;
147 TypeMap[MAXWALLTIME].maxelem = 1;
149 TypeMap[MODIFICATIONTIME].type = LONG;
150 TypeMap[MODIFICATIONTIME].maxelem = 1;
152 TypeMap[NAME].type = STRING;
153 TypeMap[NAME].maxelem = 1;
155 TypeMap[NBPROC].type = LONG;
156 TypeMap[NBPROC].maxelem = 1;
158 TypeMap[OUTFILE].type = COUPLE;
159 TypeMap[OUTFILE].maxelem = 0;
161 TypeMap[PID].type = LONG;
162 TypeMap[PID].maxelem = 1;
164 TypeMap[QUEUE].type = STRING;
165 TypeMap[QUEUE].maxelem = 1;
167 TypeMap[QUEUEDTIME].type = LONG;
168 TypeMap[QUEUEDTIME].maxelem = 1;
170 TypeMap[SERVER].type = STRING;
171 TypeMap[SERVER].maxelem = 1;
173 TypeMap[STARTTIME].type = LONG;
174 TypeMap[STARTTIME].maxelem = 1;
176 TypeMap[STATE].type = STRING;
177 TypeMap[STATE].maxelem = 1;
179 TypeMap[TEXT].type = STRING;
180 TypeMap[TEXT].maxelem = 1;
182 TypeMap[TMPDIR].type = STRING;
183 TypeMap[TMPDIR].maxelem = 1;
185 TypeMap[USEDCPUTIME].type = LONG;
186 TypeMap[USEDCPUTIME].maxelem = 1;
188 TypeMap[USEDDISKSIZE].type = LONG;
189 TypeMap[USEDDISKSIZE].maxelem = 1;
191 TypeMap[USEDRAMSIZE].type = LONG;
192 TypeMap[USEDRAMSIZE].maxelem = 1;
194 TypeMap[USEDWALLTIME].type = LONG;
195 TypeMap[USEDWALLTIME].maxelem = 1;
197 TypeMap[USER].type = STRING;
198 TypeMap[USER].maxelem = 1;
200 TypeMap[WORKDIR].type = STRING;
201 TypeMap[WORKDIR].maxelem = 1;
203 TypeMap[HOMEDIR].type = STRING;
204 TypeMap[HOMEDIR].maxelem = 1;
207 // Operateur de recherche dans la map
208 // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de
209 // la valeur associée à la clef car il retourne une reference non constante
210 Versatile & Parametre::operator [] (const string & mk)
212 // On controle que la clef est valide
213 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
215 // On recherche la valeur associee...
216 Versatile & V = map< string, Versatile >::operator [] (mk);
218 // ... et on l'initialise systematiquement
219 // ATTENTION : si un probleme de type survient (ie, on stocke une valeur d'un type
220 // different de celui inscrit dans TypeMap) une exception TypeMismatchException est
223 V.setType(TypeMap[mk].type);
224 V.setMaxSize(TypeMap[mk].maxelem);
229 // Operateur de recherche dans la map
230 // Cet operateur agit sur les objets CONSTANTS
231 const Versatile & Parametre::operator [] (const string & mk) const
233 // On controle que la clef est valide
234 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
236 // On recherche la valeur associee
237 Parametre::const_iterator it = find(mk);
238 if (it == end()) throw InvalidKeyException(mk.c_str());
239 const Versatile & V = (*it).second;
244 // Operateur d'affectation
245 Parametre & Parametre::operator =(const Parametre & PM)
247 // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
248 if (this == &PM) return *this;
250 // On efface toute la map
251 erase(begin(), end());
253 // On recopie la map interne
254 // Meme si cela ne sert a rien pour le moment car les maps internes sont identiques,
255 // il n'est pas exclu que dans un avenir proche elles puissent etre differentes
256 (*this).TypeMap = PM.TypeMap;
258 // On recree la structure interne de la map avec les valeurs de celle passee en argument
259 Parametre::const_iterator it;
260 for(it=PM.begin(); it!=PM.end(); it++)
261 insert(make_pair( (*it).first ,
262 Versatile( (*it).second)
268 // Constructeur par recopie
269 Parametre::Parametre(const Parametre & PM)
271 // inutile car l'objet est vierge : il vient d'etre cree
272 // On efface toute la map
273 // erase(begin(), end());
275 // On recopie la map interne
276 (*this).TypeMap = PM.TypeMap;
278 // On cree la structure interne de la map avec les valeurs de celle passee en argument
279 Parametre::const_iterator it;
286 Versatile( (*it).second)
290 // map< string, TypeParam > Parametre::getTypeMap() const