Salome HOME
merge from branch BR_For40_DSC tag mergeto_V4_1_0_maintainance_29may08
[modules/kernel.git] / src / Batch / Batch_Parametre.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 /*
21  * Parametre.cxx : 
22  *
23  * Auteur : Ivan DUTKA-MALEN - EDF R&D
24  * Date   : Septembre 2003
25  * Projet : SALOME 2
26  *
27  */
28
29 #include <map>
30 #include "Batch_Versatile.hxx"
31 #include "Batch_InvalidKeyException.hxx"
32 #include "Batch_Parametre.hxx"
33
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);
76
77 namespace Batch {
78
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 >()
85   {
86     TypeMap[ACCOUNT].type = STRING;
87     TypeMap[ACCOUNT].maxelem = 1;
88
89     TypeMap[ARGUMENTS].type = STRING;
90     TypeMap[ARGUMENTS].maxelem = 0;
91
92     TypeMap[CHECKPOINT].type = LONG;
93     TypeMap[CHECKPOINT].maxelem = 1;
94
95     TypeMap[CKPTINTERVAL].type = LONG;
96     TypeMap[CKPTINTERVAL].maxelem = 1;
97
98     TypeMap[CREATIONTIME].type = LONG;
99     TypeMap[CREATIONTIME].maxelem = 1;
100
101     TypeMap[EGROUP].type = STRING;
102     TypeMap[EGROUP].maxelem = 1;
103
104     TypeMap[ELIGIBLETIME].type = LONG;
105     TypeMap[ELIGIBLETIME].maxelem = 1;
106
107     TypeMap[ENDTIME].type = LONG;
108     TypeMap[ENDTIME].maxelem = 1;
109
110     TypeMap[EUSER].type = STRING;
111     TypeMap[EUSER].maxelem = 1;
112
113     TypeMap[EXECUTABLE].type = STRING;
114     TypeMap[EXECUTABLE].maxelem = 1;
115
116     TypeMap[EXECUTIONHOST].type = STRING;
117     TypeMap[EXECUTIONHOST].maxelem = 0;
118
119     TypeMap[EXITCODE].type = LONG;
120     TypeMap[EXITCODE].maxelem = 1;
121
122     TypeMap[HOLD].type = LONG;
123     TypeMap[HOLD].maxelem = 1;
124
125     TypeMap[ID].type = STRING;
126     TypeMap[ID].maxelem = 1;
127
128     TypeMap[INFILE].type = COUPLE;
129     TypeMap[INFILE].maxelem = 0;
130
131     TypeMap[MAIL].type = STRING;
132     TypeMap[MAIL].maxelem = 1;
133
134     TypeMap[MAXCPUTIME].type = LONG;
135     TypeMap[MAXCPUTIME].maxelem = 1;
136
137     TypeMap[MAXDISKSIZE].type = LONG;
138     TypeMap[MAXDISKSIZE].maxelem = 1;
139
140     TypeMap[MAXRAMSIZE].type = LONG;
141     TypeMap[MAXRAMSIZE].maxelem = 1;
142
143     TypeMap[MAXWALLTIME].type = LONG;
144     TypeMap[MAXWALLTIME].maxelem = 1;
145
146     TypeMap[MODIFICATIONTIME].type = LONG;
147     TypeMap[MODIFICATIONTIME].maxelem = 1;
148
149     TypeMap[NAME].type = STRING;
150     TypeMap[NAME].maxelem = 1;
151
152     TypeMap[NBPROC].type = LONG;
153     TypeMap[NBPROC].maxelem = 1;
154
155     TypeMap[OUTFILE].type = COUPLE;
156     TypeMap[OUTFILE].maxelem = 0;
157
158     TypeMap[PID].type = LONG;
159     TypeMap[PID].maxelem = 1;
160
161     TypeMap[QUEUE].type = STRING;
162     TypeMap[QUEUE].maxelem = 1;
163
164     TypeMap[QUEUEDTIME].type = LONG;
165     TypeMap[QUEUEDTIME].maxelem = 1;
166
167     TypeMap[SERVER].type = STRING;
168     TypeMap[SERVER].maxelem = 1;
169
170     TypeMap[STARTTIME].type = LONG;
171     TypeMap[STARTTIME].maxelem = 1;
172
173     TypeMap[STATE].type = STRING;
174     TypeMap[STATE].maxelem = 1;
175
176     TypeMap[TEXT].type = STRING;
177     TypeMap[TEXT].maxelem = 1;
178
179     TypeMap[TMPDIR].type = STRING;
180     TypeMap[TMPDIR].maxelem = 1;
181
182     TypeMap[USEDCPUTIME].type = LONG;
183     TypeMap[USEDCPUTIME].maxelem = 1;
184
185     TypeMap[USEDDISKSIZE].type = LONG;
186     TypeMap[USEDDISKSIZE].maxelem = 1;
187
188     TypeMap[USEDRAMSIZE].type = LONG;
189     TypeMap[USEDRAMSIZE].maxelem = 1;
190
191     TypeMap[USEDWALLTIME].type = LONG;
192     TypeMap[USEDWALLTIME].maxelem = 1;
193
194     TypeMap[USER].type = STRING;
195     TypeMap[USER].maxelem = 1;
196
197     TypeMap[WORKDIR].type = STRING;
198     TypeMap[WORKDIR].maxelem = 1;
199
200     TypeMap[HOMEDIR].type = STRING;
201     TypeMap[HOMEDIR].maxelem = 1;
202   }
203
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)
208   {
209     // On controle que la clef est valide
210     if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
211
212     // On recherche la valeur associee...
213     Versatile & V = map< string, Versatile >::operator [] (mk);
214
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
218     // levee
219     V.setName(mk);
220     V.setType(TypeMap[mk].type);
221     V.setMaxSize(TypeMap[mk].maxelem);
222
223     return V;
224   }
225
226   // Operateur de recherche dans la map
227   // Cet operateur agit sur les objets CONSTANTS
228   const Versatile & Parametre::operator [] (const string & mk) const
229   {
230     // On controle que la clef est valide
231     if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
232  
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;
237
238     return V;
239   }
240
241   // Operateur d'affectation
242   Parametre & Parametre::operator =(const Parametre & PM)
243   {
244     // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
245     if (this == &PM) return *this;
246
247     // On efface toute la map
248     erase(begin(), end());
249
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;
254
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)
260                         ) );
261
262     return *this;
263   }
264
265   // Constructeur par recopie
266   Parametre::Parametre(const Parametre & PM)
267   {
268     // inutile car l'objet est vierge : il vient d'etre cree
269     // On efface toute la map
270     // erase(begin(), end());
271
272     // On recopie la map interne
273     (*this).TypeMap = PM.TypeMap;
274
275     // On cree la structure interne de la map avec les valeurs de celle passee en argument
276     Parametre::const_iterator it;
277     for(it=PM.begin(); 
278         it!=PM.end(); 
279         it++)
280       insert(
281              make_pair( 
282                        (*it).first ,
283                        Versatile( (*it).second)
284                        ) );
285   }
286
287   //   map< string, TypeParam > Parametre::getTypeMap() const
288   //   {
289   //     return TypeMap;
290   //   }
291
292 }