1
0

🔨」 fix: fixed Form class from ex01

This commit is contained in:
2025-04-01 11:09:10 +02:00
parent d56e8011de
commit 9e85ca79d9
16 changed files with 204 additions and 74 deletions

View File

@ -1,50 +1,89 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* Form.cpp :+: :+: :+: */
/* AForm.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 */
/* Updated: 2025/04/01 11:06:48 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "Form.hpp"
#include "AForm.hpp"
#include "Bureaucrat.hpp"
Form::Form(void) : _name(""), _signed(false), _minForSign(1), _minForExec(1) {
_log("", "Form", "", "default constructor called");
AForm::AForm(void) : _name(""), _signed(false), _minForSign(1), _minForExec(1) {
_log("", "AForm", "", "default constructor called");
}
Form::Form(std::string name, uint8_t minForSign, uint8_t minForExec)
AForm::AForm(std::string name, uint8_t minForSign, uint8_t minForExec)
: _name(name), _signed(false), _minForSign(minForSign),
_minForExec(minForExec) {
_log("", "Form", "", "default constructor called");
_log("", "AForm", "", "constructor called");
_gradeCheck();
}
Form::~Form(void) { _log("", "Form", "", "destructor called"); }
AForm::AForm(const AForm &f)
: _name(f.getName()), _signed(f.getSigned()),
_minForExec(f.getMinForExec()), _minForSign(f.getMinForSign()) {
_log("", "AForm", "", "copy constructor called");
_gradeCheck();
}
const char *Form::GradeTooHighException::what() const throw() {
AForm::~AForm(void) { _log("", "AForm", "", "destructor called"); }
AForm &AForm::operator=(const AForm &f) {
if (this == &f)
return *this;
_name = f.getName();
_signed = f.getSigned();
return *this;
}
const char *AForm::GradeTooHighException::what() const throw() {
return ("grade is too high");
}
const char *Form::GradeTooLowException::what() const throw() {
const char *AForm::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; }
const char *AForm::NotSigned::what() const throw() {
return ("not yet signed");
}
void Form::beSigned(Bureaucrat b) {
std::string AForm::getName(void) const { return _name; }
bool AForm::getSigned(void) const { return _signed; }
uint8_t AForm::getMinForSign(void) const { return _minForSign; }
uint8_t AForm::getMinForExec(void) const { return _minForExec; }
void AForm::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;
void AForm::execute(const Bureaucrat &b) const {
if (_signed == false) {
throw NotSigned();
}
if (b.getGrade() > _minForExec) {
throw GradeTooLowException();
}
_exec(b);
}
void AForm::_gradeCheck(void) const {
if (_minForExec < MAXGRADE || _minForSign < MAXGRADE)
throw GradeTooHighException();
if (_minForExec > MINGRADE || _minForExec > MINGRADE)
throw GradeTooLowException();
}
std::ostream &operator<<(std::ostream &os, AForm &val) {
os << "AForm: " << val.getName()
<< ", minGrade to sign: " << val.getMinForSign()
<< ", min grade to execute: " << val.getMinForExec() << std::endl;
return (os);
}