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