#include "Bureaucrat.hpp" #include #include #include Bureaucrat::Bureaucrat() { std::cout << "Bureaucrat()" << std::endl; } Bureaucrat::Bureaucrat(const Bureaucrat& src) { *this = src; std::cout << "Bureaucrat(Bureaucrat)" << std::endl; } Bureaucrat::Bureaucrat(const std::string& name, int grade): _name(name) { setGrade(grade); std::cout << "Bureaucrat(" << name << ", " << grade << ")" << std::endl; } Bureaucrat::~Bureaucrat() { std::cout << "~Bureaucrat()" << std::endl; } Bureaucrat& Bureaucrat::operator=(const Bureaucrat &src) { this->_grade = src._grade; return *this; } void Bureaucrat::setGrade(int new_grade) { if (new_grade > 150) throw Bureaucrat::GradeTooLowException(); if (new_grade < 1) throw Bureaucrat::GradeTooHighException(); this->_grade = new_grade; } const std::string& Bureaucrat::getName(void) const { return this->_name; } int Bureaucrat::getGrade(void) const { return this->_grade; } void Bureaucrat::increment() { if (this->_grade == 1) throw GradeTooHighException(); this->_grade--; } void Bureaucrat::decrement() { if (this->_grade == 150) throw GradeTooLowException(); this->_grade++; } const char* Bureaucrat::GradeTooLowException::what() const throw() { return "Too low grade"; } const char* Bureaucrat::GradeTooHighException::what() const throw() { return "Too high grade"; } std::ostream& operator<<(std::ostream &stream, Bureaucrat &src) { stream << src.getName() << ", bureaucrat grade " << src.getGrade() << "." << std::endl; return stream; }