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"
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(ARGUMENTS);
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(ENDTIME);
26 def_static_MapKey(EUSER);
27 def_static_MapKey(EXECUTABLE);
28 def_static_MapKey(EXECUTIONHOST);
29 def_static_MapKey(EXITCODE);
30 def_static_MapKey(HOLD);
31 def_static_MapKey(ID);
32 def_static_MapKey(INFILE);
33 def_static_MapKey(MAIL);
34 def_static_MapKey(MAXCPUTIME);
35 def_static_MapKey(MAXDISKSIZE);
36 def_static_MapKey(MAXRAMSIZE);
37 def_static_MapKey(MAXWALLTIME);
38 def_static_MapKey(MODIFICATIONTIME);
39 def_static_MapKey(NAME);
40 def_static_MapKey(NBPROC);
41 def_static_MapKey(OUTFILE);
42 def_static_MapKey(PID);
43 def_static_MapKey(QUEUE);
44 def_static_MapKey(QUEUEDTIME);
45 def_static_MapKey(SERVER);
46 def_static_MapKey(STARTTIME);
47 def_static_MapKey(STATE);
48 def_static_MapKey(TEXT);
49 def_static_MapKey(TMPDIR);
50 def_static_MapKey(USEDCPUTIME);
51 def_static_MapKey(USEDDISKSIZE);
52 def_static_MapKey(USEDRAMSIZE);
53 def_static_MapKey(USEDWALLTIME);
54 def_static_MapKey(USER);
58 // Constructeur standard
59 // La map interne TypeMap possede les memes clefs que la map principale, mais les
60 // valeurs associees contiennent le type des clefs de la map principale ainsi que
61 // le nombre de valeurs autorisees dans l'objet Versatile (0=nombre quelconque,
62 // sinon valeur precisee)
63 Parametre::Parametre() : map< string, Versatile >()
65 TypeMap[ACCOUNT].type = STRING;
66 TypeMap[ACCOUNT].maxelem = 1;
68 TypeMap[ARGUMENTS].type = STRING;
69 TypeMap[ARGUMENTS].maxelem = 0;
71 TypeMap[CHECKPOINT].type = LONG;
72 TypeMap[CHECKPOINT].maxelem = 1;
74 TypeMap[CKPTINTERVAL].type = LONG;
75 TypeMap[CKPTINTERVAL].maxelem = 1;
77 TypeMap[CREATIONTIME].type = LONG;
78 TypeMap[CREATIONTIME].maxelem = 1;
80 TypeMap[EGROUP].type = STRING;
81 TypeMap[EGROUP].maxelem = 1;
83 TypeMap[ELIGIBLETIME].type = LONG;
84 TypeMap[ELIGIBLETIME].maxelem = 1;
86 TypeMap[ENDTIME].type = LONG;
87 TypeMap[ENDTIME].maxelem = 1;
89 TypeMap[EUSER].type = STRING;
90 TypeMap[EUSER].maxelem = 1;
92 TypeMap[EXECUTABLE].type = STRING;
93 TypeMap[EXECUTABLE].maxelem = 1;
95 TypeMap[EXECUTIONHOST].type = STRING;
96 TypeMap[EXECUTIONHOST].maxelem = 0;
98 TypeMap[EXITCODE].type = LONG;
99 TypeMap[EXITCODE].maxelem = 1;
101 TypeMap[HOLD].type = LONG;
102 TypeMap[HOLD].maxelem = 1;
104 TypeMap[ID].type = STRING;
105 TypeMap[ID].maxelem = 1;
107 TypeMap[INFILE].type = COUPLE;
108 TypeMap[INFILE].maxelem = 0;
110 TypeMap[MAIL].type = STRING;
111 TypeMap[MAIL].maxelem = 1;
113 TypeMap[MAXCPUTIME].type = LONG;
114 TypeMap[MAXCPUTIME].maxelem = 1;
116 TypeMap[MAXDISKSIZE].type = LONG;
117 TypeMap[MAXDISKSIZE].maxelem = 1;
119 TypeMap[MAXRAMSIZE].type = LONG;
120 TypeMap[MAXRAMSIZE].maxelem = 1;
122 TypeMap[MAXWALLTIME].type = LONG;
123 TypeMap[MAXWALLTIME].maxelem = 1;
125 TypeMap[MODIFICATIONTIME].type = LONG;
126 TypeMap[MODIFICATIONTIME].maxelem = 1;
128 TypeMap[NAME].type = STRING;
129 TypeMap[NAME].maxelem = 1;
131 TypeMap[NBPROC].type = LONG;
132 TypeMap[NBPROC].maxelem = 1;
134 TypeMap[OUTFILE].type = COUPLE;
135 TypeMap[OUTFILE].maxelem = 0;
137 TypeMap[PID].type = LONG;
138 TypeMap[PID].maxelem = 1;
140 TypeMap[QUEUE].type = STRING;
141 TypeMap[QUEUE].maxelem = 1;
143 TypeMap[QUEUEDTIME].type = LONG;
144 TypeMap[QUEUEDTIME].maxelem = 1;
146 TypeMap[SERVER].type = STRING;
147 TypeMap[SERVER].maxelem = 1;
149 TypeMap[STARTTIME].type = LONG;
150 TypeMap[STARTTIME].maxelem = 1;
152 TypeMap[STATE].type = STRING;
153 TypeMap[STATE].maxelem = 1;
155 TypeMap[TEXT].type = STRING;
156 TypeMap[TEXT].maxelem = 1;
158 TypeMap[TMPDIR].type = STRING;
159 TypeMap[TMPDIR].maxelem = 1;
161 TypeMap[USEDCPUTIME].type = LONG;
162 TypeMap[USEDCPUTIME].maxelem = 1;
164 TypeMap[USEDDISKSIZE].type = LONG;
165 TypeMap[USEDDISKSIZE].maxelem = 1;
167 TypeMap[USEDRAMSIZE].type = LONG;
168 TypeMap[USEDRAMSIZE].maxelem = 1;
170 TypeMap[USEDWALLTIME].type = LONG;
171 TypeMap[USEDWALLTIME].maxelem = 1;
173 TypeMap[USER].type = STRING;
174 TypeMap[USER].maxelem = 1;
177 // Operateur de recherche dans la map
178 // Cet operateur agit sur les objets NON CONSTANTS, il autorise la modification de
179 // la valeur associée à la clef car il retourne une reference non constante
180 Versatile & Parametre::operator [] (const string & mk)
182 // On controle que la clef est valide
183 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
185 // On recherche la valeur associee...
186 Versatile & V = map< string, Versatile >::operator [] (mk);
188 // ... et on l'initialise systematiquement
189 // ATTENTION : si un probleme de type survient (ie, on stocke une valeur d'un type
190 // different de celui inscrit dans TypeMap) une exception TypeMismatchException est
193 V.setType(TypeMap[mk].type);
194 V.setMaxSize(TypeMap[mk].maxelem);
199 // Operateur de recherche dans la map
200 // Cet operateur agit sur les objets CONSTANTS
201 const Versatile & Parametre::operator [] (const string & mk) const
203 // On controle que la clef est valide
204 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
206 // On recherche la valeur associee
207 Parametre::const_iterator it = find(mk);
208 const Versatile & V = (*it).second;
213 // Operateur d'affectation
214 Parametre & Parametre::operator =(const Parametre & PM)
216 // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
217 if (this == &PM) return *this;
219 // On efface toute la map
220 erase(begin(), end());
222 // On recopie la map interne
223 // Meme si cela ne sert a rien pour le moment car les maps internes sont identiques,
224 // il n'est pas exclu que dans un avenir proche elles puissent etre differentes
225 (*this).TypeMap = PM.TypeMap;
227 // On recree la structure interne de la map avec les valeurs de celle passee en argument
228 Parametre::const_iterator it;
229 for(it=PM.begin(); it!=PM.end(); it++)
230 insert(make_pair( (*it).first ,
231 Versatile( (*it).second)
237 // Constructeur par recopie
238 Parametre::Parametre(const Parametre & PM)
240 // inutile car l'objet est vierge : il vient d'etre cree
241 // On efface toute la map
242 // erase(begin(), end());
244 // On recopie la map interne
245 (*this).TypeMap = PM.TypeMap;
247 // On cree la structure interne de la map avec les valeurs de celle passee en argument
248 Parametre::const_iterator it;
255 Versatile( (*it).second)
259 // map< string, TypeParam > Parametre::getTypeMap() const