-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUTProfiler.h
More file actions
222 lines (196 loc) · 6.43 KB
/
UTProfiler.h
File metadata and controls
222 lines (196 loc) · 6.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#ifndef UT_PROFILER_h
#define UT_PROFILER_h
#include <QString>
#include <QTextStream>
#include <vector>
#include <map>
using namespace std;
class UTProfilerException{
public:
UTProfilerException(const QString& message, const QString &f="na", unsigned int l=0):
info(message),file(f),line(l){}
QString getInfo() const { return info; }
#ifndef NDEBUG
// retourne le fichier dans lequel cettte exception a été levée.
QString getFile() const { return file; }
// retourne la ligne du fichier à laquelle cette exception a été levée.
unsigned int getLine() const { return line; }
#endif
private:
QString info;
QString file;
unsigned int line;
};
enum Categorie {
/* Connaissances Scientifiques */ CS, /* Techniques et Méthodes */ TM,
/* Technologies et Sciences de l'Homme */ TSH, /* Stage et Projet */ SP
};
QTextStream& operator<<(QTextStream& f, const Categorie& s);
Categorie StringToCategorie(const QString& s);
QString CategorieToString(Categorie c);
QTextStream& operator>>(QTextStream& f, Categorie& cat);
enum Note { A, B, C, D, E, F, FX, RES, ABS, /* en cours */ EC };
enum Saison { Automne, Printemps };
inline QTextStream& operator<<(QTextStream& f, const Saison& s) { if (s==Automne) f<<"A"; else f<<"P"; return f;}
class Semestre {
Saison saison;
unsigned int annee;
public:
Semestre(Saison s, unsigned int a):saison(s),annee(a){ if (annee<1972||annee>2099) throw UTProfilerException("annee non valide"); }
Saison getSaison() const { return saison; }
unsigned int getAnnee() const { return annee; }
void setSaison (Saison s){ saison = s;}
void setAnnee (unsigned int a){ annee = a;}
};
inline QTextStream& operator<<(QTextStream& f, const Semestre& s) { return f<<s.getSaison()<<s.getAnnee()%100; }
//************************
// transformation de string en objet et inversement.
Note StringToNote(const QString& s);
QString NoteToString(Note c);
Saison StringToSaison(const QString& s);
QString SaisonToString(Saison c);
//***********************
class UV {
QString code;
QString titre;
unsigned int nbCredits;
Categorie categorie;
bool automne;
bool printemps;
//UV(const UV& u);
UV& operator=(const UV& u);
UV(const QString& c, const QString& t, unsigned int nbc, Categorie cat, bool a, bool p):
code(c),titre(t),nbCredits(nbc),categorie(cat),automne(a),printemps(p){}
friend class UVManager;
public:
// Public ?
UV(const UV& u);
////
QString getCode() const { return code; }
QString getTitre() const { return titre; }
unsigned int getNbCredits() const { return nbCredits; }
Categorie getCategorie() const { return categorie; }
bool ouvertureAutomne() const { return automne; }
bool ouverturePrintemps() const { return printemps; }
void setCode(const QString& c) { code=c; }
void setTitre(const QString& t) { titre=t; }
void setNbCredits(unsigned int n) { nbCredits=n; }
void setCategorie(Categorie c) { categorie=c; }
void setOuvertureAutomne(bool b) { automne=b; }
void setOuverturePrintemps(bool b) { printemps=b; }
};
QTextStream& operator<<(QTextStream& f, const UV& uv);
class UVManager {
private:
UV** uvs;
unsigned int nbUV;
unsigned int nbMaxUV;
void addItem(UV* uv);
bool modification;
UVManager(const UVManager& um);
UVManager& operator=(const UVManager& um);
UVManager();
~UVManager();
QString file;
friend struct Handler;
struct Handler{
UVManager* instance;
Handler():instance(0){}
~Handler(){ if (instance) delete instance; instance=0; }
};
static Handler handler;
public:
void SupprUV(QString);
UV* trouverUV(const QString& c) const;
UV &creatUV();
int existUV(const QString& code) const;
void load(const QString& f);
void save(const QString& f);
static UVManager& getInstance();
static void libererInstance();
void ajouterUV(const QString& c, const QString& t, unsigned int nbc, Categorie cat, bool a, bool p);
const UV& getUV(const QString& code) const;
UV& getUV(const QString& code);
class Iterator {
friend class UVManager;
UV** currentUV;
unsigned int nbRemain;
Iterator(UV** u, unsigned nb):currentUV(u),nbRemain(nb){}
public:
Iterator():nbRemain(0),currentUV(0){}
bool isDone() const { return nbRemain==0; }
void next() {
if (isDone())
throw UTProfilerException("error, next on an iterator which is done");
nbRemain--;
currentUV++;
}
UV& current() const {
if (isDone())
throw UTProfilerException("error, indirection on an iterator which is done");
return **currentUV;
}
};
Iterator getIterator() {
return Iterator(uvs,nbUV);
}
class iterator {
UV** current;
iterator(UV** u):current(u){}
friend class UVManager;
public:
iterator():current(0){};
UV& operator*() const { return **current; }
bool operator!=(iterator it) const { return current!=it.current; }
iterator& operator++(){ ++current; return *this; }
};
iterator begin() { return iterator(uvs); }
iterator end() { return iterator(uvs+nbUV); }
class FilterIterator {
friend class UVManager;
UV** currentUV;
unsigned int nbRemain;
Categorie categorie;
FilterIterator(UV** u, unsigned nb, Categorie c):currentUV(u),nbRemain(nb),categorie(c){
while(nbRemain>0 && (*currentUV)->getCategorie()!=categorie){
nbRemain--; currentUV++;
}
}
public:
FilterIterator():nbRemain(0),currentUV(0){}
bool isDone() const { return nbRemain==0; }
void next() {
if (isDone())
throw UTProfilerException("error, next on an iterator which is done");
do {
nbRemain--; currentUV++;
}while(nbRemain>0 && (*currentUV)->getCategorie()!=categorie);
}
UV& current() const {
if (isDone())
throw UTProfilerException("error, indirection on an iterator which is done");
return **currentUV;
}
};
FilterIterator getFilterIterator(Categorie c) {
return FilterIterator(uvs,nbUV,c);
}
};
/*
class Inscription {
const UV* uv;
Semestre semestre;
Note resultat;
public:
Inscription(const UV& u, const Semestre& s, Note res=EC):uv(&u),semestre(s),resultat(res){}
const UV& getUV() const { return *uv; }
Semestre getSemestre() const { return semestre; }
Note getResultat() const { return resultat; }
void setResultat(Note newres) { resultat=newres; }
};
*/
/*class Dossier {
};*/
class Formation{
};
#endif