「🔨」 fix: fixed Form class from ex01
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/23 13:59:45 by adjoly #+# #+# */
|
||||
/* Updated: 2025/03/30 15:13:43 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/01 10:49:43 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -42,8 +42,8 @@ Bureaucrat::Bureaucrat(std::string name, uint8_t grade)
|
||||
_log("➕", "Bureaucrat", "", "constructor called");
|
||||
}
|
||||
|
||||
const std::string &Bureaucrat::getName(void) { return _name; }
|
||||
uint8_t Bureaucrat::getGrade(void) { return _grade; }
|
||||
const std::string &Bureaucrat::getName(void) const { return _name; }
|
||||
uint8_t Bureaucrat::getGrade(void) const { return _grade; }
|
||||
|
||||
Bureaucrat::~Bureaucrat(void) {
|
||||
_log("➖", "Bureaucrat", "", "destructor called");
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/12/23 13:59:43 by adjoly #+# #+# */
|
||||
/* Updated: 2025/03/30 15:10:46 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/01 10:50:00 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -35,8 +35,8 @@ class Bureaucrat {
|
||||
Bureaucrat(std::string name, uint8_t grade);
|
||||
~Bureaucrat(void);
|
||||
|
||||
const std::string &getName(void);
|
||||
uint8_t getGrade(void);
|
||||
const std::string &getName(void) const;
|
||||
uint8_t getGrade(void) const;
|
||||
|
||||
class GradeTooHighException : public std::exception {
|
||||
public:
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* 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:07:49 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -19,11 +19,27 @@ Form::Form(void) : _name(""), _signed(false), _minForSign(1), _minForExec(1) {
|
||||
Form::Form(std::string name, uint8_t minForSign, uint8_t minForExec)
|
||||
: _name(name), _signed(false), _minForSign(minForSign),
|
||||
_minForExec(minForExec) {
|
||||
_log("➕", "Form", "", "default constructor called");
|
||||
_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");
|
||||
}
|
||||
@ -33,9 +49,9 @@ const char *Form::GradeTooLowException::what() const throw() {
|
||||
}
|
||||
|
||||
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; }
|
||||
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()) {
|
||||
@ -44,7 +60,16 @@ void Form::beSigned(Bureaucrat b) {
|
||||
_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: " << val.getMinForSign() << ", min grade to execute: " << val.getMinForExec() << std::endl;
|
||||
os << "Form: " << val.getName()
|
||||
<< ", minGrade to sign: " << val.getMinForSign()
|
||||
<< ", min grade to execute: " << val.getMinForExec() << std::endl;
|
||||
return (os);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/03/08 20:10:59 by adjoly #+# #+# */
|
||||
/* Updated: 2025/03/30 15:11:58 by adjoly ### ########.fr */
|
||||
/* Updated: 2025/04/01 10:57:28 by adjoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -20,14 +20,16 @@ void _log(std::string emoji, std::string what, std::string who,
|
||||
typedef unsigned char uint8_t;
|
||||
|
||||
#include "Bureaucrat.hpp"
|
||||
//class Bureaucrat;
|
||||
|
||||
class Form {
|
||||
public:
|
||||
Form(void);
|
||||
Form(std::string name, uint8_t minForSign, uint8_t minForExec);
|
||||
Form(const Form &);
|
||||
~Form(void);
|
||||
|
||||
Form &operator=(const Form &);
|
||||
|
||||
class GradeTooHighException : public std::exception {
|
||||
public:
|
||||
virtual const char *what() const throw();
|
||||
@ -45,10 +47,12 @@ class Form {
|
||||
void beSigned(Bureaucrat);
|
||||
|
||||
private:
|
||||
const std::string _name;
|
||||
std::string _name;
|
||||
bool _signed;
|
||||
const uint8_t _minForSign;
|
||||
const uint8_t _minForExec;
|
||||
|
||||
void _gradeCheck(void) const;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &, Form &);
|
||||
|
Reference in New Issue
Block a user