88 lines
1.5 KiB
C++
88 lines
1.5 KiB
C++
#include "Form.hpp"
|
|
#include "Bureaucrat.hpp"
|
|
|
|
Bureaucrat::Bureaucrat() : _name("default"), _grade(150)
|
|
{
|
|
}
|
|
|
|
Bureaucrat::Bureaucrat(const Bureaucrat ©) : _name(copy._name), _grade(copy._grade)
|
|
{
|
|
}
|
|
|
|
Bureaucrat::Bureaucrat(const std::string name, int grade) : _name(name)
|
|
{
|
|
if (grade < 1)
|
|
throw GradeTooHighException();
|
|
else if (grade > 150)
|
|
throw GradeTooLowException();
|
|
else
|
|
_grade = grade;
|
|
}
|
|
|
|
Bureaucrat &Bureaucrat::operator=(const Bureaucrat &other)
|
|
{
|
|
if (this != &other)
|
|
_grade = other._grade;
|
|
return (*this);
|
|
}
|
|
|
|
Bureaucrat::~Bureaucrat()
|
|
{
|
|
}
|
|
|
|
std::string Bureaucrat::getName() const
|
|
{
|
|
return (_name);
|
|
}
|
|
|
|
int Bureaucrat::getGrade() const
|
|
{
|
|
return (_grade);
|
|
}
|
|
|
|
void Bureaucrat::incrementGrade()
|
|
{
|
|
if (_grade == 1)
|
|
throw GradeTooHighException();
|
|
else
|
|
_grade--;
|
|
}
|
|
|
|
void Bureaucrat::decrementGrade()
|
|
{
|
|
if (_grade == 150)
|
|
throw GradeTooLowException();
|
|
else
|
|
_grade++;
|
|
}
|
|
|
|
std::ostream &operator<<(std::ostream &os, Bureaucrat const &other)
|
|
{
|
|
os << other.getName() << ", bureaucrat grade " << other.getGrade() << std::endl;
|
|
return (os);
|
|
}
|
|
|
|
const char *Bureaucrat::GradeTooHighException::what() const throw()
|
|
{
|
|
return ("Grade too high!");
|
|
}
|
|
|
|
const char *Bureaucrat::GradeTooLowException::what() const throw()
|
|
{
|
|
return ("Grade too low!");
|
|
}
|
|
|
|
void Bureaucrat::signForm(Form &form)
|
|
{
|
|
try
|
|
{
|
|
form.beSigned(*this);
|
|
}
|
|
catch(const std::exception& e)
|
|
{
|
|
std::cout << _name << " couldn't sign " << form.getName() << " because " << e.what() << std::endl;
|
|
return;
|
|
}
|
|
std::cout << _name << " signed " << form.getName() << std::endl;
|
|
}
|