Salome HOME
Fixed errors in CMake FindXXX modules. Fixed Windows compilation errors.
[tools/libbatch.git] / src / Core / Batch_Parametre.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 /*
23  * Parametre.cxx :
24  *
25  * Auteur : Ivan DUTKA-MALEN - EDF R&D
26  * Date   : Septembre 2003
27  * Projet : SALOME 2
28  *
29  */
30
31 #include "Batch_Versatile.hxx"
32 #include "Batch_InvalidKeyException.hxx"
33 #include "Batch_Parametre.hxx"
34
35 using namespace std;
36
37 // Definition des membres constants statiques
38 // Definition des noms globaux pour les clefs en tant que references
39 // TODO : supprimer les declarations statiques des clefs de la map
40 def_static_MapKey(ACCOUNT)
41 def_static_MapKey(ARGUMENTS)
42 def_static_MapKey(CHECKPOINT)
43 def_static_MapKey(CKPTINTERVAL)
44 def_static_MapKey(CREATIONTIME)
45 def_static_MapKey(EGROUP)
46 def_static_MapKey(ELIGIBLETIME)
47 def_static_MapKey(ENDTIME)
48 def_static_MapKey(EUSER)
49 def_static_MapKey(EXECUTABLE)
50 def_static_MapKey(EXECUTIONHOST)
51 def_static_MapKey(EXITCODE)
52 def_static_MapKey(HOLD)
53 def_static_MapKey(ID)
54 def_static_MapKey(INFILE)
55 def_static_MapKey(MAIL)
56 def_static_MapKey(MAXCPUTIME)
57 def_static_MapKey(MAXDISKSIZE)
58 def_static_MapKey(MAXRAMSIZE)
59 def_static_MapKey(MAXWALLTIME)
60 def_static_MapKey(MODIFICATIONTIME)
61 def_static_MapKey(NAME)
62 def_static_MapKey(NBPROC)
63 def_static_MapKey(OUTFILE)
64 def_static_MapKey(PID)
65 def_static_MapKey(QUEUE)
66 def_static_MapKey(QUEUEDTIME)
67 def_static_MapKey(SERVER)
68 def_static_MapKey(STARTTIME)
69 def_static_MapKey(STATE)
70 def_static_MapKey(TEXT)
71 def_static_MapKey(TMPDIR)
72 def_static_MapKey(USEDCPUTIME)
73 def_static_MapKey(USEDDISKSIZE)
74 def_static_MapKey(USEDRAMSIZE)
75 def_static_MapKey(USEDWALLTIME)
76 def_static_MapKey(USER)
77 def_static_MapKey(WORKDIR)
78 def_static_MapKey(HOMEDIR)
79
80 namespace Batch {
81
82   // Constructeur standard
83   // La map interne TypeMap possede les memes clefs que la map principale, mais les
84   // valeurs associees contiennent le type des clefs de la map principale ainsi que
85   // le nombre de valeurs autorisees dans l'objet Versatile (0=nombre quelconque,
86   // sinon valeur precisee)
87   Parametre::Parametre() : map< string, Versatile >()
88   {
89     TypeMap[ACCOUNT].type = STRING;
90     TypeMap[ACCOUNT].maxelem = 1;
91
92     TypeMap[ARGUMENTS].type = STRING;
93     TypeMap[ARGUMENTS].maxelem = 0;
94
95     TypeMap[CHECKPOINT].type = LONG;
96     TypeMap[CHECKPOINT].maxelem = 1;
97
98     TypeMap[CKPTINTERVAL].type = LONG;
99     TypeMap[CKPTINTERVAL].maxelem = 1;
100
101     TypeMap[CREATIONTIME].type = LONG;
102     TypeMap[CREATIONTIME].maxelem = 1;
103
104     TypeMap[EGROUP].type = STRING;
105     TypeMap[EGROUP].maxelem = 1;
106
107     TypeMap[ELIGIBLETIME].type = LONG;
108     TypeMap[ELIGIBLETIME].maxelem = 1;
109
110     TypeMap[ENDTIME].type = LONG;
111     TypeMap[ENDTIME].maxelem = 1;
112
113     TypeMap[EUSER].type = STRING;
114     TypeMap[EUSER].maxelem = 1;
115
116     TypeMap[EXECUTABLE].type = STRING;
117     TypeMap[EXECUTABLE].maxelem = 1;
118
119     TypeMap[EXECUTIONHOST].type = STRING;
120     TypeMap[EXECUTIONHOST].maxelem = 0;
121
122     TypeMap[EXITCODE].type = LONG;
123     TypeMap[EXITCODE].maxelem = 1;
124
125     TypeMap[HOLD].type = LONG;
126     TypeMap[HOLD].maxelem = 1;
127
128     TypeMap[ID].type = STRING;
129     TypeMap[ID].maxelem = 1;
130
131     TypeMap[INFILE].type = COUPLE;
132     TypeMap[INFILE].maxelem = 0;
133
134     TypeMap[MAIL].type = STRING;
135     TypeMap[MAIL].maxelem = 1;
136
137     TypeMap[MAXCPUTIME].type = LONG;
138     TypeMap[MAXCPUTIME].maxelem = 1;
139
140     TypeMap[MAXDISKSIZE].type = LONG;
141     TypeMap[MAXDISKSIZE].maxelem = 1;
142
143     TypeMap[MAXRAMSIZE].type = LONG;
144     TypeMap[MAXRAMSIZE].maxelem = 1;
145
146     TypeMap[MAXWALLTIME].type = LONG;
147     TypeMap[MAXWALLTIME].maxelem = 1;
148
149     TypeMap[MODIFICATIONTIME].type = LONG;
150     TypeMap[MODIFICATIONTIME].maxelem = 1;
151
152     TypeMap[NAME].type = STRING;
153     TypeMap[NAME].maxelem = 1;
154
155     TypeMap[NBPROC].type = LONG;
156     TypeMap[NBPROC].maxelem = 1;
157
158     TypeMap[OUTFILE].type = COUPLE;
159     TypeMap[OUTFILE].maxelem = 0;
160
161     TypeMap[PID].type = LONG;
162     TypeMap[PID].maxelem = 1;
163
164     TypeMap[QUEUE].type = STRING;
165     TypeMap[QUEUE].maxelem = 1;
166
167     TypeMap[QUEUEDTIME].type = LONG;
168     TypeMap[QUEUEDTIME].maxelem = 1;
169
170     TypeMap[SERVER].type = STRING;
171     TypeMap[SERVER].maxelem = 1;
172
173     TypeMap[STARTTIME].type = LONG;
174     TypeMap[STARTTIME].maxelem = 1;
175
176     TypeMap[STATE].type = STRING;
177     TypeMap[STATE].maxelem = 1;
178
179     TypeMap[TEXT].type = STRING;
180     TypeMap[TEXT].maxelem = 1;
181
182     TypeMap[TMPDIR].type = STRING;
183     TypeMap[TMPDIR].maxelem = 1;
184
185     TypeMap[USEDCPUTIME].type = LONG;
186     TypeMap[USEDCPUTIME].maxelem = 1;
187
188     TypeMap[USEDDISKSIZE].type = LONG;
189     TypeMap[USEDDISKSIZE].maxelem = 1;
190
191     TypeMap[USEDRAMSIZE].type = LONG;
192     TypeMap[USEDRAMSIZE].maxelem = 1;
193
194     TypeMap[USEDWALLTIME].type = LONG;
195     TypeMap[USEDWALLTIME].maxelem = 1;
196
197     TypeMap[USER].type = STRING;
198     TypeMap[USER].maxelem = 1;
199
200     TypeMap[WORKDIR].type = STRING;
201     TypeMap[WORKDIR].maxelem = 1;
202
203     TypeMap[HOMEDIR].type = STRING;
204     TypeMap[HOMEDIR].maxelem = 1;
205   }
206
207   // Operateur de recherche dans la map
208   // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de
209   // la valeur associ�e � la clef car il retourne une reference non constante
210   Versatile & Parametre::operator [] (const string & mk)
211   {
212     // On controle que la clef est valide
213     if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
214
215     // On recherche la valeur associee...
216     Versatile & V = map< string, Versatile >::operator [] (mk);
217
218     // ... et on l'initialise systematiquement
219     // ATTENTION : si un probleme de type survient (ie, on stocke une valeur d'un type
220     // different de celui inscrit dans TypeMap) une exception TypeMismatchException est
221     // levee
222     V.setName(mk);
223     V.setType(TypeMap[mk].type);
224     V.setMaxSize(TypeMap[mk].maxelem);
225
226     return V;
227   }
228
229   // Operateur de recherche dans la map
230   // Cet operateur agit sur les objets CONSTANTS
231   const Versatile & Parametre::operator [] (const string & mk) const
232   {
233     // On controle que la clef est valide
234     if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
235
236     // On recherche la valeur associee
237     Parametre::const_iterator it = find(mk);
238     if (it == end()) throw InvalidKeyException(mk.c_str());
239     const Versatile & V = (*it).second;
240
241     return V;
242   }
243
244   // Operateur d'affectation
245   Parametre & Parametre::operator =(const Parametre & PM)
246   {
247     // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
248     if (this == &PM) return *this;
249
250     // On efface toute la map
251     erase(begin(), end());
252
253     // On recopie la map interne
254     // Meme si cela ne sert a rien pour le moment car les maps internes sont identiques,
255     // il n'est pas exclu que dans un avenir proche elles puissent etre differentes
256     (*this).TypeMap = PM.TypeMap;
257
258     // On recree la structure interne de la map avec les valeurs de celle passee en argument
259     Parametre::const_iterator it;
260     for(it=PM.begin(); it!=PM.end(); it++)
261       insert(make_pair( (*it).first ,
262                         Versatile( (*it).second)
263                         ) );
264
265     return *this;
266   }
267
268   // Constructeur par recopie
269   Parametre::Parametre(const Parametre & PM) : map< string, Versatile >()
270   {
271     // inutile car l'objet est vierge : il vient d'etre cree
272     // On efface toute la map
273     // erase(begin(), end());
274
275     // On recopie la map interne
276     (*this).TypeMap = PM.TypeMap;
277
278     // On cree la structure interne de la map avec les valeurs de celle passee en argument
279     Parametre::const_iterator it;
280     for(it=PM.begin();
281         it!=PM.end();
282         it++)
283       insert(
284              make_pair(
285                        (*it).first ,
286                        Versatile( (*it).second)
287                        ) );
288   }
289
290   //   map< string, TypeParam > Parametre::getTypeMap() const
291   //   {
292   //     return TypeMap;
293   //   }
294
295 }