You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9 KiB

#include "livreRecettes.hpp"
#include "recetteAffichage.hpp"
#include "ingredient.hpp"
#include <map>
#include <algorithm>
using namespace std;
namespace appli {
map<Recette, unordered_set<Ingredient>> LivreRecettes::rechercherRecette(const string &nomRecette) {
map<Recette, unordered_set<Ingredient>> rech;
for(auto it = livre.cbegin(); it != livre.cend(); ++it) {
if(it->first.getNom() == nomRecette) {
rech.insert({it->first, it->second});
}
}
return rech;
}
map<string, Quantite> LivreRecettes::faireListeCourses(list<Recette> l) {
string nomRecette;
int rep;
cout << "Quelle recette voulez vous ? " << endl;
cin >> nomRecette;
map<Recette, unordered_set<Ingredient>>::iterator it = livre.find(nomRecette);
// it = this->rechercherRecette(nomRecette);
for(const Ingredient &ing : it->second) {
cout << "avez vous du, des " << ing << " ? (0 : non/1 : oui)" << endl;
cin >> rep;
if(rep == 0) {
l.push_back(ing);
}
}
}
void LivreRecettes::ajouter(const Recette &r, list<Ingredient> l) {
unordered_set<Ingredient> ing;
if(livre.find(r) != livre.end()) {
cout << "recette déjà présente" << endl;
return;
}
for(Ingredient i : l) {
unordered_set<Ingredient>::iterator it2 = ing.find(i);
if(it2 == ing.end()) {
ing.insert(i);
}
else {
Quantite q = i.getQuantite() + it2->getQuantite();
ing.erase(it2);
ing.insert(Ingredient{i.getAliment(), q});
}
}
livre.insert({r, ing});
}
void LivreRecettes::afficherNomRecette() {
afficherNoms(livre);
}
void LivreRecettes::afficher() {
afficherTout(livre);
}
}