/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Bureaucrat.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 13:16:26 by fgras-ca #+# #+# */ /* Updated: 2024/02/11 14:50:15 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" #include "Form.hpp" Bureaucrat::Bureaucrat(const std::string &nom, int grade) : name(nom) { if (grade < 1) { throw GradeTooHighException(); } else if (grade > 150) { throw GradeTooLowException(); } this->grade = grade; } std::string Bureaucrat::getName() const { return (name); } int Bureaucrat::getGrade() const { return (grade); } void Bureaucrat::incrementGrade() { if (grade <= 1) { throw GradeTooHighException(); } --grade; } void Bureaucrat::decrementGrade() { if (grade >= 150) { throw GradeTooLowException(); } ++grade; } void Bureaucrat::signForm(Form& form) { try { form.beSigned(*this); std::cout << this->name << " signed " << form.getName() << std::endl; } catch (std::exception& e) { std::cout << this->name << " couldn’t sign " << form.getName() << " because " << e.what() << std::endl; } } std::ostream& operator<<(std::ostream &os, const Bureaucrat &bureaucrat) { os << bureaucrat.getName() << MAGENTA << ", bureaucrat grade " << RESET << bureaucrat.getGrade(); return (os); }