/* * Methode qui retire un abonne du vecteur avec sa matricule. * @param Un string matricule. * @return Aucun. */ void Bibliotheque::retirerAbonne(const string & matricule) { unsigned int z = 0; Abonne* abonne = trouverAbonne(matricule, z); if (abonne != nullptr) { if (abonne->obtenirNombreEmprunte() == 0) { vecAbonne_.erase(vecAbonne_.begin() + z); }else { for (unsigned int i = 0; i < abonne->obtenirNombreEmprunte(); i++) { bool trouver = false; unsigned int h = 0; while (!trouver && h < vecEmprunt_.size()) { if (*(vecEmprunt_[h]->obtenirLivre()) == *(abonne->obtenirEmprunt(i)->obtenirLivre())) { trouver = true; Livre* livre = vecEmprunt_[h]->obtenirLivre(); livre->modifierNbDisponibles(livre->obtenirNbDisponibles() + 1); vecEmprunt_.erase(vecEmprunt_.begin() + h); } else { h++; } } } } } }
bool Bibliotheque::emprunter(const string& matricule, const string& cote, const unsigned int dateRetour) { Abonne* abonne = trouverAbonne(matricule); ObjetEmpruntable* objetEmpruntable = trouverObjetEmpruntable(cote); if (objetEmpruntable != nullptr) { if (estEmpruntable(matricule, *objetEmpruntable)) { if (obtenirClasseObjet(cote) == "Livre") { bool estTrouveLivre = false; Livre* livre = nullptr; for (unsigned int i = 0; i < livres_.size() && !estTrouveLivre; i++) if (livres_[i]->obtenirCote() == cote) { livre = livres_[i]; estTrouveLivre = true; } Emprunt* emprunt = new Emprunt(livre, *abonne, dateRetour); emprunts_.push_back(emprunt); livre->modifierNbDisponibles(livre->obtenirNbDisponibles() - 1); abonne->ajouterEmprunt(emprunt); return true; } else if (obtenirClasseObjet(cote) == "Dvd") { bool estTrouveDvd = false; Dvd* dvd = nullptr; for (unsigned int i = 0; i < livres_.size() && !estTrouveDvd; i++) if (dvds_[i]->obtenirCote() == cote) { dvd = dvds_[i]; estTrouveDvd = true; } Emprunt* emprunt = new Emprunt(dvd, *abonne, dateRetour); emprunts_.push_back(emprunt); dvd->modifierNbDisponibles(dvd->obtenirNbDisponibles() - 1); abonne->ajouterEmprunt(emprunt); return true; } } } return false; }
bool Bibliotheque::retourner(const string & matricule, const string & cote) { bool retour = false; Abonne* abonne = trouverAbonne(matricule); Livre* livre = trouverLivre(cote); if (abonne->retirerEmprunt(*livre)) { livre->modifierNbDisponibles(livre->obtenirNbDisponibles() + 1); for (unsigned int i = 0; i < vecEmprunt_.size(); i++) { if (*(vecEmprunt_[i]->obtenirLivre()) == *livre) { vecEmprunt_.erase(vecEmprunt_.begin() + i); retour = true; i = vecEmprunt_.size(); } } } return retour; }
/* * Methode qui vérifie si l'emprunt peut se faire en verifiant tout les conditions. * @param Un string matricule, cote et un int date. * @return Un bool. */ bool Bibliotheque::emprunter(const string & matricule, const string & cote, const int & date) { bool retour = false; unsigned int iAbonne = 0; unsigned int iLivre = 0; Livre * livre = trouverLivre(cote); Abonne * abonne = trouverAbonne(matricule, iAbonne); if (estEmpruntable(*abonne, *livre)) { if (abonne->obtenirNombreEmprunte() < 2) { Emprunt* emprunt = new Emprunt(abonne->obtenirMatricule(), livre, date); livre->modifierNbDisponibles(livre->obtenirNbDisponibles() - 1); abonne->ajouterEmprunt(emprunt); vecEmprunt_.push_back(emprunt); retour = true; } } return retour; }