| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* AForm.cpp :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2025/12/29 16:42:01 by bchanot #+# #+# */
- /* Updated: 2025/12/31 16:01:36 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 )
- {
- i.print(o);
- return o;
- }
- void AForm::print(std::ostream & o) const {
- o << "AForm name : " << this->getName() << ", Minimum grade for sign : " << (int)this->getSignGrade() << ", Minimum exection grade : " << (int)this->getExecutionGrade() << ", Is signed : " << this->getSigned() << ", target : " << this->getTarget();
- }
- /*
- ** --------------------------------- 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;
- }
- std::string const AForm::getTarget(void) const {
- return this->_target;
- }
- 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;
- }
- /* ************************************************************************** */
|