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 // TODO: These definitions in global namespace are here only to avoid breaking Kernel compilation for now.
38 // They must be removed as soon as possible.
39 def_static_MapKey(ACCOUNT)
40 def_static_MapKey(ARGUMENTS)
41 def_static_MapKey(CHECKPOINT)
42 def_static_MapKey(CKPTINTERVAL)
43 def_static_MapKey(CREATIONTIME)
44 def_static_MapKey(EGROUP)
45 def_static_MapKey(ELIGIBLETIME)
46 def_static_MapKey(ENDTIME)
47 def_static_MapKey(EUSER)
48 def_static_MapKey(EXECUTABLE)
49 def_static_MapKey(EXECUTIONHOST)
50 def_static_MapKey(EXITCODE)
51 def_static_MapKey(HOLD)
53 def_static_MapKey(INFILE)
54 def_static_MapKey(MAIL)
55 def_static_MapKey(MAXCPUTIME)
56 def_static_MapKey(MAXDISKSIZE)
57 def_static_MapKey(MAXRAMSIZE)
58 def_static_MapKey(MAXWALLTIME)
59 def_static_MapKey(MODIFICATIONTIME)
60 def_static_MapKey(NAME)
61 def_static_MapKey(NBPROC)
62 def_static_MapKey(OUTFILE)
63 def_static_MapKey(PID)
64 def_static_MapKey(QUEUE)
65 def_static_MapKey(QUEUEDTIME)
66 def_static_MapKey(SERVER)
67 def_static_MapKey(STARTTIME)
68 def_static_MapKey(STATE)
69 def_static_MapKey(TEXT)
70 def_static_MapKey(TMPDIR)
71 def_static_MapKey(USEDCPUTIME)
72 def_static_MapKey(USEDDISKSIZE)
73 def_static_MapKey(USEDRAMSIZE)
74 def_static_MapKey(USEDWALLTIME)
75 def_static_MapKey(USER)
76 def_static_MapKey(WORKDIR)
77 def_static_MapKey(HOMEDIR)
81 // Constructeur standard
82 // La map interne TypeMap possede les memes clefs que la map principale, mais les
83 // valeurs associees contiennent le type des clefs de la map principale ainsi que
84 // le nombre de valeurs autorisees dans l'objet Versatile (0=nombre quelconque,
85 // sinon valeur precisee)
86 Parametre::Parametre() : map< string, Versatile >()
88 TypeMap[ACCOUNT].type = STRING;
89 TypeMap[ACCOUNT].maxelem = 1;
91 TypeMap[ARGUMENTS].type = STRING;
92 TypeMap[ARGUMENTS].maxelem = 0;
94 TypeMap[CHECKPOINT].type = LONG;
95 TypeMap[CHECKPOINT].maxelem = 1;
97 TypeMap[CKPTINTERVAL].type = LONG;
98 TypeMap[CKPTINTERVAL].maxelem = 1;
100 TypeMap[CREATIONTIME].type = LONG;
101 TypeMap[CREATIONTIME].maxelem = 1;
103 TypeMap[EGROUP].type = STRING;
104 TypeMap[EGROUP].maxelem = 1;
106 TypeMap[ELIGIBLETIME].type = LONG;
107 TypeMap[ELIGIBLETIME].maxelem = 1;
109 TypeMap[ENDTIME].type = LONG;
110 TypeMap[ENDTIME].maxelem = 1;
112 TypeMap[EUSER].type = STRING;
113 TypeMap[EUSER].maxelem = 1;
115 TypeMap[EXECUTABLE].type = STRING;
116 TypeMap[EXECUTABLE].maxelem = 1;
118 TypeMap[EXECUTIONHOST].type = STRING;
119 TypeMap[EXECUTIONHOST].maxelem = 0;
121 TypeMap[EXITCODE].type = LONG;
122 TypeMap[EXITCODE].maxelem = 1;
124 TypeMap[HOLD].type = LONG;
125 TypeMap[HOLD].maxelem = 1;
127 TypeMap[ID].type = STRING;
128 TypeMap[ID].maxelem = 1;
130 TypeMap[INFILE].type = COUPLE;
131 TypeMap[INFILE].maxelem = 0;
133 TypeMap[MAIL].type = STRING;
134 TypeMap[MAIL].maxelem = 1;
136 TypeMap[MAXCPUTIME].type = LONG;
137 TypeMap[MAXCPUTIME].maxelem = 1;
139 TypeMap[MAXDISKSIZE].type = LONG;
140 TypeMap[MAXDISKSIZE].maxelem = 1;
142 TypeMap[MAXRAMSIZE].type = LONG;
143 TypeMap[MAXRAMSIZE].maxelem = 1;
145 TypeMap[MAXWALLTIME].type = LONG;
146 TypeMap[MAXWALLTIME].maxelem = 1;
148 TypeMap[MODIFICATIONTIME].type = LONG;
149 TypeMap[MODIFICATIONTIME].maxelem = 1;
151 TypeMap[NAME].type = STRING;
152 TypeMap[NAME].maxelem = 1;
154 TypeMap[NBPROC].type = LONG;
155 TypeMap[NBPROC].maxelem = 1;
157 TypeMap[OUTFILE].type = COUPLE;
158 TypeMap[OUTFILE].maxelem = 0;
160 TypeMap[PID].type = LONG;
161 TypeMap[PID].maxelem = 1;
163 TypeMap[QUEUE].type = STRING;
164 TypeMap[QUEUE].maxelem = 1;
166 TypeMap[QUEUEDTIME].type = LONG;
167 TypeMap[QUEUEDTIME].maxelem = 1;
169 TypeMap[SERVER].type = STRING;
170 TypeMap[SERVER].maxelem = 1;
172 TypeMap[STARTTIME].type = LONG;
173 TypeMap[STARTTIME].maxelem = 1;
175 TypeMap[STATE].type = STRING;
176 TypeMap[STATE].maxelem = 1;
178 TypeMap[TEXT].type = STRING;
179 TypeMap[TEXT].maxelem = 1;
181 TypeMap[TMPDIR].type = STRING;
182 TypeMap[TMPDIR].maxelem = 1;
184 TypeMap[USEDCPUTIME].type = LONG;
185 TypeMap[USEDCPUTIME].maxelem = 1;
187 TypeMap[USEDDISKSIZE].type = LONG;
188 TypeMap[USEDDISKSIZE].maxelem = 1;
190 TypeMap[USEDRAMSIZE].type = LONG;
191 TypeMap[USEDRAMSIZE].maxelem = 1;
193 TypeMap[USEDWALLTIME].type = LONG;
194 TypeMap[USEDWALLTIME].maxelem = 1;
196 TypeMap[USER].type = STRING;
197 TypeMap[USER].maxelem = 1;
199 TypeMap[WORKDIR].type = STRING;
200 TypeMap[WORKDIR].maxelem = 1;
202 TypeMap[HOMEDIR].type = STRING;
203 TypeMap[HOMEDIR].maxelem = 1;
206 // Operateur de recherche dans la map
207 // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de
208 // la valeur associ�e � la clef car il retourne une reference non constante
209 Versatile & Parametre::operator [] (const string & mk)
211 // On controle que la clef est valide
212 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
214 // On recherche la valeur associee...
215 Versatile & V = map< string, Versatile >::operator [] (mk);
217 // ... et on l'initialise systematiquement
218 // ATTENTION : si un probleme de type survient (ie, on stocke une valeur d'un type
219 // different de celui inscrit dans TypeMap) une exception TypeMismatchException est
222 V.setType(TypeMap[mk].type);
223 V.setMaxSize(TypeMap[mk].maxelem);
228 // Operateur de recherche dans la map
229 // Cet operateur agit sur les objets CONSTANTS
230 const Versatile & Parametre::operator [] (const string & mk) const
232 // On controle que la clef est valide
233 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
235 // On recherche la valeur associee
236 Parametre::const_iterator it = find(mk);
237 if (it == end()) throw InvalidKeyException(mk.c_str());
238 const Versatile & V = (*it).second;
243 // Operateur d'affectation
244 Parametre & Parametre::operator =(const Parametre & PM)
246 // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
247 if (this == &PM) return *this;
249 // On efface toute la map
250 erase(begin(), end());
252 // On recopie la map interne
253 // Meme si cela ne sert a rien pour le moment car les maps internes sont identiques,
254 // il n'est pas exclu que dans un avenir proche elles puissent etre differentes
255 (*this).TypeMap = PM.TypeMap;
257 // On recree la structure interne de la map avec les valeurs de celle passee en argument
258 Parametre::const_iterator it;
259 for(it=PM.begin(); it!=PM.end(); it++)
260 insert(make_pair( (*it).first ,
261 Versatile( (*it).second)
267 // Constructeur par recopie
268 Parametre::Parametre(const Parametre & PM) : map< string, Versatile >()
270 // inutile car l'objet est vierge : il vient d'etre cree
271 // On efface toute la map
272 // erase(begin(), end());
274 // On recopie la map interne
275 (*this).TypeMap = PM.TypeMap;
277 // On cree la structure interne de la map avec les valeurs de celle passee en argument
278 Parametre::const_iterator it;
285 Versatile( (*it).second)
289 // map< string, TypeParam > Parametre::getTypeMap() const