Salome HOME
Removed CASCatch
[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
76 namespace Batch {
77
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 >()
84   {
85     TypeMap[ACCOUNT].type = STRING;
86     TypeMap[ACCOUNT].maxelem = 1;
87
88     TypeMap[ARGUMENTS].type = STRING;
89     TypeMap[ARGUMENTS].maxelem = 0;
90
91     TypeMap[CHECKPOINT].type = LONG;
92     TypeMap[CHECKPOINT].maxelem = 1;
93
94     TypeMap[CKPTINTERVAL].type = LONG;
95     TypeMap[CKPTINTERVAL].maxelem = 1;
96
97     TypeMap[CREATIONTIME].type = LONG;
98     TypeMap[CREATIONTIME].maxelem = 1;
99
100     TypeMap[EGROUP].type = STRING;
101     TypeMap[EGROUP].maxelem = 1;
102
103     TypeMap[ELIGIBLETIME].type = LONG;
104     TypeMap[ELIGIBLETIME].maxelem = 1;
105
106     TypeMap[ENDTIME].type = LONG;
107     TypeMap[ENDTIME].maxelem = 1;
108
109     TypeMap[EUSER].type = STRING;
110     TypeMap[EUSER].maxelem = 1;
111
112     TypeMap[EXECUTABLE].type = STRING;
113     TypeMap[EXECUTABLE].maxelem = 1;
114
115     TypeMap[EXECUTIONHOST].type = STRING;
116     TypeMap[EXECUTIONHOST].maxelem = 0;
117
118     TypeMap[EXITCODE].type = LONG;
119     TypeMap[EXITCODE].maxelem = 1;
120
121     TypeMap[HOLD].type = LONG;
122     TypeMap[HOLD].maxelem = 1;
123
124     TypeMap[ID].type = STRING;
125     TypeMap[ID].maxelem = 1;
126
127     TypeMap[INFILE].type = COUPLE;
128     TypeMap[INFILE].maxelem = 0;
129
130     TypeMap[MAIL].type = STRING;
131     TypeMap[MAIL].maxelem = 1;
132
133     TypeMap[MAXCPUTIME].type = LONG;
134     TypeMap[MAXCPUTIME].maxelem = 1;
135
136     TypeMap[MAXDISKSIZE].type = LONG;
137     TypeMap[MAXDISKSIZE].maxelem = 1;
138
139     TypeMap[MAXRAMSIZE].type = LONG;
140     TypeMap[MAXRAMSIZE].maxelem = 1;
141
142     TypeMap[MAXWALLTIME].type = LONG;
143     TypeMap[MAXWALLTIME].maxelem = 1;
144
145     TypeMap[MODIFICATIONTIME].type = LONG;
146     TypeMap[MODIFICATIONTIME].maxelem = 1;
147
148     TypeMap[NAME].type = STRING;
149     TypeMap[NAME].maxelem = 1;
150
151     TypeMap[NBPROC].type = LONG;
152     TypeMap[NBPROC].maxelem = 1;
153
154     TypeMap[OUTFILE].type = COUPLE;
155     TypeMap[OUTFILE].maxelem = 0;
156
157     TypeMap[PID].type = LONG;
158     TypeMap[PID].maxelem = 1;
159
160     TypeMap[QUEUE].type = STRING;
161     TypeMap[QUEUE].maxelem = 1;
162
163     TypeMap[QUEUEDTIME].type = LONG;
164     TypeMap[QUEUEDTIME].maxelem = 1;
165
166     TypeMap[SERVER].type = STRING;
167     TypeMap[SERVER].maxelem = 1;
168
169     TypeMap[STARTTIME].type = LONG;
170     TypeMap[STARTTIME].maxelem = 1;
171
172     TypeMap[STATE].type = STRING;
173     TypeMap[STATE].maxelem = 1;
174
175     TypeMap[TEXT].type = STRING;
176     TypeMap[TEXT].maxelem = 1;
177
178     TypeMap[TMPDIR].type = STRING;
179     TypeMap[TMPDIR].maxelem = 1;
180
181     TypeMap[USEDCPUTIME].type = LONG;
182     TypeMap[USEDCPUTIME].maxelem = 1;
183
184     TypeMap[USEDDISKSIZE].type = LONG;
185     TypeMap[USEDDISKSIZE].maxelem = 1;
186
187     TypeMap[USEDRAMSIZE].type = LONG;
188     TypeMap[USEDRAMSIZE].maxelem = 1;
189
190     TypeMap[USEDWALLTIME].type = LONG;
191     TypeMap[USEDWALLTIME].maxelem = 1;
192
193     TypeMap[USER].type = STRING;
194     TypeMap[USER].maxelem = 1;
195
196     TypeMap[WORKDIR].type = STRING;
197     TypeMap[WORKDIR].maxelem = 1;
198   }
199
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)
204   {
205     // On controle que la clef est valide
206     if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
207
208     // On recherche la valeur associee...
209     Versatile & V = map< string, Versatile >::operator [] (mk);
210
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
214     // levee
215     V.setName(mk);
216     V.setType(TypeMap[mk].type);
217     V.setMaxSize(TypeMap[mk].maxelem);
218
219     return V;
220   }
221
222   // Operateur de recherche dans la map
223   // Cet operateur agit sur les objets CONSTANTS
224   const Versatile & Parametre::operator [] (const string & mk) const
225   {
226     // On controle que la clef est valide
227     if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
228  
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;
233
234     return V;
235   }
236
237   // Operateur d'affectation
238   Parametre & Parametre::operator =(const Parametre & PM)
239   {
240     // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
241     if (this == &PM) return *this;
242
243     // On efface toute la map
244     erase(begin(), end());
245
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;
250
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)
256                         ) );
257
258     return *this;
259   }
260
261   // Constructeur par recopie
262   Parametre::Parametre(const Parametre & PM)
263   {
264     // inutile car l'objet est vierge : il vient d'etre cree
265     // On efface toute la map
266     // erase(begin(), end());
267
268     // On recopie la map interne
269     (*this).TypeMap = PM.TypeMap;
270
271     // On cree la structure interne de la map avec les valeurs de celle passee en argument
272     Parametre::const_iterator it;
273     for(it=PM.begin(); 
274         it!=PM.end(); 
275         it++)
276       insert(
277              make_pair( 
278                        (*it).first ,
279                        Versatile( (*it).second)
280                        ) );
281   }
282
283   //   map< string, TypeParam > Parametre::getTypeMap() const
284   //   {
285   //     return TypeMap;
286   //   }
287
288 }