From 8b84a934b18d50374656eede3b9773a6720c87d9 Mon Sep 17 00:00:00 2001 From: Ladebeze66 Date: Tue, 20 Feb 2024 19:24:13 +0100 Subject: [PATCH] ded --- cpp05/ex02/AForm.cpp | 2 +- cpp05/ex02/AForm.hpp | 9 ++++--- cpp05/ex02/Bureaucrat.cpp | 16 +++++++++++- cpp05/ex02/Bureaucrat.hpp | 3 ++- cpp05/ex02/PresidentialPardonForm.hpp | 29 ++++++++++++++++++++++ cpp05/ex02/RobotomyRequestForm.hpp | 30 +++++++++++++++++++++++ cpp05/ex02/ShrubberyCreationForm.cpp | 35 +++++++++++++++++++++++++++ cpp05/ex02/ShrubberyCreationForm.hpp | 30 +++++++++++++++++++++++ 8 files changed, 147 insertions(+), 7 deletions(-) create mode 100644 cpp05/ex02/PresidentialPardonForm.hpp create mode 100644 cpp05/ex02/RobotomyRequestForm.hpp create mode 100644 cpp05/ex02/ShrubberyCreationForm.cpp create mode 100644 cpp05/ex02/ShrubberyCreationForm.hpp diff --git a/cpp05/ex02/AForm.cpp b/cpp05/ex02/AForm.cpp index af28bce..cbab9a6 100644 --- a/cpp05/ex02/AForm.cpp +++ b/cpp05/ex02/AForm.cpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:39:51 by fgras-ca #+# #+# */ -/* Updated: 2024/02/16 18:44:23 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/20 16:39:29 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/cpp05/ex02/AForm.hpp b/cpp05/ex02/AForm.hpp index ebd02ac..10b0b68 100644 --- a/cpp05/ex02/AForm.hpp +++ b/cpp05/ex02/AForm.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:37:14 by fgras-ca #+# #+# */ -/* Updated: 2024/02/16 18:50:37 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/20 17:00:31 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -32,11 +32,11 @@ public: AForm(); AForm(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute); // Constructeur par copie - AForm(const AForm& other); + AForm(const AForm& other); // Opérateur d'affectation - virtual AForm& operator=(const AForm& other); + AForm& operator=(const AForm& other); // Destructeur - virtual ~AForm(); + virtual ~AForm(); std::string getName() const; @@ -45,6 +45,7 @@ public: int getGradeRequiredToExecute() const; virtual void beSigned(const Bureaucrat& bureaucrat); + virtual void execute(Bureaucrat const &executor) const = 0; class GradeTooHighException : public std::exception { diff --git a/cpp05/ex02/Bureaucrat.cpp b/cpp05/ex02/Bureaucrat.cpp index b1045fa..d38c256 100644 --- a/cpp05/ex02/Bureaucrat.cpp +++ b/cpp05/ex02/Bureaucrat.cpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 13:16:26 by fgras-ca #+# #+# */ -/* Updated: 2024/02/16 17:30:32 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/20 17:02:49 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -92,6 +92,20 @@ void Bureaucrat::signForm(Form& form) std::cout << this->name << " couldn’t sign " << form.getName() << " because " << e.what() << std::endl; } } + +void Bureaucrat::executeForm(AForm const &form) +{ + try + { + form.execute(*this); + std::cout << name << " executed " << form.getName() << std::endl; + } + catch (std::exception& e) + { + std::cout << name << " couldn’t execute " << form.getName() << " because: " << e.what() << std::endl; + } +} + // Méthodes pour les exceptions const char* Bureaucrat::GradeTooHighException::what() const throw() { diff --git a/cpp05/ex02/Bureaucrat.hpp b/cpp05/ex02/Bureaucrat.hpp index 34fca77..70414a9 100644 --- a/cpp05/ex02/Bureaucrat.hpp +++ b/cpp05/ex02/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 12:57:28 by fgras-ca #+# #+# */ -/* Updated: 2024/02/16 18:26:55 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/20 17:01:47 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -54,6 +54,7 @@ public: void incrementGrade(); void decrementGrade(); void signForm(Form& form); + void executeForm(AForm const &form); private: const std::string name; diff --git a/cpp05/ex02/PresidentialPardonForm.hpp b/cpp05/ex02/PresidentialPardonForm.hpp new file mode 100644 index 0000000..f2653ef --- /dev/null +++ b/cpp05/ex02/PresidentialPardonForm.hpp @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* PresidentialPardonForm.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/20 16:56:48 by fgras-ca #+# #+# */ +/* Updated: 2024/02/20 16:57:14 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef PRESIDENTIALPARDONFORM_HPP +#define PRESIDENTIALPARDONFORM_HPP + +#include "AForm.hpp" + +class PresidentialPardonForm : public AForm +{ +public: + PresidentialPardonForm(const std::string& target); + PresidentialPardonForm(const PresidentialPardonForm& other); + PresidentialPardonForm& operator=(const PresidentialPardonForm& other); + virtual ~PresidentialPardonForm(); + + void execute(Bureaucrat const &executor) const override; +}; + +#endif diff --git a/cpp05/ex02/RobotomyRequestForm.hpp b/cpp05/ex02/RobotomyRequestForm.hpp new file mode 100644 index 0000000..59652af --- /dev/null +++ b/cpp05/ex02/RobotomyRequestForm.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* RobotomyRequestForm.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/20 16:55:26 by fgras-ca #+# #+# */ +/* Updated: 2024/02/20 16:56:11 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef ROBOTOMYREQUESTFORM_HPP +#define ROBOTOMYREQUESTFORM_HPP + +#include "AForm.hpp" +#include // Pour rand() + +class RobotomyRequestForm : public AForm +{ +public: + RobotomyRequestForm(const std::string& target); + RobotomyRequestForm(const RobotomyRequestForm& other); + RobotomyRequestForm& operator=(const RobotomyRequestForm& other); + virtual ~RobotomyRequestForm(); + + void execute(Bureaucrat const &executor) const override; +}; + +#endif diff --git a/cpp05/ex02/ShrubberyCreationForm.cpp b/cpp05/ex02/ShrubberyCreationForm.cpp new file mode 100644 index 0000000..8c00bb9 --- /dev/null +++ b/cpp05/ex02/ShrubberyCreationForm.cpp @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ShrubberyCreationForm.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/20 16:54:52 by fgras-ca #+# #+# */ +/* Updated: 2024/02/20 19:23:43 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ShrubberyCreationForm.hpp" + +ShrubberyCreationForm::ShrubberyCreationForm(const std::string& target) + : AForm("ShrubberyCreationForm", 145, 137, target) {} + +ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm& other) + : AForm(other) {} + +ShrubberyCreationForm& ShrubberyCreationForm::operator=(const ShrubberyCreationForm& other) +{ + AForm::operator=(other); + return (*this); +} + +ShrubberyCreationForm::~ShrubberyCreationForm() {} + +void ShrubberyCreationForm::execute(Bureaucrat const &executor) const +{ + AForm::execute(executor); // Assurez-vous que cette vérification est implémentée dans AForm ou faites-la ici. + std::ofstream ofs(getTarget() + "_shrubbery"); + // Assurez-vous que ofs est ouvert correctement. + ofs << "ASCII trees" << std::endl; +} diff --git a/cpp05/ex02/ShrubberyCreationForm.hpp b/cpp05/ex02/ShrubberyCreationForm.hpp new file mode 100644 index 0000000..518ad4e --- /dev/null +++ b/cpp05/ex02/ShrubberyCreationForm.hpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ShrubberyCreationForm.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/20 16:41:49 by fgras-ca #+# #+# */ +/* Updated: 2024/02/20 16:58:51 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef SHRUBBERYCREATIONFORM_HPP +#define SHRUBBERYCREATIONFORM_HPP + +#include "AForm.hpp" +#include + +class ShrubberyCreationForm : public AForm +{ +public: + ShrubberyCreationForm(const std::string& target); + ShrubberyCreationForm(const ShrubberyCreationForm& other); + ShrubberyCreationForm& operator=(const ShrubberyCreationForm& other); + virtual ~ShrubberyCreationForm(); + + void execute(Bureaucrat const &executor) const override; +}; + +#endif \ No newline at end of file