diff --git a/cpp05/.vscode/settings.json b/cpp05/.vscode/settings.json index d150fb8..549173e 100644 --- a/cpp05/.vscode/settings.json +++ b/cpp05/.vscode/settings.json @@ -57,50 +57,52 @@ "C_Cpp_Runner.useLinkTimeOptimization": false, "C_Cpp_Runner.msvcSecureNoWarnings": false, "files.associations": { - "iostream": "cpp", - "ostream": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "compare": "cpp", - "concepts": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "string": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "random": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "numbers": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "typeinfo": "cpp" - }, + "iostream": "cpp", + "ostream": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "compare": "cpp", + "concepts": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "string": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "random": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "numbers": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "typeinfo": "cpp", + "ctime": "cpp", + "fstream": "cpp" +}, "C_Cpp.errorSquiggles": "disabled" } \ No newline at end of file diff --git a/cpp05/ex00/Makefile b/cpp05/ex00/Makefile index af741b7..780c306 100644 --- a/cpp05/ex00/Makefile +++ b/cpp05/ex00/Makefile @@ -6,7 +6,7 @@ # By: fgras-ca +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# # -# Updated: 2024/02/11 13:37:27 by fgras-ca ### ########.fr # +# Updated: 2024/02/21 17:06:51 by fgras-ca ### ########.fr # # # # **************************************************************************** # @@ -28,14 +28,16 @@ NAME = Bureaucrat SRC = Bureaucrat.cpp \ main.cpp \ -OBJS = ${SRC:.cpp=.o} - CC = c++ CFLAGS = -Wall -Werror -Wextra -std=c++98 RM = rm -f +OBJS = ${SRC:.cpp=.o} all : $(NAME) +%.o: %.cpp + $(CC) $(CFLAGS) -c $< -o $@ + $(NAME) : $(OBJS) @echo "$(RED)Compilation fixed... $(DEF_COLOR)" $(CC) $(CFLAGS) $(OBJS) -g -o $(NAME) diff --git a/cpp05/ex02/AForm.cpp b/cpp05/ex02/AForm.cpp index cbab9a6..52c6aa3 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/20 16:39:29 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/21 14:25:05 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -94,6 +94,10 @@ const char* AForm::GradeTooLowException::what() const noexcept return ("Grade too low\n"); } +const char* AForm::NotSignedException::what() const noexcept +{ + return ("The forpm is not signed.\n"); +} std::ostream& operator<<(std::ostream& os, const AForm& aform) { os << "AForm: " << aform.getName() diff --git a/cpp05/ex02/AForm.hpp b/cpp05/ex02/AForm.hpp index 10b0b68..56486c7 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/20 17:00:31 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/21 15:53:16 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,9 @@ private: const int gradeRequiredToSign; const int gradeRequiredToExecute; +protected: + std::string target; + public: //constructueur AForm(); @@ -43,6 +46,7 @@ public: bool getIsSigned() const; int getGradeRequiredToSign() const; int getGradeRequiredToExecute() const; + virtual std::string getTarget() const {return target;} virtual void beSigned(const Bureaucrat& bureaucrat); virtual void execute(Bureaucrat const &executor) const = 0; @@ -58,8 +62,13 @@ public: public: const char* what() const noexcept override; }; -}; + class NotSignedException : public std::exception + { + public: + const char* what() const noexcept override; + }; +}; // Surcharge de l'opérateur d'insertion std::ostream& operator<<(std::ostream& os, const AForm& aform); diff --git a/cpp05/ex02/Bureaucrat.cpp b/cpp05/ex02/Bureaucrat.cpp index d38c256..cc7f0ce 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/20 17:02:49 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/21 16:02:52 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -80,30 +80,30 @@ void Bureaucrat::decrementGrade() ++grade; } -void Bureaucrat::signForm(Form& form) +void Bureaucrat::signForm(AForm& form) { try { form.beSigned(*this); - std::cout << this->name << " signed " << form.getName() << std::endl; + std::cout << this->name << " signed " << RED << form.getName() << BLUE << " (" << form.getTarget() << ")" << RESET << std::endl; } catch (std::exception& e) { - std::cout << this->name << " couldn’t sign " << form.getName() << " because " << e.what() << std::endl; + std::cout << this->name << " couldn’t sign " << RED << form.getName() << BLUE << " (" << form.getTarget() << ")" << RESET << " because " << e.what() << std::endl; } } void Bureaucrat::executeForm(AForm const &form) { - try + try { - form.execute(*this); - std::cout << name << " executed " << form.getName() << std::endl; - } + form.execute(*this); + std::cout << name << " executed " << RED << form.getName() << BLUE << " (" << form.getTarget() << ")" << RESET << std::endl; + } catch (std::exception& e) { - std::cout << name << " couldn’t execute " << form.getName() << " because: " << e.what() << std::endl; - } + std::cout << name << " couldn’t execute " << RED << form.getName() << BLUE << " (" << form.getTarget() << ")" << RESET << " because: " << e.what() << std::endl; + } } // Méthodes pour les exceptions diff --git a/cpp05/ex02/Bureaucrat.hpp b/cpp05/ex02/Bureaucrat.hpp index 70414a9..bb47f17 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/20 17:01:47 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/21 13:09:39 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -28,6 +28,8 @@ #define CYAN "\033[36m" #define WHITE "\033[37m" +class AForm; + class Bureaucrat { public: @@ -53,7 +55,7 @@ public: int getGrade() const; void incrementGrade(); void decrementGrade(); - void signForm(Form& form); + void signForm(AForm& form); void executeForm(AForm const &form); private: diff --git a/cpp05/ex02/Home_shrubbery b/cpp05/ex02/Home_shrubbery new file mode 100644 index 0000000..6f7aa37 --- /dev/null +++ b/cpp05/ex02/Home_shrubbery @@ -0,0 +1 @@ +ASCII trees diff --git a/cpp05/ex02/Makefile b/cpp05/ex02/Makefile index ca845c0..74be5d4 100644 --- a/cpp05/ex02/Makefile +++ b/cpp05/ex02/Makefile @@ -6,7 +6,7 @@ # By: fgras-ca +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# # -# Updated: 2024/02/16 18:36:25 by fgras-ca ### ########.fr # +# Updated: 2024/02/21 13:06:08 by fgras-ca ### ########.fr # # # # **************************************************************************** # @@ -28,6 +28,9 @@ NAME = Form SRC = Bureaucrat.cpp \ AForm.cpp \ main.cpp \ + PresidentialPardonForm.cpp \ + RobotomyRequestForm.cpp \ + ShrubberyCreationForm.cpp \ OBJS = ${SRC:.cpp=.o} diff --git a/cpp05/ex02/PresidentialPardonForm.cpp b/cpp05/ex02/PresidentialPardonForm.cpp new file mode 100644 index 0000000..4c4fcb3 --- /dev/null +++ b/cpp05/ex02/PresidentialPardonForm.cpp @@ -0,0 +1,59 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* PresidentialPardonForm.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/21 11:31:13 by fgras-ca #+# #+# */ +/* Updated: 2024/02/21 15:18:45 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "PresidentialPardonForm.hpp" + +PresidentialPardonForm::PresidentialPardonForm(const std::string& target) + : AForm("PresidentialPardonForm", 25, 5), target(target) +{ + std::cout << GREEN << "PresidentialPardonForm constructed for target: " << target << RESET << std::endl; +} + +PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm& other) + : AForm(other), target(other.target) +{ + std::cout << "PresidentialPardonForm copy constructed for target: " << target << std::endl; +} + +PresidentialPardonForm& PresidentialPardonForm::operator=(const PresidentialPardonForm& other) +{ + if (this != &other) + { + AForm::operator=(other); + target = other.target; + std::cout << "PresidentialPardonForm assigned from another form for target: " << target << std::endl; + } + return (*this); +} + +PresidentialPardonForm::~PresidentialPardonForm() +{ + std::cout << RED << "PresidentialPardonForm destroyed for target: " << target << RESET << std::endl; +} + +void PresidentialPardonForm::execute(Bureaucrat const &executor) const +{ + if (!getIsSigned()) + { + throw AForm::NotSignedException(); + } + if (executor.getGrade() > getGradeRequiredToExecute()) + { + throw AForm::GradeTooLowException(); + } + std::cout << getTarget() << " has been pardoned by Zaphod Beeblebrox." << std::endl; +} + +std::string PresidentialPardonForm::getTarget() const +{ + return (target); +} \ No newline at end of file diff --git a/cpp05/ex02/PresidentialPardonForm.hpp b/cpp05/ex02/PresidentialPardonForm.hpp index f2653ef..961c6e1 100644 --- a/cpp05/ex02/PresidentialPardonForm.hpp +++ b/cpp05/ex02/PresidentialPardonForm.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/20 16:56:48 by fgras-ca #+# #+# */ -/* Updated: 2024/02/20 16:57:14 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/21 15:17:46 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,9 +14,18 @@ #define PRESIDENTIALPARDONFORM_HPP #include "AForm.hpp" +#include + +#define RESET "\033[0m" +#define GREEN "\033[32m" +#define CYAN "\033[36m" +#define RED "\033[31m" class PresidentialPardonForm : public AForm { +private: + std::string target; + public: PresidentialPardonForm(const std::string& target); PresidentialPardonForm(const PresidentialPardonForm& other); @@ -24,6 +33,7 @@ public: virtual ~PresidentialPardonForm(); void execute(Bureaucrat const &executor) const override; + std::string getTarget() const; }; #endif diff --git a/cpp05/ex02/RobotomyRequestForm.cpp b/cpp05/ex02/RobotomyRequestForm.cpp new file mode 100644 index 0000000..1f22358 --- /dev/null +++ b/cpp05/ex02/RobotomyRequestForm.cpp @@ -0,0 +1,68 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* RobotomyRequestForm.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/21 11:25:21 by fgras-ca #+# #+# */ +/* Updated: 2024/02/21 16:00:03 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "RobotomyRequestForm.hpp" + +RobotomyRequestForm::RobotomyRequestForm(const std::string& target) + : AForm("RobotomyRequestForm", 72, 45), target(target) +{ + std::cout << GREEN << "RobotomyRequestForm constructor called for target: " << target << RESET << std::endl; +} + +RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm& other) + : AForm(other), target(other.target) +{ + std::cout << CYAN << "Copy constructor called for RobotomyRequestForm with target: " << target << RESET << std::endl; +} + +RobotomyRequestForm& RobotomyRequestForm::operator=(const RobotomyRequestForm& other) +{ + if (this != &other) + { + AForm::operator=(other); // Note: Ceci n'aura aucun effet car AForm::operator= est supprimé ou non implémenté. + target = other.target; + // Log pour l'opération d'affectation + std::cout << CYAN << "Assignment operator called for RobotomyRequestForm with target: " << target << RESET << std::endl; + } + return (*this); +} + +RobotomyRequestForm::~RobotomyRequestForm() +{ + std::cout << RED << "RobotomyRequestForm for target: " << target << " is destroyed!" << RESET << std::endl; +} + +void RobotomyRequestForm::execute(Bureaucrat const &executor) const +{ + if (!getIsSigned()) + { + throw NotSignedException(); + } + if (executor.getGrade() > getGradeRequiredToExecute()) + { + throw GradeTooLowException(); + } + std::cout << "Drilling noises... Zzzzzz..." << std::endl; + if (std::rand() % 2 == 0) + { + std::cout << target << " has been robotomized successfully." << std::endl; + } + else + { + std::cout << "The robotomy on " << target << " failed." << std::endl; + } +} + +std::string RobotomyRequestForm::getTarget() const +{ + return (target); // Assurez-vous que 'target' est bien défini et accessible +} diff --git a/cpp05/ex02/RobotomyRequestForm.hpp b/cpp05/ex02/RobotomyRequestForm.hpp index 59652af..8738dae 100644 --- a/cpp05/ex02/RobotomyRequestForm.hpp +++ b/cpp05/ex02/RobotomyRequestForm.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/20 16:55:26 by fgras-ca #+# #+# */ -/* Updated: 2024/02/20 16:56:11 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/21 15:58:32 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,10 +14,20 @@ #define ROBOTOMYREQUESTFORM_HPP #include "AForm.hpp" -#include // Pour rand() +#include +#include // Pour std::rand() et std::srand() +#include // Pour std::time() +// Assurez-vous d'avoir ces définitions quelque part, ou remplacez-les par vos propres codes de couleur. +#define RESET "\033[0m" +#define GREEN "\033[32m" +#define CYAN "\033[36m" +#define RED "\033[31m" class RobotomyRequestForm : public AForm { +private: + std::string target; + public: RobotomyRequestForm(const std::string& target); RobotomyRequestForm(const RobotomyRequestForm& other); @@ -25,6 +35,7 @@ public: virtual ~RobotomyRequestForm(); void execute(Bureaucrat const &executor) const override; + std::string getTarget() const override; }; #endif diff --git a/cpp05/ex02/ShrubberyCreationForm.cpp b/cpp05/ex02/ShrubberyCreationForm.cpp index 8c00bb9..a26d31b 100644 --- a/cpp05/ex02/ShrubberyCreationForm.cpp +++ b/cpp05/ex02/ShrubberyCreationForm.cpp @@ -6,30 +6,58 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/20 16:54:52 by fgras-ca #+# #+# */ -/* Updated: 2024/02/20 19:23:43 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/21 15:39:36 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "ShrubberyCreationForm.hpp" ShrubberyCreationForm::ShrubberyCreationForm(const std::string& target) - : AForm("ShrubberyCreationForm", 145, 137, target) {} + : AForm("ShrubberyCreationForm", 145, 137), target(target) +{ + std::cout << GREEN << "ShrubberyCreationForm constructor called for target: " << target << RESET << std::endl; +} ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm& other) - : AForm(other) {} + : AForm(other), target(other.target) +{ + std::cout << CYAN << "Copy constructor called for ShrubberyCreationForm with target: " << target << RESET << std::endl; +} ShrubberyCreationForm& ShrubberyCreationForm::operator=(const ShrubberyCreationForm& other) { - AForm::operator=(other); + if (this != &other) + { + AForm::operator=(other); // Cette opération n'a pas d'effet réel si AForm n'implémente pas operator= pour les champs non statiques. + target = other.target; + std::cout << CYAN << "Assignment operator called for ShrubberyCreationForm with target: " << target << RESET << std::endl; + } return (*this); } -ShrubberyCreationForm::~ShrubberyCreationForm() {} +ShrubberyCreationForm::~ShrubberyCreationForm() +{ + std::cout << RED << "ShrubberyCreationForm for target: " << target << " is destroyed!" << RESET << std::endl; +} 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. + // Vérification si le formulaire est signé et si le grade de l'exécuteur est suffisant + if (!getIsSigned()) + throw NotSignedException(); // Assurez-vous que cette exception est correctement définie dans AForm + if (executor.getGrade() > getGradeRequiredToExecute()) + throw GradeTooLowException(); + + std::ofstream ofs(target + "_shrubbery"); + if (!ofs) + { + std::cerr << "Failed to create file " << target << "_shrubbery" << std::endl; + return ; + } ofs << "ASCII trees" << std::endl; } + +std::string ShrubberyCreationForm::getTarget() const +{ + return (target); +} diff --git a/cpp05/ex02/ShrubberyCreationForm.hpp b/cpp05/ex02/ShrubberyCreationForm.hpp index 518ad4e..c464af2 100644 --- a/cpp05/ex02/ShrubberyCreationForm.hpp +++ b/cpp05/ex02/ShrubberyCreationForm.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/20 16:41:49 by fgras-ca #+# #+# */ -/* Updated: 2024/02/20 16:58:51 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/21 15:51:24 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,9 +15,17 @@ #include "AForm.hpp" #include +#include +#define RESET "\033[0m" +#define GREEN "\033[32m" +#define CYAN "\033[36m" +#define RED "\033[31m" class ShrubberyCreationForm : public AForm { +private: + std::string target; + public: ShrubberyCreationForm(const std::string& target); ShrubberyCreationForm(const ShrubberyCreationForm& other); @@ -25,6 +33,7 @@ public: virtual ~ShrubberyCreationForm(); void execute(Bureaucrat const &executor) const override; + std::string getTarget() const; }; #endif \ No newline at end of file diff --git a/cpp05/ex02/main.cpp b/cpp05/ex02/main.cpp index bbb68bf..0e1de4a 100644 --- a/cpp05/ex02/main.cpp +++ b/cpp05/ex02/main.cpp @@ -6,77 +6,44 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:55:46 by fgras-ca #+# #+# */ -/* Updated: 2024/02/11 15:38:42 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/21 15:21:24 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" -#include "Form.hpp" +#include "ShrubberyCreationForm.hpp" +#include "RobotomyRequestForm.hpp" +#include "PresidentialPardonForm.hpp" +#include +#include int main() { - try - { - // Création d'un bureaucrate avec un grade élevé - Bureaucrat highRankBureaucrat("HighRank", 2); - // Création d'un bureaucrate avec un grade bas - Bureaucrat lowRankBureaucrat("LowRank", 149); - Bureaucrat chief("Chief", 1); - Bureaucrat intern("Intern", 150); + Bureaucrat john("John", 2); + Bureaucrat doe("Doe", 150); - // Création de formulaires - Form highRequirementForm("HighRequirement", 1, 1); // Exige un grade très élevé pour signer - Form lowRequirementForm("LowRequirement", 150, 150); // Peut être signé par n'importe quel bureaucrate - Form formHigh("HighForm", 2, 5); + ShrubberyCreationForm shrub("Home"); + RobotomyRequestForm robot("Robot"); + PresidentialPardonForm pardon("Criminal"); - // Tentative de signature des formulaires - std::cout << CYAN << "Tentative de signature par HighRank:" << RESET << std::endl; - highRankBureaucrat.signForm(highRequirementForm); - highRankBureaucrat.signForm(lowRequirementForm); + try { + john.signForm(shrub); + john.executeForm(shrub); - std::cout << CYAN << "\nTentative de signature par LowRank:" << RESET << std::endl; - lowRankBureaucrat.signForm(highRequirementForm); - lowRankBureaucrat.signForm(lowRequirementForm); + john.signForm(robot); + john.executeForm(robot); - std::cout << GREEN << "\nTenative de signature formHight par chief: " << RESET << std::endl; - chief.signForm(formHigh); - chief.signForm(highRequirementForm); - chief.signForm(lowRequirementForm); + john.signForm(pardon); + john.executeForm(pardon); - std::cout << GREEN << "\nTenative de signature formHight par intern: " << RESET << std::endl; - intern.signForm(formHigh); - intern.signForm(highRequirementForm); - intern.signForm(lowRequirementForm); + // Tester avec un bureaucrate de grade insuffisant + doe.signForm(shrub); + doe.executeForm(shrub); } catch (std::exception& e) { - std::cerr << RED << "Une exception a été capturée: " << RESET << e.what() << std::endl; + std::cout << e.what() << std::endl; } - // Création d'un formulaire avec des grades invalides - try - { - Form invalidForm("ImpossibleForm", 0, 151); - } - catch (const Form::GradeTooHighException& e) - { - std::cerr << RED << "Form creation error: " << RESET << e.what() << std::endl; - } - // Signature d'un formulaire par un bureaucrate au seuil du grade requis - try - { - Bureaucrat chief("Chief", 1); - Bureaucrat intern("Intern", 150); - Form formHigh("HighForm", 2, 5); - Form edgeCaseForm("EdgeCaseForm", 150, 150); - intern.signForm(edgeCaseForm); - - // Tentative de signature d'un formulaire déjà signé - chief.signForm(formHigh); - } - catch (const std::exception& e) - { - std::cerr << RED << "Unexpected error: " << RESET << e.what() << std::endl; - } return (0); }