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.

83 lines
2.4 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Form.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/26 16:12:05 by narnaud #+# #+# */
3 years ago
/* Updated: 2022/06/27 09:40:11 by narnaud ### ########.fr */
3 years ago
/* */
/* ************************************************************************** */
#include "Form.hpp"
3 years ago
std::ostream &operator<< (std::ostream &out, const Form &f) {
out << "Form: " << f.getName() << " - Required grade to sign: " << f.getSignGrade() << " - Required grade to execute: " << f.getExeGrade() << endl;
return (out);
};
/* Defaults */
Form & Form::operator=(Form const &f) {
(void)f;
cout << "Form assignement called" << endl;
return (*this);
}
Form::Form(Form const &f) {
(void)f;
cout << "Form copy called" << endl;
}
Form::~Form(void) {
cout << "Form desctructor called" << endl;
}
/* Custom constructor */
Form::Form(const string name, int signGrade, int exeGrade)
3 years ago
throw (Form::GradeTooHighException, Form::GradeTooLowException): _name(name){
if (signGrade < 1 || exeGrade < 1)
3 years ago
throw Form::GradeTooHighException();
3 years ago
if (signGrade > 150 || exeGrade > 150)
3 years ago
throw Form::GradeTooLowException();
3 years ago
_signGrade = signGrade;
_exeGrade = exeGrade;
}
3 years ago
/* Getters */
3 years ago
const string Form::getName(void) const {
return (_name);
}
3 years ago
int Form::getSignGrade(void) const {
3 years ago
return (_signGrade);
}
3 years ago
int Form::getExeGrade(void) const {
3 years ago
return (_exeGrade);
}
3 years ago
/* Seter */
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 ("Grade was too high for a form");
}
3 years ago
3 years ago
const char *Form::GradeTooLowException::what(void) const throw (){
return ("Grade was too low for a form");
}