/* * 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++; } } } } } }
/* * Methode qui vérifie s’il est possible que l'abonne emprunte un livre. * @param Un Abonne et un Livre. * @return Un bool. */ bool Bibliotheque::estEmpruntable(const Abonne & abonne, const Livre & livre) const { unsigned int k; bool retour = ( (livre.obtenirNbDisponibles() >= 1) && (abonne.obtenirAge() >= livre.obtenirAgeMinimal()) && (!(abonne.estEmprunte(livre, k)))); return retour; }
bool Bibliotheque::estEmpruntable(const string& matricule, const ObjetEmpruntable& objetEmpruntable) const { Abonne* abonne = trouverAbonne(matricule); bool estEmprunte = false; for (unsigned int i = 0; i < emprunts_.size() && !estEmprunte; i++) if (emprunts_[i]->obtenirMatricule() == matricule && emprunts_[i]->obtenirObjetEmpruntable()->obtenirCote() == objetEmpruntable.obtenirCote()) estEmprunte = true; return objetEmpruntable.obtenirNbDisponibles() > 0 && objetEmpruntable.obtenirAgeMinimal() < abonne->obtenirAge() && !estEmprunte && abonne->obtenirNombreEmprunte() < abonne->obtenirEmpruntsLimite(); }
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::ajouterAbonne(Abonne& abonne) { if (trouverAbonne(abonne.obtenirMatricule())== nullptr) { abonnes_.push_back(&abonne); 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; }
bool Bibliotheque::retourner(const string& matricule, const string& cote) { bool estEmprunte = false; unsigned int position = 0; for (unsigned int i = 0; i < emprunts_.size() && !estEmprunte; i++) if (emprunts_[i]->obtenirMatricule() == matricule && emprunts_[i]->obtenirObjetEmpruntable()->obtenirCote() == cote) { estEmprunte = true; position = i; } if (estEmprunte) { Abonne* abonne = trouverAbonne(matricule); ObjetEmpruntable* objetEmpruntable = trouverObjetEmpruntable(cote); abonne->retirerEmprunt(*objetEmpruntable); delete emprunts_[position]; emprunts_[position] = emprunts_[emprunts_.size() - 1]; emprunts_.pop_back(); objetEmpruntable->modifierNbDisponibles(objetEmpruntable->obtenirNbDisponibles() + 1); return true; } return false; }
void Bibliotheque::ajouterAbonne(Abonne& abonne) { if (trouverAbonne(abonne.obtenirMatricule()) == nullptr) vecAbonne_.push_back(&abonne); }
Emprunt::Emprunt(Livre* livre, Abonne& abonne, const unsigned int& dateRetour) : matricule_(abonne.obtenirMatricule()), livre_(livre), dvd_(nullptr), dateRetour_(dateRetour) { }