cpp/CPP05/ex03/AForm.cpp
2024-12-04 17:29:31 +01:00

74 lines
1.6 KiB
C++

#include "AForm.hpp"
AForm::AForm() : name(""), sign(false), grade(150), gradeExec(150) {
}
AForm::AForm(std::string name, int grade, int gradeExec)
: name(name), sign(false), grade(grade), gradeExec(gradeExec) {
if (grade > 150 || gradeExec > 151)
throw AForm::GradeTooLowException();
if (grade < 1 || gradeExec < 1)
throw AForm::GradeTooHighException();
}
AForm::~AForm() {
}
AForm::AForm(const AForm &form) : name(form.name), grade(form.grade), gradeExec(form.gradeExec) {
*this = form;
}
AForm &AForm::operator=(const AForm &form) {
if (this != &form) {
this->sign = form.sign;
}
return *this;
}
std::string AForm::getName() const {
return this->name;
}
std::string AForm::getTarget() const {
return this->target;
}
bool AForm::isSigned() const {
return this->sign;
}
int AForm::getGrade() const {
return this->grade;
}
int AForm::getGradeExec() const {
return this->gradeExec;
}
void AForm::beSigned(Bureaucrat &crat) {
if (crat.getGrade() > this->grade)
throw AForm::GradeTooLowException();
this->sign = true;
}
void AForm::execute(Bureaucrat &crat) {
if (crat.getGrade() > this->gradeExec)
throw AForm::GradeTooLowException();
this->target = crat.getName();
executeAction();
}
std::ostream& operator<<( std::ostream& os, AForm const& form ) {
return os << "name:" << form.getName() << " sign:" << form.isSigned()
<< " grade:" << form.getGrade() << " gradeExec:" << form.getGradeExec() << std::endl;
}
char const* AForm::GradeTooHighException::what() const throw() {
return "Grade is too high";
}
char const* AForm::GradeTooLowException::what() const throw() {
return "Grade is too low";
}