「🎉」 init: hello world !
This commit is contained in:
78
ex01/Form.cpp
Normal file
78
ex01/Form.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Form.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/06/27 13:49:35 by mmoussou #+# #+# */
|
||||
/* Updated: 2025/06/27 15:12:49 by mmoussou ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Form.hpp"
|
||||
#include "Bureaucrat.hpp"
|
||||
|
||||
Form::Form(void)
|
||||
: _name("Form"), _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", "", "constructor called");
|
||||
_gradeCheck();
|
||||
}
|
||||
|
||||
Form::Form(const Form &f)
|
||||
: _name(f.getName()), _signed(f.getSigned()), _minForSign(f.getMinForSign()), _minForExec(f.getMinForExec())
|
||||
{
|
||||
_log("➕", "Form", "", "copy constructor called");
|
||||
_gradeCheck();
|
||||
}
|
||||
|
||||
Form::~Form(void) { _log("➖", "Form", "", "destructor called"); }
|
||||
|
||||
Form &Form::operator=(const Form &f) {
|
||||
if (this == &f)
|
||||
return *this;
|
||||
_name = f.getName();
|
||||
_signed = f.getSigned();
|
||||
return *this;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void Form::_gradeCheck(void) const {
|
||||
if (_minForExec < MAXGRADE || _minForSign < MAXGRADE)
|
||||
throw GradeTooHighException();
|
||||
if (_minForExec > MINGRADE || _minForExec > MINGRADE)
|
||||
throw GradeTooLowException();
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, Form &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