1
0
Files
CPP_Module_05/ex02/AForm.cpp
2025-03-30 18:07:11 +02:00

51 lines
2.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Form.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/03/09 17:38:19 by adjoly #+# #+# */
/* Updated: 2025/03/30 15:14:17 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "Form.hpp"
#include "Bureaucrat.hpp"
Form::Form(void) : _name(""), _signed(false), _minForSign(1), _minForExec(1) {
_log("", "Form", "", "default constructor called");
}
Form::Form(std::string name, uint8_t minForSign, uint8_t minForExec)
: _name(name), _signed(false), _minForSign(minForSign),
_minForExec(minForExec) {
_log("", "Form", "", "default constructor called");
}
Form::~Form(void) { _log("", "Form", "", "destructor called"); }
const char *Form::GradeTooHighException::what() const throw() {
return ("grade is too high");
}
const char *Form::GradeTooLowException::what() const throw() {
return ("grade is too low");
}
std::string Form::getName(void) const { return _name; }
bool Form::getSigned(void) const { return _signed; }
uint8_t Form::getMinForSign(void) const { return _minForSign; }
uint8_t Form::getMinForExec(void) const { return _minForExec; }
void Form::beSigned(Bureaucrat b) {
if (_minForSign > b.getGrade()) {
throw GradeTooLowException();
}
_signed = true;
}
std::ostream &operator<<(std::ostream &os, Form &val) {
os << "Form: " << val.getName() << ", minGrade to sign: " << val.getMinForSign() << ", min grade to execute: " << val.getMinForExec() << std::endl;
return (os);
}