75 lines
1.7 KiB
C++
75 lines
1.7 KiB
C++
#include "AForm.hpp"
|
|
|
|
AForm::AForm() : name(""), sign(false), grade(150), gradeExec(150) {
|
|
}
|
|
|
|
AForm::AForm(std::string name, std::string target, int grade, int gradeExec)
|
|
: name(name), target(target), 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;
|
|
this->target = form.target;
|
|
}
|
|
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(const Bureaucrat &crat) const {
|
|
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";
|
|
}
|