diff --git a/ex00/Bureaucrat.cpp b/ex00/Bureaucrat.cpp index 0580e37..d618223 100644 --- a/ex00/Bureaucrat.cpp +++ b/ex00/Bureaucrat.cpp @@ -6,11 +6,13 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/23 13:59:45 by adjoly #+# #+# */ -/* Updated: 2025/03/29 14:58:52 by adjoly ### ########.fr */ +/* Updated: 2025/04/01 10:49:43 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" +#include "Form.hpp" +#include void _log(std::string emoji, std::string what, std::string who, std::string str) { @@ -40,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"); @@ -92,10 +94,18 @@ std::ostream &operator<<(std::ostream &os, Bureaucrat &val) { } const char *Bureaucrat::GradeTooHighException::what() const throw() { - return ("Grade is too high"); - } + return ("Grade is too high"); +} const char *Bureaucrat::GradeTooLowException::what() const throw() { - return ("Grade is too low"); - } + return ("Grade is too low"); +} +void Bureaucrat::signForm(Form &f) { + try { + f.beSigned(*this); + std::cout << _name << " signed " << f.getName() << std::endl; + } catch (std::exception &e) { + std::cout << _name << " counldn't sign " << f.getName() << " because " << e.what() << std::endl; + } +} diff --git a/ex00/Bureaucrat.hpp b/ex00/Bureaucrat.hpp index cd2b0a3..1e17fa5 100644 --- a/ex00/Bureaucrat.hpp +++ b/ex00/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/23 13:59:43 by adjoly #+# #+# */ -/* Updated: 2025/03/29 15:02:17 by adjoly ### ########.fr */ +/* Updated: 2025/04/01 10:50:00 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,14 +18,16 @@ #include #include +void _log(std::string emoji, std::string what, std::string who, + std::string str); + +class Form; + typedef unsigned char uint8_t; #define MAXGRADE 1 #define MINGRADE 150 -void _log(std::string emoji, std::string what, std::string who, - std::string str); - class Bureaucrat { public: Bureaucrat(void); @@ -33,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: @@ -56,6 +58,7 @@ class Bureaucrat { Bureaucrat operator++(int); Bureaucrat operator--(int); + void signForm(Form &); private: const std::string _name; uint8_t _grade; diff --git a/ex01/Bureaucrat.cpp b/ex01/Bureaucrat.cpp index db2b89c..d618223 100644 --- a/ex01/Bureaucrat.cpp +++ b/ex01/Bureaucrat.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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"); diff --git a/ex01/Bureaucrat.hpp b/ex01/Bureaucrat.hpp index 65eb429..1e17fa5 100644 --- a/ex01/Bureaucrat.hpp +++ b/ex01/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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: diff --git a/ex01/Form.cpp b/ex01/Form.cpp index 28b50c8..8667cbb 100644 --- a/ex01/Form.cpp +++ b/ex01/Form.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } diff --git a/ex01/Form.hpp b/ex01/Form.hpp index 582ab98..41ee48a 100644 --- a/ex01/Form.hpp +++ b/ex01/Form.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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 &); diff --git a/ex02/AForm.cpp b/ex02/AForm.cpp index 28b50c8..372440f 100644 --- a/ex02/AForm.cpp +++ b/ex02/AForm.cpp @@ -1,50 +1,89 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* Form.cpp :+: :+: :+: */ +/* AForm.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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); } diff --git a/ex02/AForm.hpp b/ex02/AForm.hpp index 582ab98..cb51c2e 100644 --- a/ex02/AForm.hpp +++ b/ex02/AForm.hpp @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* Form.hpp :+: :+: :+: */ +/* AForm.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/03/08 20:10:59 by adjoly #+# #+# */ -/* Updated: 2025/03/30 15:11:58 by adjoly ### ########.fr */ +/* Updated: 2025/04/01 11:03:13 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,13 +20,15 @@ void _log(std::string emoji, std::string what, std::string who, typedef unsigned char uint8_t; #include "Bureaucrat.hpp" -//class Bureaucrat; -class Form { +class AForm { public: - Form(void); - Form(std::string name, uint8_t minForSign, uint8_t minForExec); - ~Form(void); + AForm(void); + AForm(std::string name, uint8_t minForSign, uint8_t minForExec); + AForm(const AForm &); + virtual ~AForm(void); + + AForm &operator=(const AForm &); class GradeTooHighException : public std::exception { public: @@ -36,6 +38,10 @@ class Form { public: virtual const char *what() const throw(); }; + class NotSigned : public std::exception { + public: + virtual const char *what() const throw(); + }; std::string getName(void) const; bool getSigned(void) const; @@ -43,12 +49,16 @@ class Form { uint8_t getMinForExec(void) const; void beSigned(Bureaucrat); + void execute(const Bureaucrat &) const; private: - const std::string _name; - bool _signed; - const uint8_t _minForSign; - const uint8_t _minForExec; + std::string _name; + bool _signed; + const uint8_t _minForSign; + const uint8_t _minForExec; + + virtual void _exec(const Bureaucrat &) const = 0; + void _gradeCheck(void) const; }; std::ostream &operator<<(std::ostream &, Form &); diff --git a/ex02/Bureaucrat.cpp b/ex02/Bureaucrat.cpp index db2b89c..d618223 100644 --- a/ex02/Bureaucrat.cpp +++ b/ex02/Bureaucrat.cpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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"); diff --git a/ex02/Bureaucrat.hpp b/ex02/Bureaucrat.hpp index 65eb429..1e17fa5 100644 --- a/ex02/Bureaucrat.hpp +++ b/ex02/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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: diff --git a/ex02/PresidentialPardonForm.cpp b/ex02/PresidentialPardonForm.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/ex02/PresidentialPardonForm.hpp b/ex02/PresidentialPardonForm.hpp deleted file mode 100644 index 2b4519d..0000000 --- a/ex02/PresidentialPardonForm.hpp +++ /dev/null @@ -1,12 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* PresidentialPardonForm.hpp :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: adjoly +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2025/03/30 16:25:52 by adjoly #+# #+# */ -/* Updated: 2025/03/30 18:06:49 by adjoly ### ########.fr */ -/* */ -/* ************************************************************************** */ - diff --git a/ex02/RobotomyRequestForm.cpp b/ex02/RobotomyRequestForm.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/ex02/RobotomyRequestForm.hpp b/ex02/RobotomyRequestForm.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/ex02/ShrubberyCreationForm.cpp b/ex02/ShrubberyCreationForm.cpp index e69de29..2368868 100644 --- a/ex02/ShrubberyCreationForm.cpp +++ b/ex02/ShrubberyCreationForm.cpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ShrubberyCreationForm.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/01 09:25:06 by adjoly #+# #+# */ +/* Updated: 2025/04/01 10:53:21 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ShrubberyCreationForm.hpp" +#include "AForm.hpp" + +ShrubberyCreationForm::ShrubberyCreationForm(void) + : AForm("ShrubberyCreationForm", 145, 137) { + _log("➕", "ShrubberyCreationForm", "", "default constructor called"); +} + +ShrubberyCreationForm::~ShrubberyCreationForm(void) { + _log("➖", "ShrubberyCreationForm", "", "destructor called"); +} + +void ShrubberyCreationForm::_exec(const Bureaucrat &b) const { + +} diff --git a/ex02/ShrubberyCreationForm.hpp b/ex02/ShrubberyCreationForm.hpp index e69de29..a627f6a 100644 --- a/ex02/ShrubberyCreationForm.hpp +++ b/ex02/ShrubberyCreationForm.hpp @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ShrubberyCreationForm.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: adjoly +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2025/04/01 09:19:24 by adjoly #+# #+# */ +/* Updated: 2025/04/01 10:18:36 by adjoly ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include "AForm.hpp" + +class ShrubberyCreationForm : public AForm { + public: + ShrubberyCreationForm(void); + ~ShrubberyCreationForm(void); + private: + void _exec(const Bureaucrat &) const; +}; +