4 * Auteur : Ivan DUTKA-MALEN - EDF R&D
5 * Date : Septembre 2003
11 #include "Batch_Versatile.hxx"
12 #include "Batch_InvalidKeyException.hxx"
13 #include "Batch_Parametre.hxx"
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);
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 >()
66 TypeMap[ACCOUNT].type = STRING;
67 TypeMap[ACCOUNT].maxelem = 1;
69 TypeMap[ARGUMENTS].type = STRING;
70 TypeMap[ARGUMENTS].maxelem = 0;
72 TypeMap[CHECKPOINT].type = LONG;
73 TypeMap[CHECKPOINT].maxelem = 1;
75 TypeMap[CKPTINTERVAL].type = LONG;
76 TypeMap[CKPTINTERVAL].maxelem = 1;
78 TypeMap[CREATIONTIME].type = LONG;
79 TypeMap[CREATIONTIME].maxelem = 1;
81 TypeMap[EGROUP].type = STRING;
82 TypeMap[EGROUP].maxelem = 1;
84 TypeMap[ELIGIBLETIME].type = LONG;
85 TypeMap[ELIGIBLETIME].maxelem = 1;
87 TypeMap[ENDTIME].type = LONG;
88 TypeMap[ENDTIME].maxelem = 1;
90 TypeMap[EUSER].type = STRING;
91 TypeMap[EUSER].maxelem = 1;
93 TypeMap[EXECUTABLE].type = STRING;
94 TypeMap[EXECUTABLE].maxelem = 1;
96 TypeMap[EXECUTIONHOST].type = STRING;
97 TypeMap[EXECUTIONHOST].maxelem = 0;
99 TypeMap[EXITCODE].type = LONG;
100 TypeMap[EXITCODE].maxelem = 1;
102 TypeMap[HOLD].type = LONG;
103 TypeMap[HOLD].maxelem = 1;
105 TypeMap[ID].type = STRING;
106 TypeMap[ID].maxelem = 1;
108 TypeMap[INFILE].type = COUPLE;
109 TypeMap[INFILE].maxelem = 0;
111 TypeMap[MAIL].type = STRING;
112 TypeMap[MAIL].maxelem = 1;
114 TypeMap[MAXCPUTIME].type = LONG;
115 TypeMap[MAXCPUTIME].maxelem = 1;
117 TypeMap[MAXDISKSIZE].type = LONG;
118 TypeMap[MAXDISKSIZE].maxelem = 1;
120 TypeMap[MAXRAMSIZE].type = LONG;
121 TypeMap[MAXRAMSIZE].maxelem = 1;
123 TypeMap[MAXWALLTIME].type = LONG;
124 TypeMap[MAXWALLTIME].maxelem = 1;
126 TypeMap[MODIFICATIONTIME].type = LONG;
127 TypeMap[MODIFICATIONTIME].maxelem = 1;
129 TypeMap[NAME].type = STRING;
130 TypeMap[NAME].maxelem = 1;
132 TypeMap[NBPROC].type = LONG;
133 TypeMap[NBPROC].maxelem = 1;
135 TypeMap[OUTFILE].type = COUPLE;
136 TypeMap[OUTFILE].maxelem = 0;
138 TypeMap[PID].type = LONG;
139 TypeMap[PID].maxelem = 1;
141 TypeMap[QUEUE].type = STRING;
142 TypeMap[QUEUE].maxelem = 1;
144 TypeMap[QUEUEDTIME].type = LONG;
145 TypeMap[QUEUEDTIME].maxelem = 1;
147 TypeMap[SERVER].type = STRING;
148 TypeMap[SERVER].maxelem = 1;
150 TypeMap[STARTTIME].type = LONG;
151 TypeMap[STARTTIME].maxelem = 1;
153 TypeMap[STATE].type = STRING;
154 TypeMap[STATE].maxelem = 1;
156 TypeMap[TEXT].type = STRING;
157 TypeMap[TEXT].maxelem = 1;
159 TypeMap[TMPDIR].type = STRING;
160 TypeMap[TMPDIR].maxelem = 1;
162 TypeMap[USEDCPUTIME].type = LONG;
163 TypeMap[USEDCPUTIME].maxelem = 1;
165 TypeMap[USEDDISKSIZE].type = LONG;
166 TypeMap[USEDDISKSIZE].maxelem = 1;
168 TypeMap[USEDRAMSIZE].type = LONG;
169 TypeMap[USEDRAMSIZE].maxelem = 1;
171 TypeMap[USEDWALLTIME].type = LONG;
172 TypeMap[USEDWALLTIME].maxelem = 1;
174 TypeMap[USER].type = STRING;
175 TypeMap[USER].maxelem = 1;
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)
183 // On controle que la clef est valide
184 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
186 // On recherche la valeur associee...
187 Versatile & V = map< string, Versatile >::operator [] (mk);
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
194 V.setType(TypeMap[mk].type);
195 V.setMaxSize(TypeMap[mk].maxelem);
200 // Operateur de recherche dans la map
201 // Cet operateur agit sur les objets CONSTANTS
202 const Versatile & Parametre::operator [] (const string & mk) const
204 // On controle que la clef est valide
205 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
207 // On recherche la valeur associee
208 Parametre::const_iterator it = find(mk);
209 const Versatile & V = (*it).second;
214 // Operateur d'affectation
215 Parametre & Parametre::operator =(const Parametre & PM)
217 // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
218 if (this == &PM) return *this;
220 // On efface toute la map
221 erase(begin(), end());
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;
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)
238 // Constructeur par recopie
239 Parametre::Parametre(const Parametre & PM)
241 // inutile car l'objet est vierge : il vient d'etre cree
242 // On efface toute la map
243 // erase(begin(), end());
245 // On recopie la map interne
246 (*this).TypeMap = PM.TypeMap;
248 // On cree la structure interne de la map avec les valeurs de celle passee en argument
249 Parametre::const_iterator it;
256 Versatile( (*it).second)
260 // map< string, TypeParam > Parametre::getTypeMap() const