From fde958a25942726b58a38bd7610b67c360833ccb Mon Sep 17 00:00:00 2001 From: jopierron Date: Fri, 1 Apr 2022 08:05:43 +0000 Subject: [PATCH] Upload New File --- src/Contact.cpp | 114 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/Contact.cpp diff --git a/src/Contact.cpp b/src/Contact.cpp new file mode 100644 index 0000000..0b08dba --- /dev/null +++ b/src/Contact.cpp @@ -0,0 +1,114 @@ +#include +#include "Contact.hpp" +#include +#include + +using namespace std; +using namespace reseau; + +Contact::Contact(const Personne& Proprietaire): Proprietaire{Proprietaire} { + // cout << "Contact créé " << Proprietaire << "\n"; +} + +const Personne& Contact::getProprio() const { + return this->Proprietaire; +} + +bool Contact::ajouterContact(const Personne& unContact){ + if(lesContacts.empty()){ + // cout << "Contact ajouté " << unContact <<"\n"; + lesContacts.push_back(&unContact); + return true; + } + if(unContact==Proprietaire) + { + cout << "Erreur : Contact déjà existant (Proprietaire)\n"; + return false; + } + list::iterator it = find(lesContacts.begin(), lesContacts.end(), &unContact); + if(it!=lesContacts.end()){ + cout << "Erreur : Personne déjà dans vos contacts : " << unContact << "\n"; + return false; + } + else { + // cout << "Contact ajouté " << unContact <<"\n"; + lesContacts.push_back(&unContact); + return true; + } + return true; +} + +bool Contact::rechercher(const Personne& unContact){ + list::iterator it = find(lesContacts.begin(), lesContacts.end(),&unContact); + if(it != lesContacts.end()) + { + cout << "trouvé : " << unContact << "\n"; + return true; + } + else + { + cout << "pas trouvé\n"; + return false; + } + lesContacts.sort(); +} + +bool Contact::supprimerContact(const Personne& unContact){ + list::iterator it = find(lesContacts.begin(), lesContacts.end(), &unContact); + if(it!=lesContacts.end()){ + lesContacts.erase(it); + cout << "Contact " << unContact << " supprimé\n"; + return true; + } + else { + cout << "Erreur : le contact n'existe pas\n"; + return false; + } +} + +void Contact::afficherContactDirect() { + cout << " Les contacts directs de " << this->Proprietaire << " sont : "; + for(list::const_iterator it = lesContacts.cbegin(); it != lesContacts.cend(); ++it){ + if(it==lesContacts.cbegin()) + cout << **it; + else + cout << ", " << **it; + } + if(lesContacts.empty()) + cout << "Aucun contact "; + cout << "\n"; +} + +void Contact::Recursive(list Contacts, set* set) { + for(const Personne* Personne : lesContacts) { + if(set->find(Personne)!=set->end()) + continue; + set->insert(Personne); + for(Contact* contact : Contacts) { + if(*Personne == contact->getProprio()) { + contact->Recursive(Contacts,set); + } + } + } +} + +void Contact::afficherContactIndirect(list Contacts) { + cout << " Les contacts directs et indirects de " << this->Proprietaire << " sont : "; + set lesPersonnes{}; + Recursive(Contacts,&lesPersonnes); + if(lesPersonnes.empty()) + cout << "Aucun contact "; + for(const Personne* Personne : lesPersonnes) + cout << *Personne << " "; + cout << "\n"; +} + +ostream& reseau::operator<<(ostream& os, Personne p){ + return os << p.getPrenom(); +} + +bool reseau::operator==(reseau::Personne p1, reseau::Personne p2){ + if(p1.getPrenom()==p2.getPrenom()) + return true; + return false; +}