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);
75 def_static_MapKey(HOMEDIR);
79 // Constructeur standard
80 // La map interne TypeMap possede les memes clefs que la map principale, mais les
81 // valeurs associees contiennent le type des clefs de la map principale ainsi que
82 // le nombre de valeurs autorisees dans l'objet Versatile (0=nombre quelconque,
83 // sinon valeur precisee)
84 Parametre::Parametre() : map< string, Versatile >()
86 TypeMap[ACCOUNT].type = STRING;
87 TypeMap[ACCOUNT].maxelem = 1;
89 TypeMap[ARGUMENTS].type = STRING;
90 TypeMap[ARGUMENTS].maxelem = 0;
92 TypeMap[CHECKPOINT].type = LONG;
93 TypeMap[CHECKPOINT].maxelem = 1;
95 TypeMap[CKPTINTERVAL].type = LONG;
96 TypeMap[CKPTINTERVAL].maxelem = 1;
98 TypeMap[CREATIONTIME].type = LONG;
99 TypeMap[CREATIONTIME].maxelem = 1;
101 TypeMap[EGROUP].type = STRING;
102 TypeMap[EGROUP].maxelem = 1;
104 TypeMap[ELIGIBLETIME].type = LONG;
105 TypeMap[ELIGIBLETIME].maxelem = 1;
107 TypeMap[ENDTIME].type = LONG;
108 TypeMap[ENDTIME].maxelem = 1;
110 TypeMap[EUSER].type = STRING;
111 TypeMap[EUSER].maxelem = 1;
113 TypeMap[EXECUTABLE].type = STRING;
114 TypeMap[EXECUTABLE].maxelem = 1;
116 TypeMap[EXECUTIONHOST].type = STRING;
117 TypeMap[EXECUTIONHOST].maxelem = 0;
119 TypeMap[EXITCODE].type = LONG;
120 TypeMap[EXITCODE].maxelem = 1;
122 TypeMap[HOLD].type = LONG;
123 TypeMap[HOLD].maxelem = 1;
125 TypeMap[ID].type = STRING;
126 TypeMap[ID].maxelem = 1;
128 TypeMap[INFILE].type = COUPLE;
129 TypeMap[INFILE].maxelem = 0;
131 TypeMap[MAIL].type = STRING;
132 TypeMap[MAIL].maxelem = 1;
134 TypeMap[MAXCPUTIME].type = LONG;
135 TypeMap[MAXCPUTIME].maxelem = 1;
137 TypeMap[MAXDISKSIZE].type = LONG;
138 TypeMap[MAXDISKSIZE].maxelem = 1;
140 TypeMap[MAXRAMSIZE].type = LONG;
141 TypeMap[MAXRAMSIZE].maxelem = 1;
143 TypeMap[MAXWALLTIME].type = LONG;
144 TypeMap[MAXWALLTIME].maxelem = 1;
146 TypeMap[MODIFICATIONTIME].type = LONG;
147 TypeMap[MODIFICATIONTIME].maxelem = 1;
149 TypeMap[NAME].type = STRING;
150 TypeMap[NAME].maxelem = 1;
152 TypeMap[NBPROC].type = LONG;
153 TypeMap[NBPROC].maxelem = 1;
155 TypeMap[OUTFILE].type = COUPLE;
156 TypeMap[OUTFILE].maxelem = 0;
158 TypeMap[PID].type = LONG;
159 TypeMap[PID].maxelem = 1;
161 TypeMap[QUEUE].type = STRING;
162 TypeMap[QUEUE].maxelem = 1;
164 TypeMap[QUEUEDTIME].type = LONG;
165 TypeMap[QUEUEDTIME].maxelem = 1;
167 TypeMap[SERVER].type = STRING;
168 TypeMap[SERVER].maxelem = 1;
170 TypeMap[STARTTIME].type = LONG;
171 TypeMap[STARTTIME].maxelem = 1;
173 TypeMap[STATE].type = STRING;
174 TypeMap[STATE].maxelem = 1;
176 TypeMap[TEXT].type = STRING;
177 TypeMap[TEXT].maxelem = 1;
179 TypeMap[TMPDIR].type = STRING;
180 TypeMap[TMPDIR].maxelem = 1;
182 TypeMap[USEDCPUTIME].type = LONG;
183 TypeMap[USEDCPUTIME].maxelem = 1;
185 TypeMap[USEDDISKSIZE].type = LONG;
186 TypeMap[USEDDISKSIZE].maxelem = 1;
188 TypeMap[USEDRAMSIZE].type = LONG;
189 TypeMap[USEDRAMSIZE].maxelem = 1;
191 TypeMap[USEDWALLTIME].type = LONG;
192 TypeMap[USEDWALLTIME].maxelem = 1;
194 TypeMap[USER].type = STRING;
195 TypeMap[USER].maxelem = 1;
197 TypeMap[WORKDIR].type = STRING;
198 TypeMap[WORKDIR].maxelem = 1;
200 TypeMap[HOMEDIR].type = STRING;
201 TypeMap[HOMEDIR].maxelem = 1;
204 // Operateur de recherche dans la map
205 // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de
206 // la valeur associée à la clef car il retourne une reference non constante
207 Versatile & Parametre::operator [] (const string & mk)
209 // On controle que la clef est valide
210 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
212 // On recherche la valeur associee...
213 Versatile & V = map< string, Versatile >::operator [] (mk);
215 // ... et on l'initialise systematiquement
216 // ATTENTION : si un probleme de type survient (ie, on stocke une valeur d'un type
217 // different de celui inscrit dans TypeMap) une exception TypeMismatchException est
220 V.setType(TypeMap[mk].type);
221 V.setMaxSize(TypeMap[mk].maxelem);
226 // Operateur de recherche dans la map
227 // Cet operateur agit sur les objets CONSTANTS
228 const Versatile & Parametre::operator [] (const string & mk) const
230 // On controle que la clef est valide
231 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
233 // On recherche la valeur associee
234 Parametre::const_iterator it = find(mk);
235 if (it == end()) throw InvalidKeyException(mk.c_str());
236 const Versatile & V = (*it).second;
241 // Operateur d'affectation
242 Parametre & Parametre::operator =(const Parametre & PM)
244 // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
245 if (this == &PM) return *this;
247 // On efface toute la map
248 erase(begin(), end());
250 // On recopie la map interne
251 // Meme si cela ne sert a rien pour le moment car les maps internes sont identiques,
252 // il n'est pas exclu que dans un avenir proche elles puissent etre differentes
253 (*this).TypeMap = PM.TypeMap;
255 // On recree la structure interne de la map avec les valeurs de celle passee en argument
256 Parametre::const_iterator it;
257 for(it=PM.begin(); it!=PM.end(); it++)
258 insert(make_pair( (*it).first ,
259 Versatile( (*it).second)
265 // Constructeur par recopie
266 Parametre::Parametre(const Parametre & PM)
268 // inutile car l'objet est vierge : il vient d'etre cree
269 // On efface toute la map
270 // erase(begin(), end());
272 // On recopie la map interne
273 (*this).TypeMap = PM.TypeMap;
275 // On cree la structure interne de la map avec les valeurs de celle passee en argument
276 Parametre::const_iterator it;
283 Versatile( (*it).second)
287 // map< string, TypeParam > Parametre::getTypeMap() const