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(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);
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 >()
62 TypeMap[ACCOUNT].type = STRING;
63 TypeMap[ACCOUNT].maxelem = 1;
65 TypeMap[CHECKPOINT].type = LONG;
66 TypeMap[CHECKPOINT].maxelem = 1;
68 TypeMap[CKPTINTERVAL].type = LONG;
69 TypeMap[CKPTINTERVAL].maxelem = 1;
71 TypeMap[CREATIONTIME].type = LONG;
72 TypeMap[CREATIONTIME].maxelem = 1;
74 TypeMap[EGROUP].type = STRING;
75 TypeMap[EGROUP].maxelem = 1;
77 TypeMap[ELIGIBLETIME].type = LONG;
78 TypeMap[ELIGIBLETIME].maxelem = 1;
80 TypeMap[EUSER].type = STRING;
81 TypeMap[EUSER].maxelem = 1;
83 TypeMap[EXECUTABLE].type = STRING;
84 TypeMap[EXECUTABLE].maxelem = 1;
86 TypeMap[EXECUTIONHOST].type = STRING;
87 TypeMap[EXECUTIONHOST].maxelem = 0;
89 TypeMap[HOLD].type = LONG;
90 TypeMap[HOLD].maxelem = 1;
92 TypeMap[ID].type = STRING;
93 TypeMap[ID].maxelem = 1;
95 TypeMap[INFILE].type = COUPLE;
96 TypeMap[INFILE].maxelem = 0;
98 TypeMap[MAIL].type = STRING;
99 TypeMap[MAIL].maxelem = 1;
101 TypeMap[MAXCPUTIME].type = LONG;
102 TypeMap[MAXCPUTIME].maxelem = 1;
104 TypeMap[MAXDISKSIZE].type = LONG;
105 TypeMap[MAXDISKSIZE].maxelem = 1;
107 TypeMap[MAXRAMSIZE].type = LONG;
108 TypeMap[MAXRAMSIZE].maxelem = 1;
110 TypeMap[MAXWALLTIME].type = LONG;
111 TypeMap[MAXWALLTIME].maxelem = 1;
113 TypeMap[MODIFICATIONTIME].type = LONG;
114 TypeMap[MODIFICATIONTIME].maxelem = 1;
116 TypeMap[NAME].type = STRING;
117 TypeMap[NAME].maxelem = 1;
119 TypeMap[OUTFILE].type = COUPLE;
120 TypeMap[OUTFILE].maxelem = 0;
122 TypeMap[PID].type = LONG;
123 TypeMap[PID].maxelem = 1;
125 TypeMap[QUEUE].type = STRING;
126 TypeMap[QUEUE].maxelem = 1;
128 TypeMap[QUEUEDTIME].type = LONG;
129 TypeMap[QUEUEDTIME].maxelem = 1;
131 TypeMap[SERVER].type = STRING;
132 TypeMap[SERVER].maxelem = 1;
134 TypeMap[STARTDATE].type = LONG;
135 TypeMap[STARTDATE].maxelem = 1;
137 TypeMap[STATE].type = STRING;
138 TypeMap[STATE].maxelem = 1;
140 TypeMap[TEXT].type = STRING;
141 TypeMap[TEXT].maxelem = 1;
143 TypeMap[TMPDIR].type = STRING;
144 TypeMap[TMPDIR].maxelem = 1;
146 TypeMap[USEDCPUTIME].type = LONG;
147 TypeMap[USEDCPUTIME].maxelem = 1;
149 TypeMap[USEDDISKSIZE].type = LONG;
150 TypeMap[USEDDISKSIZE].maxelem = 1;
152 TypeMap[USEDRAMSIZE].type = LONG;
153 TypeMap[USEDRAMSIZE].maxelem = 1;
155 TypeMap[USEDWALLTIME].type = LONG;
156 TypeMap[USEDWALLTIME].maxelem = 1;
158 TypeMap[USER].type = STRING;
159 TypeMap[USER].maxelem = 1;
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)
167 // On controle que la clef est valide
168 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
170 // On recherche la valeur associee...
171 Versatile & V = map< string, Versatile >::operator [] (mk);
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
178 V.setType(TypeMap[mk].type);
179 V.setMaxSize(TypeMap[mk].maxelem);
184 // Operateur de recherche dans la map
185 // Cet operateur agit sur les objets CONSTANTS
186 const Versatile & Parametre::operator [] (const string & mk) const
188 // On controle que la clef est valide
189 if (TypeMap.find(mk) == TypeMap.end()) throw InvalidKeyException(mk.c_str());
191 // On recherche la valeur associee
192 Parametre::const_iterator it = find(mk);
193 const Versatile & V = (*it).second;
198 // Operateur d'affectation
199 Parametre & Parametre::operator =(const Parametre & PM)
201 // On ne reaffecte pas l'objet a lui-meme, sinon aie, aie, aie
202 if (this == &PM) return *this;
204 // On efface toute la map
205 erase(begin(), end());
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;
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)
222 // Constructeur par recopie
223 Parametre::Parametre(const Parametre & PM)
225 // inutile car l'objet est vierge : il vient d'etre cree
226 // On efface toute la map
227 // erase(begin(), end());
229 // On recopie la map interne
230 (*this).TypeMap = PM.TypeMap;
232 // On cree la structure interne de la map avec les valeurs de celle passee en argument
233 Parametre::const_iterator it;
240 Versatile( (*it).second)
244 // map< string, TypeParam > Parametre::getTypeMap() const