From 7f55fb9a5e8b1c4b4a28efef8f4efc693eec2500 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 27 Oct 2023 18:01:17 +0200 Subject: [PATCH] make it compile --- includes/Projet.hpp | 36 ++++++++++++++--------------- includes/ProtoProjet.hpp | 15 ++++++------ includes/Tache.hpp | 3 +++ src/Projet.cpp | 49 ++++++++++++++++++++++++---------------- src/ProtoProjet.cpp | 24 +++++++++++++------- 5 files changed, 73 insertions(+), 54 deletions(-) diff --git a/includes/Projet.hpp b/includes/Projet.hpp index c89f1fe..01adafb 100644 --- a/includes/Projet.hpp +++ b/includes/Projet.hpp @@ -1,43 +1,43 @@ #ifndef TP5_PROJET_HPP #define TP5_PROJET_HPP 1 -#include -#include -#include #include "../includes/Tache.hpp" +#include +#include +#include +struct Projet { + // Alias parce que le type est long + using VecTaches = std::vector>; + +private: + // Héritage de tache ? + // Tache fin; + VecTaches taches; -class Projet { - //Héritage de tache ? - //Tache fin; - std::vector taches; friend std::ostream &operator<<(std::ostream &, const Projet &); public: - Projet(); - Projet(std::vector taches); // constructor + Projet(); // constructor + Projet(VecTaches); // constructor virtual ~Projet(); // destructor Projet(const Projet &); // copy constructor const Projet &operator=(const Projet &); // copy assignement - std::vector getTaches(){ - return taches; - } + VecTaches getTaches() { return taches; } // Retourne une paire d'indentifiants de tâches au hasard - std::pair pick_two_random_tasks(); + std::pair pick_two_random_tasks(); // Indique pour une tâche si elle fait partie du projet - Tache* Projet::contains(int id); + Tache *contains(int id); // Donne une version du vecteur de tâches non modifiable - const std::vector consult_tasks() const{ - return taches; - }; + const VecTaches consult_tasks() const { return taches; }; // Corrige les éventuelles anomalies du vector de tâches - const std::vector topologicalSort(); + const VecTaches topologicalSort(); }; #endif diff --git a/includes/ProtoProjet.hpp b/includes/ProtoProjet.hpp index 64ee0d0..e09e54a 100644 --- a/includes/ProtoProjet.hpp +++ b/includes/ProtoProjet.hpp @@ -3,26 +3,25 @@ #include #include + #include "Projet.hpp" class ProtoProjet : public Projet { - Tache debut; - Tache fin; + /* Tache taches; */ friend std::ostream &operator<<(std::ostream &, const ProtoProjet &); public: - ProtoProjet(std::vector taches, Tache debut, Tache fin); // constructor + ProtoProjet(); + ProtoProjet(VecTaches taches, Tache debut, + Tache fin); // constructor virtual ~ProtoProjet(); // destructor ProtoProjet(const ProtoProjet &); // copy constructor const ProtoProjet &operator=(const ProtoProjet &); // copy assignement // Remet tous les marquages à leur valeur initiale - std::vector cleanMarks(){ - for(bool t:this->getTaches()) - t=false; - }; - + void cleanMarks(); + // Insère une nouvelle tâche en la plaçant entre deux tâches au hasars bool ajoute(std::string nom, int duree); }; diff --git a/includes/Tache.hpp b/includes/Tache.hpp index 93f1fdb..e939a3f 100644 --- a/includes/Tache.hpp +++ b/includes/Tache.hpp @@ -4,6 +4,8 @@ #include #include +struct Projet; + class Tache { // Compteur global pour les IDs static int counter_id; @@ -23,6 +25,7 @@ class Tache { std::vector dependances; friend std::ostream &operator<<(std::ostream &, const Tache &); + friend Projet; // Auxilliaire pour simplifier les copies void _copy(const Tache &); diff --git a/src/Projet.cpp b/src/Projet.cpp index 53d9a33..72f6f05 100644 --- a/src/Projet.cpp +++ b/src/Projet.cpp @@ -1,9 +1,9 @@ #include "../includes/Projet.hpp" -Projet::Projet(std::vector taches){ taches=taches;} - Projet::Projet() {} +Projet::Projet(VecTaches t) : taches(t) {} + Projet::~Projet() {} Projet::Projet(const Projet &) {} @@ -16,33 +16,42 @@ const Projet &Projet::operator=(const Projet &src) { return *this; } -std::pair Projet::pick_two_random_tasks(){ +std::pair Projet::pick_two_random_tasks() { int size = this->taches.size(); int rand1 = rand() % size; int rand2 = rand() % size; - if(this->taches[rand1]->depends_from(*this->taches[rand2])) pick_two_random_tasks(); - //Heritage de tache ? - int id1 = this->taches[rand1]->unique_id; - int id2 = this->taches[rand2]->unique_id; + if (this->taches[rand1].first->depends_from(*this->taches[rand2].first)) + pick_two_random_tasks(); + + // Heritage de tache ? + int id1 = this->taches[rand1].first->unique_id; + int id2 = this->taches[rand2].first->unique_id; return std::make_pair(id1, id2); } -//Comment acceder à unique_id ici ? -Tache *Projet::contains(int id){ - for(Tache *t:this->taches) - if(id==t->unique_id) return t; +// Comment acceder à unique_id ici ? +Tache *Projet::contains(int id) { + for (auto t : this->taches) { + if (id == t.first->unique_id) { + return t.first; + } + } + return nullptr; } -//Comment acceder à taches ici ? -std::ostream& operator<<(std::ostream &out, Projet &x){ - for(Tache *t: x.taches) - out << *t; - return out; +// Comment acceder à taches ici ? +std::ostream &operator<<(std::ostream &out, const Projet &data) { + for (auto t : data.taches) { + out << t.first << " is " << std::boolalpha << t.second; + } + + return out; } -const std::vector topologicalSort(){ - //Recupere le calcul fait par PP_postfixe et construit son tri - //PP_postfixe(this->taches); -} +const Projet::VecTaches Projet::topologicalSort() { + // Recupere le calcul fait par PP_postfixe et construit son tri + // PP_postfixe(this->taches); + return VecTaches(); /* TODO */ +} diff --git a/src/ProtoProjet.cpp b/src/ProtoProjet.cpp index b4edcb5..819e3c8 100644 --- a/src/ProtoProjet.cpp +++ b/src/ProtoProjet.cpp @@ -1,15 +1,17 @@ #include "../includes/ProtoProjet.hpp" -ProtoProjet::ProtoProjet(std::vector taches, Tache debut, Tache fin) { - taches=taches; - taches.push_back(debut); - taches.push_back(fin); +ProtoProjet::ProtoProjet() {} + +ProtoProjet::ProtoProjet(VecTaches t, Tache debut, Tache fin) : Projet(t) { + /* taches.push_back(debut); + taches.push_back(fin); */ debut.ajouteDependance(fin); - } +} ProtoProjet::~ProtoProjet() {} -ProtoProjet::ProtoProjet(const ProtoProjet &) {} +ProtoProjet::ProtoProjet(const ProtoProjet &src) + : Projet(VecTaches() /* TODO*/) {} const ProtoProjet &ProtoProjet::operator=(const ProtoProjet &src) { if (this == &src) { @@ -19,6 +21,12 @@ const ProtoProjet &ProtoProjet::operator=(const ProtoProjet &src) { return *this; } -bool ajoute(std::string nom, int duree){ - +void ProtoProjet::cleanMarks() { + for (auto t : this->getTaches()) { + t.second = false; + } +}; + +bool ProtoProjet::ajoute(std::string nom, int duree) { + return false; /* TODO */ }