/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* AForm.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: bchanot +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/12/29 16:42:01 by bchanot #+# #+# */ /* Updated: 2025/12/30 18:29:19 by bchanot ### ########.fr */ /* */ /* ************************************************************************** */ #include "AForm.hpp" #include "Bureaucrat.hpp" /* ** ------------------------------- CONSTRUCTOR -------------------------------- */ AForm::AForm() : _target("DefautTarget"), _name("DefaultAFormName"), _signGrade(1), _executeGrade(1), _signed(false) { } AForm::AForm( const std::string name, uint8_t execGrade, uint8_t signGrade, std::string target) : _target(target), _name(name), _signGrade(signGrade), _executeGrade(execGrade), _signed(false) { if (this->_executeGrade > 150 || this->_signGrade > 150) throw Bureaucrat::GradeTooHighException(); else if (this->_executeGrade < 1 || this->_signGrade < 1) throw Bureaucrat::GradeTooLowException(); } AForm::AForm( const AForm & src ) : _target(src._target), _name(src._name), _signGrade(src._signGrade), _executeGrade(src._executeGrade), _signed(false) { if (this->_executeGrade > 150 || this->_signGrade > 150) throw Bureaucrat::GradeTooHighException(); else if (this->_executeGrade < 1 || this->_signGrade < 1) throw Bureaucrat::GradeTooLowException(); } /* ** -------------------------------- DESTRUCTOR -------------------------------- */ AForm::~AForm() { } /* ** --------------------------------- OVERLOAD --------------------------------- */ AForm & AForm::operator=( AForm const & rhs ) { (void)rhs; //if ( this != &rhs ) //{ //this->_value = rhs.getValue(); //} return *this; } std::ostream & operator<<( std::ostream & o, AForm const & i ) { o << "AForm name : " << i.getName() << ", Minimum grade for sign : " << (int)i.getSignGrade() << ", Minimum exection grade : " << (int)i.getExecutionGrade() << ", Is signed : " << i.getSigned(); return o; } /* ** --------------------------------- METHODS ---------------------------------- */ void AForm::beSigned(const Bureaucrat &sch) { if (sch.getGrade() <= this->_signGrade) this->_signed = true; else throw AForm::GradeTooLowException(); } void AForm::execute(Bureaucrat const & executor) const { if (this->_signed && executor.getGrade() <= this->_signGrade && executor.getGrade() <= this->_executeGrade) this->action(); else throw AForm::GradeTooLowException(); } /* ** --------------------------------- ACCESSOR --------------------------------- */ std::string const AForm::getName(void) const { return this->_name; } uint8_t AForm::getSignGrade(void) const { return this->_signGrade; } uint8_t AForm::getExecutionGrade(void) const { return this->_executeGrade; } bool AForm::getSigned(void) const { return this->_signed; } /* ************************************************************************** */