cpp/CPP05/ex01/Form.cpp
2024-12-04 17:29:31 +01:00

62 lines
1.4 KiB
C++

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