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.
80 lines
2.4 KiB
80 lines
2.4 KiB
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* Form.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2022/06/26 16:12:05 by narnaud #+# #+# */
|
|
/* Updated: 2022/06/27 09:40:11 by narnaud ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "Form.hpp"
|
|
|
|
/* Constructors */
|
|
|
|
Form::Form(void) {}
|
|
|
|
Form::Form(const string name, int signGrade,
|
|
int exeGrade) throw(Form::GradeTooHighException,
|
|
Form::GradeTooLowException)
|
|
: _name(name) {
|
|
if (signGrade < 1 || exeGrade < 1)
|
|
throw Form::GradeTooHighException();
|
|
if (signGrade > 150 || exeGrade > 150)
|
|
throw Form::GradeTooLowException();
|
|
_signGrade = signGrade;
|
|
_exeGrade = exeGrade;
|
|
_isSigned = 0;
|
|
}
|
|
|
|
/* copy const. */
|
|
Form::Form(Form const &f) { (void)f; }
|
|
|
|
/* assign const. */
|
|
Form &Form::operator=(Form const &f) {
|
|
(void)f;
|
|
return (*this);
|
|
}
|
|
|
|
/* Destructor */
|
|
Form::~Form(void) {}
|
|
|
|
/* Getters */
|
|
|
|
const string Form::getName(void) const { return (_name); }
|
|
|
|
int Form::getSignGrade(void) const { return (_signGrade); }
|
|
|
|
int Form::getExeGrade(void) const { return (_exeGrade); }
|
|
|
|
/* Setters */
|
|
|
|
bool Form::beSigned(const Bureaucrat &b) throw(Form::GradeTooLowException) {
|
|
if (_isSigned)
|
|
return (1);
|
|
if (b.getGrade() > _signGrade)
|
|
throw GradeTooLowException();
|
|
_isSigned = 1;
|
|
return (0);
|
|
}
|
|
|
|
/* Except */
|
|
|
|
const char *Form::GradeTooHighException::what(void) const throw() {
|
|
return ("error: grade is too high for a form");
|
|
}
|
|
|
|
const char *Form::GradeTooLowException::what(void) const throw() {
|
|
return ("error: grade is too low for a form");
|
|
}
|
|
|
|
/* Stream */
|
|
std::ostream &operator<<(std::ostream &out, const Form &f) {
|
|
out << f.getName()
|
|
<< "(s:" << f.getSignGrade()
|
|
<< "|e:" << f.getExeGrade()
|
|
<< ")";
|
|
return (out);
|
|
};
|
|
|