You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.7 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Form.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/26 16:12:05 by narnaud #+# #+# */
/* Updated: 2022/06/27 14:56:54 by narnaud ### ########.fr */
/* */
/* ************************************************************************** */
#include "Form.hpp"
/* Defaults */
2 years ago
Form &Form::operator=(Form const &f) {
(void)f;
return (*this);
3 years ago
}
Form::Form(Form const &f)
2 years ago
: _name(f.getName()), _signGrade(f.getSignGrade()),
_exeGrade(f.getExeGrade()) {
(void)f;
3 years ago
}
2 years ago
Form::~Form(void) {}
3 years ago
/* Custom constructor */
2 years ago
Form::Form(const string name, const int signGrade, const int exeGrade,
const string target) throw(Form::GradeTooHighException,
Form::GradeTooLowException)
: _name(name), _signGrade(signGrade), _exeGrade(exeGrade), _target(target) {
if (signGrade < 1 || exeGrade < 1)
throw Form::GradeTooHighException();
if (signGrade > 150 || exeGrade > 150)
throw Form::GradeTooLowException();
_isSigned = 0;
3 years ago
}
/* Getters */
2 years ago
const string Form::getName(void) const { return (_name); }
3 years ago
2 years ago
int Form::getSignGrade(void) const { return (_signGrade); }
3 years ago
2 years ago
int Form::getExeGrade(void) const { return (_exeGrade); }
3 years ago
2 years ago
/* Setters */
3 years ago
2 years ago
int Form::beSigned(const Bureaucrat &signer) throw(Form::GradeTooLowException) {
if (_isSigned)
return (-1);
if (signer.getGrade() > _signGrade)
throw GradeTooLowException();
_isSigned = 1;
return (0);
3 years ago
}
2 years ago
int Form::execute(Bureaucrat const &executor) const
throw(GradeTooLowException) {
if (executor.getGrade() > _exeGrade)
throw Form::GradeTooLowException();
if (!_isSigned)
return (-1);
this->run();
return (0);
3 years ago
}
/* Except */
2 years ago
const char *Form::GradeTooHighException::what(void) const throw() {
return ("grade is too high for a form");
3 years ago
}
2 years ago
const char *Form::GradeTooLowException::what(void) const throw() {
return ("grade is too low for a form");
3 years ago
}
2 years ago
std::ostream &operator<<(std::ostream &out, const Form &f) {
out << f.getName() << "(s:" << f.getSignGrade() << "|e:" << f.getExeGrade()
<< ")";
return (out);
};