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