This repository was archived by the owner on Aug 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormation.cpp
More file actions
108 lines (93 loc) · 3.19 KB
/
Formation.cpp
File metadata and controls
108 lines (93 loc) · 3.19 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
#include "Formation.h"
Formation::Formation(QString n,QString d,std::map<UV*,bool> uv,std::map<Categorie,unsigned int> nbCred)
{
Formation(n,d,uv,nbCred,std::vector<Condition>());
}
Formation::Formation(QString n,QString d,std::map<UV*,bool> uv,std::map<Categorie,unsigned int> nbCred,std::vector<Condition> cv)
{
TemplateManager<Formation>& tFormation=TemplateManager<Formation>::getInstance();
if(!tFormation.alreadyExist(n))
{
nom=n;
description=d;
uvs=uv;
nbCredits=nbCred;
critereValidation=cv;
tFormation.New(*this);
}
else
{
throw FormationException("Erreur : la formation "+n.toStdString()+" existe deja !");
}
}
int Formation::getNbCreditsTotal()const
{
int sum=0;
typedef std::map<Categorie, unsigned int>::const_iterator it_type;
for(it_type iterator = nbCredits.begin(); iterator != nbCredits.end(); iterator++)
{
sum += iterator->second;
}
return sum;
}
void Formation::addUv(UV* uv, bool required)
{
std::pair<std::map<UV*,bool>::iterator,bool> ret = uvs.insert ( std::pair<UV*,bool>(uv,required) );
if (ret.second==false) //echec lors de l'insertion
{
throw FormationException("Erreur, l'Uv appartient déjà à la formation.");
}
if(required)//ajouter les crédits dans les crédits à valider pour chaque catégorie de l'UV si il n'y en a pas assez
{
std::map<Categorie, unsigned int> cat=uv->getCredits();
typedef std::map<Categorie, unsigned int>::iterator it_type;
for(it_type iterator = cat.begin(); iterator != cat.end(); iterator++)
{
if(nbCredits[iterator->first]<iterator->second)//si il n'y a pas assez de crédits obligatoires dans les catégories d'une Uv obligatoire
{
nbCredits[iterator->first]=iterator->second;
}
}
}
}
void Formation::setNom(QString n)
{
TemplateManager<Formation>& tFormation=TemplateManager<Formation>::getInstance();
if(!tFormation.alreadyExist(n))
{
tFormation.erase(*this);
nom=n;
tFormation.New(*this);
}
else
{
throw FormationException("Erreur : la formation "+n.toStdString()+" existe deja !");
}
}
std::map<Categorie, unsigned int> getCategorieOfUV(std::vector<UV*> uvs)
{
std::map<Categorie, unsigned int> res;
for(std::vector<UV*>::iterator it=uvs.begin();it != uvs.end() ; it++)
{
std::map<Categorie, unsigned int> temp=(*it)->getCredits();
for(std::map<Categorie, unsigned int>::iterator it2=temp.begin();it2 != temp.end() ; it2++)
{
res[it2->first]+=it2->second;
}
}
return res;
}
std::vector<UV*> uvNotIn(std::vector<UV*> thisVector)
{
std::vector<UV*> res;
TemplateManager<UV>& tUV=TemplateManager<UV>::getInstance();
for(std::vector<UV>::iterator it=tUV.getIterator();it != tUV.end() ; it++)
{
if(std::find(thisVector.begin(),thisVector.end(),&(*it))==thisVector.end())
{
res.push_back(&(*it));
}
}
return res;
}
bool operator==(Formation f1, Formation f2 ){return (f1.getStrLabel()==f2.getStrLabel());}