]> SALOME platform Git repositories - modules/kernel.git/blob - src/Batch/Batch_Parametre.cxx
Salome HOME
1facc62874dd50638a50eeaa08e606122f1bcad4
[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 "Batch_Versatile.hxx"
30 #include "Batch_InvalidKeyException.hxx"
31 #include "Batch_Parametre.hxx"
32
33 using namespace std;
34
35 // Definition des membres constants statiques
36 // Definition des noms globaux pour les clefs en tant que references
37 // TODO : supprimer les declarations statiques des clefs de la map
38 def_static_MapKey(ACCOUNT);
39 def_static_MapKey(ARGUMENTS);
40 def_static_MapKey(CHECKPOINT);
41 def_static_MapKey(CKPTINTERVAL);
42 def_static_MapKey(CREATIONTIME);
43 def_static_MapKey(EGROUP);
44 def_static_MapKey(ELIGIBLETIME);
45 def_static_MapKey(ENDTIME);
46 def_static_MapKey(EUSER);
47 def_static_MapKey(EXECUTABLE);
48 def_static_MapKey(EXECUTIONHOST);
49 def_static_MapKey(EXITCODE);
50 def_static_MapKey(HOLD);
51 def_static_MapKey(ID);
52 def_static_MapKey(INFILE);
53 def_static_MapKey(MAIL);
54 def_static_MapKey(MAXCPUTIME);
55 def_static_MapKey(MAXDISKSIZE);
56 def_static_MapKey(MAXRAMSIZE);
57 def_static_MapKey(MAXWALLTIME);
58 def_static_MapKey(MODIFICATIONTIME);
59 def_static_MapKey(NAME);
60 def_static_MapKey(NBPROC);
61 def_static_MapKey(OUTFILE);
62 def_static_MapKey(PID);
63 def_static_MapKey(QUEUE);
64 def_static_MapKey(QUEUEDTIME);
65 def_static_MapKey(SERVER);
66 def_static_MapKey(STARTTIME);
67 def_static_MapKey(STATE);
68 def_static_MapKey(TEXT);
69 def_static_MapKey(TMPDIR);
70 def_static_MapKey(USEDCPUTIME);
71 def_static_MapKey(USEDDISKSIZE);
72 def_static_MapKey(USEDRAMSIZE);
73 def_static_MapKey(USEDWALLTIME);
74 def_static_MapKey(USER);
75 def_static_MapKey(WORKDIR);
76 def_static_MapKey(HOMEDIR);
77
78 namespace Batch {
79
80   // Constructeur standard
81   // La map interne TypeMap possede les memes clefs que la map principale, mais les
82   // valeurs associees contiennent le type des clefs de la map principale ainsi que
83   // le nombre de valeurs autorisees dans l'objet Versatile (0=nombre quelconque,
84   // sinon valeur precisee)
85   Parametre::Parametre() : map< string, Versatile >()
86   {
87     TypeMap[ACCOUNT].type = STRING;
88     TypeMap[ACCOUNT].maxelem = 1;
89
90     TypeMap[ARGUMENTS].type = STRING;
91     TypeMap[ARGUMENTS].maxelem = 0;
92
93     TypeMap[CHECKPOINT].type = LONG;
94     TypeMap[CHECKPOINT].maxelem = 1;
95
96     TypeMap[CKPTINTERVAL].type = LONG;
97     TypeMap[CKPTINTERVAL].maxelem = 1;
98
99     TypeMap[CREATIONTIME].type = LONG;
100     TypeMap[CREATIONTIME].maxelem = 1;
101
102     TypeMap[EGROUP].type = STRING;
103     TypeMap[EGROUP].maxelem = 1;
104
105     TypeMap[ELIGIBLETIME].type = LONG;
106     TypeMap[ELIGIBLETIME].maxelem = 1;
107
108     TypeMap[ENDTIME].type = LONG;
109     TypeMap[ENDTIME].maxelem = 1;
110
111     TypeMap[EUSER].type = STRING;
112     TypeMap[EUSER].maxelem = 1;
113
114     TypeMap[EXECUTABLE].type = STRING;
115     TypeMap[EXECUTABLE].maxelem = 1;
116
117     TypeMap[EXECUTIONHOST].type = STRING;
118     TypeMap[EXECUTIONHOST].maxelem = 0;
119
120     TypeMap[EXITCODE].type = LONG;
121     TypeMap[EXITCODE].maxelem = 1;
122
123     TypeMap[HOLD].type = LONG;
124     TypeMap[HOLD].maxelem = 1;
125
126     TypeMap[ID].type = STRING;
127     TypeMap[ID].maxelem = 1;
128
129     TypeMap[INFILE].type = COUPLE;
130     TypeMap[INFILE].maxelem = 0;
131
132     TypeMap[MAIL].type = STRING;
133     TypeMap[MAIL].maxelem = 1;
134
135     TypeMap[MAXCPUTIME].type = LONG;
136     TypeMap[MAXCPUTIME].maxelem = 1;
137
138     TypeMap[MAXDISKSIZE].type = LONG;
139     TypeMap[MAXDISKSIZE].maxelem = 1;
140
141     TypeMap[MAXRAMSIZE].type = LONG;
142     TypeMap[MAXRAMSIZE].maxelem = 1;
143
144     TypeMap[MAXWALLTIME].type = LONG;
145     TypeMap[MAXWALLTIME].maxelem = 1;
146
147     TypeMap[MODIFICATIONTIME].type = LONG;
148     TypeMap[MODIFICATIONTIME].maxelem = 1;
149
150     TypeMap[NAME].type = STRING;
151     TypeMap[NAME].maxelem = 1;
152
153     TypeMap[NBPROC].type = LONG;
154     TypeMap[NBPROC].maxelem = 1;
155
156     TypeMap[OUTFILE].type = COUPLE;
157     TypeMap[OUTFILE].maxelem = 0;
158
159     TypeMap[PID].type = LONG;
160     TypeMap[PID].maxelem = 1;
161
162     TypeMap[QUEUE].type = STRING;
163     TypeMap[QUEUE].maxelem = 1;
164
165     TypeMap[QUEUEDTIME].type = LONG;
166     TypeMap[QUEUEDTIME].maxelem = 1;
167
168     TypeMap[SERVER].type = STRING;
169     TypeMap[SERVER].maxelem = 1;
170
171     TypeMap[STARTTIME].type = LONG;
172     TypeMap[STARTTIME].maxelem = 1;
173
174     TypeMap[STATE].type = STRING;
175     TypeMap[STATE].maxelem = 1;
176
177     TypeMap[TEXT].type = STRING;
178     TypeMap[TEXT].maxelem = 1;
179
180     TypeMap[TMPDIR].type = STRING;
181     TypeMap[TMPDIR].maxelem = 1;
182
183     TypeMap[USEDCPUTIME].type = LONG;
184     TypeMap[USEDCPUTIME].maxelem = 1;
185
186     TypeMap[USEDDISKSIZE].type = LONG;
187     TypeMap[USEDDISKSIZE].maxelem = 1;
188
189     TypeMap[USEDRAMSIZE].type = LONG;
190     TypeMap[USEDRAMSIZE].maxelem = 1;
191
192     TypeMap[USEDWALLTIME].type = LONG;
193     TypeMap[USEDWALLTIME].maxelem = 1;
194
195     TypeMap[USER].type = STRING;
196     TypeMap[USER].maxelem = 1;
197
198     TypeMap[WORKDIR].type = STRING;
199     TypeMap[WORKDIR].maxelem = 1;
200
201     TypeMap[HOMEDIR].type = STRING;
202     TypeMap[HOMEDIR].maxelem = 1;
203   }
204
205   // Operateur de recherche dans la map
206   // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de
207   // la valeur associée à la clef car il retourne une reference non constante
208   Versatile & Parametre::operator [] (const string & mk)
209   {
210     // On controle que la clef est valide
211     if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
212
213     // On recherche la valeur associee...
214     Versatile & V = map< string, Versatile >::operator [] (mk);
215
216     // ... et on l'initialise systematiquement
217     // ATTENTION : si un probleme de type survient (ie, on stocke une valeur d'un type
218     // different de celui inscrit dans TypeMap) une exception TypeMismatchException est
219     // levee
220     V.setName(mk);
221     V.setType(TypeMap[mk].type);
222     V.setMaxSize(TypeMap[mk].maxelem);
223
224     return V;
225   }
226
227   // Operateur de recherche dans la map
228   // Cet operateur agit sur les objets CONSTANTS
229   const Versatile & Parametre::operator [] (const string & mk) const
230   {
231     // On controle que la clef est valide
232     if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
233  
234     // On recherche la valeur associee
235     Parametre::const_iterator it = find(mk);
236     if (it == end()) throw InvalidKeyException(mk.c_str());
237     const Versatile & V = (*it).second;
238
239     return V;
240   }
241
242   // Operateur d'affectation
243   Parametre & Parametre::operator =(const Parametre & PM)
244   {
245     // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
246     if (this == &PM) return *this;
247
248     // On efface toute la map
249     erase(begin(), end());
250
251     // On recopie la map interne
252     // Meme si cela ne sert a rien pour le moment car les maps internes sont identiques,
253     // il n'est pas exclu que dans un avenir proche elles puissent etre differentes
254     (*this).TypeMap = PM.TypeMap;
255
256     // On recree la structure interne de la map avec les valeurs de celle passee en argument
257     Parametre::const_iterator it;
258     for(it=PM.begin(); it!=PM.end(); it++)
259       insert(make_pair( (*it).first ,
260                         Versatile( (*it).second)
261                         ) );
262
263     return *this;
264   }
265
266   // Constructeur par recopie
267   Parametre::Parametre(const Parametre & PM)
268   {
269     // inutile car l'objet est vierge : il vient d'etre cree
270     // On efface toute la map
271     // erase(begin(), end());
272
273     // On recopie la map interne
274     (*this).TypeMap = PM.TypeMap;
275
276     // On cree la structure interne de la map avec les valeurs de celle passee en argument
277     Parametre::const_iterator it;
278     for(it=PM.begin(); 
279         it!=PM.end(); 
280         it++)
281       insert(
282              make_pair( 
283                        (*it).first ,
284                        Versatile( (*it).second)
285                        ) );
286   }
287
288   //   map< string, TypeParam > Parametre::getTypeMap() const
289   //   {
290   //     return TypeMap;
291   //   }
292
293 }