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