50 if (bContenuEstChemin) {
51 std::string sFileContent(
""), sBuffer;
52 std::fstream FILfichier(cpContenu);
53 char sExceptionMessage[255];
57 if (FILfichier.is_open())
59 while (std::getline(FILfichier, sBuffer)) {
62 sFileContent += sBuffer + (!FILfichier.eof() ?
"\n" :
"");
66 cpContentToUse = _strdup(sFileContent.c_str());
71 sprintf_s(sExceptionMessage, 255,
"CGraphe::CGraphe(const char *cpChemin) : Impossible d'ouvrir le fichier \"%s\"\n", cpContenu);
72 throw CException(CGRAPHE_Ouverture_Fichier_Impossible, sExceptionMessage);
77 cpContentToUse = _strdup(cpContenu);
84 char sExceptionMessage[255];
86 std::string sRegexResult;
87 std::regex rRegex(
"NBSommets[ \\t]*=[ \\t]*([0-9]+)[ \\t]*\\nNBArcs[ \\t]*=[ \\t]*([0-9]+)[ \\t]*\\nSommets[ \\t]*=[ \\t]*(\\[)[ \\t]*\\n((?:Numero[ \\t]*=[ \\t]*[0-9]+\\n)*)\\][ \\t]*\\nArcs[ \\t]*=[ \\t]*(\\[)[ \\t]*\\n((?:Debut[ \\t]*=[ \\t]*[0-9]+[ \\t]*,[ \\t]*Fin[ \\t]*=[ \\t]*([0-9]+)[ \\t]*\\n)*)\\]\\s*");
88 std::cmatch cmMatchGlobal, cmMatchNumeric;
90 int iNbSommets, iNbArcs;
93 std::regex rNumericRegex(
"[0-9]+");
97 if (std::regex_match(cpContentToUse, cmMatchGlobal, rRegex)) {
100 for (
unsigned uiRegexIndex = 1; uiRegexIndex < cmMatchGlobal.size(); ++uiRegexIndex) {
101 sRegexResult = cmMatchGlobal[uiRegexIndex].str();
104 switch (sRegexResult[sRegexResult.length() - 1]) {
111 if (++uiRegexIndex < cmMatchGlobal.size()) {
113 sRegexResult = cmMatchGlobal[uiRegexIndex].str();
115 int iCurrentResIndex = 0, iResValue, iTempInitValue;
118 while (std::regex_search(sRegexResult.c_str(), cmMatchNumeric, rNumericRegex)) {
121 iResValue = atoi(cmMatchNumeric.str().c_str());
137 if (iCurrentResIndex % 2 == 0) {
138 iTempInitValue = iResValue;
152 sRegexResult = cmMatchNumeric.suffix();
158 if (iNbInit == 1 && iCurrentResIndex != iNbSommets) {
159 sprintf_s(sExceptionMessage, 255,
"CGraphe::CGraphe(const char *cpContenu, bool bContenuEstChemin) : %d sommets attendus %d sommets obtenus\n", iNbSommets, iCurrentResIndex);
160 throw CException(CGRAPHE_Erreur_NbArcs, sExceptionMessage);
165 else if (iNbInit == 2 && (iCurrentResIndex /= 2) != iNbArcs) {
166 sprintf_s(sExceptionMessage, 255,
"CGraphe::CGraphe(const char *cpContenu, bool bContenuEstChemin) : %d arcs attendus %d arcs obtenus\n", iNbArcs, iCurrentResIndex);
167 throw CException(CGRAPHE_Erreur_NbArcs, sExceptionMessage);
174 switch (uiRegexIndex) {
178 iNbSommets = atoi(sRegexResult.c_str());
183 iNbArcs = atoi(sRegexResult.c_str());
187 if (iNbSommets == 0 && iNbArcs != 0) {
188 throw CException(CGRAPHE_Erreur_NbArcs,
"CGraphe::CGraphe(const char *cpContenu, bool bContenuEstChemin) : Le nombre de sommets a été défini sur 0, le nombre d'arcs devrait l'être aussi.\n");
194 if (iNbArcs > (iNbSommets * iNbSommets - iNbSommets)) {
195 sprintf_s(sExceptionMessage, 255,
"CGraphe::CGraphe(const char *cpContenu, bool bContenuEstChemin) : Top d'arcs a initialiser, %d maximum .\n", (iNbSommets * iNbSommets - iNbSommets));
196 throw CException(CGRAPHE_Erreur_NbArcs, sExceptionMessage);
204 free(cpContentToUse);
207 throw CException(CGRAPHE_Erreur_Syntaxe,
"CGraphe::CGraphe(const char *cpContenu, bool bContenuEstChemin) : La chaîne de caractères ne correspond pas au format attendu\n");
211 throw CException(CGRAPHE_Erreur_Syntaxe,
"CGraphe::CGraphe(const char *cpContenu, bool bContenuEstChemin) : La chaîne de caractères est nulle\n");
235 unsigned int uBoucle;
258 char sExceptionMessage[255];
259 sprintf_s(sExceptionMessage, 255,
"CGraphe::GPHAjouterSommet(unsigned int uNumero) : Le sommet numero %d existe deja.\n", uNumero);
260 throw CException(CGRAPHE_Sommet_Existant, sExceptionMessage);
268 if (pSOMNouvelleListe == NULL) {
269 throw(
CException(CGRAPHE_Alloc_Echouee,
"CGraphe::GPHAjouterSommet(unsigned int uNumero) : Erreur d'allocation/réallocation.\n"));
310 if (pSOMNouvelleListe == NULL) {
311 throw(
CException(CGRAPHE_Alloc_Echouee,
"CGraphe::GPHSupprimerSommet(unsigned int uId) : Erreur d'allocation.\n"));
315 for (
unsigned uBoucle = 0, uCounter = 0; uBoucle <
uGPHTailleLSom; uBoucle++) {
323 delete pSOMNouvelleListe[uCounter];
364 char sExceptionMessage[255];
368 if (uIdDepart != uIdArrivee) {
385 sprintf_s(sExceptionMessage, 255,
"CGraphe::GPHLierSommets(unsigned int uIdDepart, unsigned int uIdArrivee) : L'arc sortant depuis %d vers %d existe deja.\n", uIdDepart, uIdArrivee);
386 throw CException(CGRAPHE_Arc_Existant, sExceptionMessage);
399 sprintf_s(sExceptionMessage, 255,
"CGraphe::GPHLierSommets(unsigned int uIdDepart, unsigned int uIdArrivee) : Le sommet de depart %d est inconnu.\n", uIdDepart);
400 throw CException(CGRAPHE_Sommet_Inconnu, sExceptionMessage);
405 sprintf_s(sExceptionMessage, 255,
"CGraphe::GPHLierSommets(unsigned int uIdDepart, unsigned int uIdArrivee) : Le sommet d'arrivee %d est inconnu.\n", uIdArrivee);
406 throw CException(CGRAPHE_Sommet_Inconnu, sExceptionMessage);
410 sprintf_s(sExceptionMessage, 255,
"CGraphe::GPHLierSommets(unsigned int uIdDepart, unsigned int uIdArrivee) : Tentative de relier le sommet %d avec lui-meme.\n", uIdArrivee);
411 throw CException(CGRAPHE_Auto_Referencement, sExceptionMessage);
429 char sExceptionMessage[255];
455 sprintf_s(sExceptionMessage, 255,
"CGraphe::GPHDelierSommets(unsigned int uIdDepart, unsigned int uIdArrivee) : Le sommet de depart %d est inconnu.\n", uIdDepart);
456 throw CException(CGRAPHE_Sommet_Inconnu, sExceptionMessage);
461 sprintf_s(sExceptionMessage, 255,
"CGraphe::GPHDelierSommets(unsigned int uIdDepart, unsigned int uIdArrivee) : Le sommet d'arrivee %d est inconnu.\n", uIdArrivee);
462 throw CException(CGRAPHE_Sommet_Inconnu, sExceptionMessage);
487 unsigned int uBoucle;
526 unsigned int uBoucle;
560 char sExceptionMessage[255];
561 sprintf_s(sExceptionMessage, 255,
"Le sommet %d n'est pas dans le graphe.\n", uId);
562 throw CException(CGRAPHE_Sommet_Inconnu, sExceptionMessage);
574 unsigned int uBoucle;
585 std::cout << std::endl;
596 unsigned int uBoucle;
602 return *GPHGrapheRenv;
615 if (
this != &GPHParam) {
622 throw(
CException(CGRAPHE_Alloc_Echouee,
"CSommet::operator=(const CSommet & SOMParam) : Erreur d'allocation/réallocation.\n"));
625 unsigned int uBoucle;