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