「🎉」 init: hello world !
This commit is contained in:
94
ex03/AForm.cpp
Normal file
94
ex03/AForm.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* AForm.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/06/27 13:49:35 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/08/02 13:15:48 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "AForm.hpp"
|
||||
#include "Bureaucrat.hpp"
|
||||
|
||||
void AForm::execute(const Bureaucrat &b) const {
|
||||
if (_signed == false) {
|
||||
throw NotSigned();
|
||||
}
|
||||
if (b.getGrade() > _minForExec) {
|
||||
throw GradeTooLowException();
|
||||
}
|
||||
std::cout << b.getName() << " executed " << this->getName() << std::endl;
|
||||
_exec(b);
|
||||
}
|
||||
|
||||
|
||||
AForm::AForm(void)
|
||||
: _name("Form"), _signed(false), _minForSign(1), _minForExec(1)
|
||||
{
|
||||
_log("➕", "AForm", "", "default constructor called");
|
||||
}
|
||||
|
||||
AForm::AForm(std::string name, uint8_t minForSign, uint8_t minForExec)
|
||||
: _name(name), _signed(false), _minForSign(minForSign), _minForExec(minForExec)
|
||||
{
|
||||
_log("➕", "AForm", "", "constructor called");
|
||||
_gradeCheck();
|
||||
}
|
||||
|
||||
AForm::AForm(const AForm &f)
|
||||
: _name(f.getName()), _signed(f.getSigned()), _minForSign(f.getMinForSign()), _minForExec(f.getMinForExec())
|
||||
{
|
||||
_log("➕", "Form", "", "copy constructor called");
|
||||
_gradeCheck();
|
||||
}
|
||||
|
||||
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 *AForm::GradeTooLowException::what() const throw() {
|
||||
return ("grade is too low");
|
||||
}
|
||||
|
||||
const char *AForm::NotSigned::what() const throw() {
|
||||
return "Form exception: Form not signed";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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 << "Form: " << val.getName()
|
||||
<< ", minGrade to sign: " << int(val.getMinForSign())
|
||||
<< ", minGrade to execute: " << int(val.getMinForExec());
|
||||
return (os);
|
||||
}
|
||||
Reference in New Issue
Block a user