This commit is contained in:
Ladebeze66 2024-02-20 19:24:13 +01:00
parent bb9b81c53f
commit 8b84a934b1
8 changed files with 147 additions and 7 deletions

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 */
/* */
/* ************************************************************************** */

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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
{

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 << " couldnt 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 << " couldnt execute " << form.getName() << " because: " << e.what() << std::endl;
}
}
// Méthodes pour les exceptions
const char* Bureaucrat::GradeTooHighException::what() const throw()
{

View File

@ -6,7 +6,7 @@
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* PresidentialPardonForm.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* RobotomyRequestForm.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <cstdlib> // 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

View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ShrubberyCreationForm.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;
}

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ShrubberyCreationForm.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <fstream>
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