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(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);
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 >()
61 TypeMap[ACCOUNT].type = STRING;
62 TypeMap[ACCOUNT].maxelem = 1;
64 TypeMap[CHECKPOINT].type = LONG;
65 TypeMap[CHECKPOINT].maxelem = 1;
67 TypeMap[CKPTINTERVAL].type = LONG;
68 TypeMap[CKPTINTERVAL].maxelem = 1;
70 TypeMap[CREATIONTIME].type = LONG;
71 TypeMap[CREATIONTIME].maxelem = 1;
73 TypeMap[EGROUP].type = STRING;
74 TypeMap[EGROUP].maxelem = 1;
76 TypeMap[ELIGIBLETIME].type = LONG;
77 TypeMap[ELIGIBLETIME].maxelem = 1;
79 TypeMap[EUSER].type = STRING;
80 TypeMap[EUSER].maxelem = 1;
82 TypeMap[EXECUTABLE].type = STRING;
83 TypeMap[EXECUTABLE].maxelem = 1;
85 TypeMap[EXECUTIONHOST].type = STRING;
86 TypeMap[EXECUTIONHOST].maxelem = 0;
88 TypeMap[HOLD].type = LONG;
89 TypeMap[HOLD].maxelem = 1;
91 TypeMap[ID].type = STRING;
92 TypeMap[ID].maxelem = 1;
94 TypeMap[INFILE].type = COUPLE;
95 TypeMap[INFILE].maxelem = 0;
97 TypeMap[MAIL].type = STRING;
98 TypeMap[MAIL].maxelem = 1;
100 TypeMap[MAXCPUTIME].type = LONG;
101 TypeMap[MAXCPUTIME].maxelem = 1;
103 TypeMap[MAXDISKSIZE].type = LONG;
104 TypeMap[MAXDISKSIZE].maxelem = 1;
106 TypeMap[MAXRAMSIZE].type = LONG;
107 TypeMap[MAXRAMSIZE].maxelem = 1;
109 TypeMap[MAXWALLTIME].type = LONG;
110 TypeMap[MAXWALLTIME].maxelem = 1;
112 TypeMap[MODIFICATIONTIME].type = LONG;
113 TypeMap[MODIFICATIONTIME].maxelem = 1;
115 TypeMap[NAME].type = STRING;
116 TypeMap[NAME].maxelem = 1;
118 TypeMap[OUTFILE].type = COUPLE;
119 TypeMap[OUTFILE].maxelem = 0;
121 TypeMap[PID].type = LONG;
122 TypeMap[PID].maxelem = 1;
124 TypeMap[QUEUE].type = STRING;
125 TypeMap[QUEUE].maxelem = 1;
127 TypeMap[QUEUEDTIME].type = LONG;
128 TypeMap[QUEUEDTIME].maxelem = 1;
130 TypeMap[SERVER].type = STRING;
131 TypeMap[SERVER].maxelem = 1;
133 TypeMap[STARTDATE].type = LONG;
134 TypeMap[STARTDATE].maxelem = 1;
136 TypeMap[STATE].type = STRING;
137 TypeMap[STATE].maxelem = 1;
139 TypeMap[TEXT].type = STRING;
140 TypeMap[TEXT].maxelem = 1;
142 TypeMap[TMPDIR].type = STRING;
143 TypeMap[TMPDIR].maxelem = 1;
145 TypeMap[USEDCPUTIME].type = LONG;
146 TypeMap[USEDCPUTIME].maxelem = 1;
148 TypeMap[USEDDISKSIZE].type = LONG;
149 TypeMap[USEDDISKSIZE].maxelem = 1;
151 TypeMap[USEDRAMSIZE].type = LONG;
152 TypeMap[USEDRAMSIZE].maxelem = 1;
154 TypeMap[USEDWALLTIME].type = LONG;
155 TypeMap[USEDWALLTIME].maxelem = 1;
157 TypeMap[USER].type = STRING;
158 TypeMap[USER].maxelem = 1;
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)
166 // On controle que la clef est valide
167 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
169 // On recherche la valeur associee...
170 Versatile & V = map< string, Versatile >::operator [] (mk);
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
177 V.setType(TypeMap[mk].type);
178 V.setMaxSize(TypeMap[mk].maxelem);
183 // Operateur de recherche dans la map
184 // Cet operateur agit sur les objets CONSTANTS
185 const Versatile & Parametre::operator [] (const string & mk) const
187 // On controle que la clef est valide
188 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
190 // On recherche la valeur associee
191 Parametre::const_iterator it = find(mk);
192 const Versatile & V = (*it).second;
197 // Operateur d'affectation
198 Parametre & Parametre::operator =(const Parametre & PM)
200 // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
201 if (this == &PM) return *this;
203 // On efface toute la map
204 erase(begin(), end());
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;
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)
221 // Constructeur par recopie
222 Parametre::Parametre(const Parametre & PM)
224 // inutile car l'objet est vierge : il vient d'etre cree
225 // On efface toute la map
226 // erase(begin(), end());
228 // On recopie la map interne
229 (*this).TypeMap = PM.TypeMap;
231 // On cree la structure interne de la map avec les valeurs de celle passee en argument
232 Parametre::const_iterator it;
239 Versatile( (*it).second)
243 // map< string, TypeParam > Parametre::getTypeMap() const