#include "AForm.hpp" #include "Bureaucrat.hpp" AForm::AForm() : _name("Default"), _signed(false), _grade_ex(150), _grade_si(150) { } AForm::AForm(const std::string name, const int grade_si, const int grade_ex) : _name(name), _signed(false), _grade_ex(grade_ex), _grade_si(grade_si) { } AForm::AForm(const AForm &other) : _name(other._name), _signed(other._signed), _grade_ex(other._grade_ex), _grade_si(other._grade_si) { } AForm::~AForm() { } std::string AForm::getName() const { return (_name); } bool AForm::getSigned() const { return (_signed); } int AForm::getExecuteGrade() const { return (_grade_ex); } int AForm::getSignGrade() const { return (_grade_si); } void AForm::beSigned(const Bureaucrat &bureaucrat) { if (bureaucrat.getGrade() <= _grade_si) _signed = true; else throw GradeTooLowException(); } AForm &AForm::operator=(const AForm &other) { _signed = other._signed; return (*this); } const char *AForm::GradeTooHighException::what() const throw() { return ("Grade too high!"); } const char *AForm::GradeTooLowException::what() const throw() { return ("Grade too low!"); } std::ostream &operator<<(std::ostream &os, AForm const &AForm) { os << "Name: " << AForm.getName() << " Signed: " << AForm.getSigned() << " SiGrade: " << AForm.getSignGrade() << " ExGrade: " << AForm.getExecuteGrade() << std::endl; return (os); } void AForm::setIsSigned(bool i_signed) { _signed = i_signed; } void AForm::execute(const Bureaucrat &executor) const { if (_signed == false) throw IsNotSignedException(); if (_grade_ex < executor.getGrade()) throw GradeTooLowException(); performAction(); } const char *AForm::IsNotSignedException::what() const throw() { return ("The form cannot be executed because it is not signed!"); }