/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* Bureaucrat.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: aortigos grade = other.getGrade(); //std::cout << "Copy operator called" << std::endl; return (*this); } Bureaucrat::~Bureaucrat() { //std::cout << "Bureaucrat destroyed" << std::endl; } Bureaucrat::Bureaucrat(std::string name, int grade) : name(name) { if (grade > 150) throw GradeTooLowException(); else if (grade < 1) throw GradeTooHighException(); this->grade = grade; //std::cout << "Bureaucrat with params has been created" << std::endl; } ////////////////// // Getters // ////////////////// std::string Bureaucrat::getName() const { return (this->name); } int Bureaucrat::getGrade() const { return (this->grade); } ////////////////// // Grade // ////////////////// void Bureaucrat::incrementGrade() { if (this->grade <= 1) throw GradeTooHighException(); this->grade--; } void Bureaucrat::decrementGrade() { if (this->grade >= 150) throw GradeTooLowException(); this->grade++; } ////////////////// // Sign // ////////////////// void Bureaucrat::signForm(AForm &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; } } void Bureaucrat::executeForm(AForm &form) { try { form.execute(*this); std::cout << this->name << " executed " << form.getName() << std::endl; } catch (std::exception &e) { std::cout << this->name << " couldn't execute " << form.getName() << " because " << e.what() << std::endl; } } ////////////////// // << // ////////////////// std::ostream &operator<<(std::ostream &os, const Bureaucrat &bureaucrat) { os << bureaucrat.getName() << ", bureaucrat grade " << bureaucrat.getGrade() << std::endl; return (os); } ////////////////// // Excepciones // ////////////////// const char* Bureaucrat::GradeTooHighException::what() const throw() { return ("Grade is too high!"); } const char* Bureaucrat::GradeTooLowException::what() const throw() { return ("Grade is too low!"); }