diff --git a/cpp05/.vscode/settings.json b/cpp05/.vscode/settings.json index 5b21dcf..d150fb8 100644 --- a/cpp05/.vscode/settings.json +++ b/cpp05/.vscode/settings.json @@ -57,7 +57,50 @@ "C_Cpp_Runner.useLinkTimeOptimization": false, "C_Cpp_Runner.msvcSecureNoWarnings": false, "files.associations": { - "iostream": "cpp", - "ostream": "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" + }, + "C_Cpp.errorSquiggles": "disabled" } \ No newline at end of file diff --git a/cpp05/ex00/Bureaucrat.cpp b/cpp05/ex00/Bureaucrat.cpp index b8f3482..585766a 100644 --- a/cpp05/ex00/Bureaucrat.cpp +++ b/cpp05/ex00/Bureaucrat.cpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 13:16:26 by fgras-ca #+# #+# */ -/* Updated: 2024/02/14 14:38:10 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/16 16:48:16 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ // Constructeur par défaut Bureaucrat::Bureaucrat() : name("Default"), grade(150) { - std::cout << GREEN << "Bureaucrat default constructor called!\n" << RESET << std::endl; + std::cout << GREEN << "Bureaucrat default constructor called!" << RESET << std::endl; } // Constructeur avec paramètres Bureaucrat::Bureaucrat(const std::string& name, int grade) :name(name), grade(grade) @@ -73,7 +73,8 @@ void Bureaucrat::incrementGrade() // Décrémente le grade void Bureaucrat::decrementGrade() { - if (grade >= 150) { + if (grade >= 150) + { throw GradeTooLowException(); } ++grade; @@ -81,12 +82,12 @@ void Bureaucrat::decrementGrade() // Méthodes pour les exceptions const char* Bureaucrat::GradeTooHighException::what() const throw() { - return "Grade too hight\n"; + return ("Grade too hight\n"); } const char* Bureaucrat::GradeTooLowException::what() const throw() { - return "Grade too low\n"; + return ("Grade too low\n"); } // Surcharge de l'opérateur << std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat) @@ -94,4 +95,3 @@ std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat) os << bureaucrat.getName() << " bureaucrat grade " << bureaucrat.getGrade(); return (os); } - diff --git a/cpp05/ex00/Bureaucrat.hpp b/cpp05/ex00/Bureaucrat.hpp index 8547078..cc93394 100644 --- a/cpp05/ex00/Bureaucrat.hpp +++ b/cpp05/ex00/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 12:57:28 by fgras-ca #+# #+# */ -/* Updated: 2024/02/14 14:32:41 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/16 16:39:04 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,35 +30,34 @@ class Bureaucrat { public: - class GradeTooHighException : public std::exception + class GradeTooHighException : public std::exception { - public: - const char* what() const throw() override; - }; + public: + const char* what() const throw() override; + }; - class GradeTooLowException : public std::exception + class GradeTooLowException : public std::exception { - public: - const char* what() const throw() override; - }; + public: + const char* what() const throw() override; + }; - Bureaucrat(); - Bureaucrat(const std::string& name, int grade); - Bureaucrat(const Bureaucrat& other); - Bureaucrat& operator=(const Bureaucrat& other); - ~Bureaucrat(); + Bureaucrat(); + Bureaucrat(const std::string& name, int grade); + Bureaucrat(const Bureaucrat& other); + Bureaucrat& operator=(const Bureaucrat& other); + ~Bureaucrat(); - std::string getName() const; - int getGrade() const; - void incrementGrade(); - void decrementGrade(); + std::string getName() const; + int getGrade() const; + void incrementGrade(); + void decrementGrade(); private: - const std::string name; - int grade; + const std::string name; + int grade; }; std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat); #endif - diff --git a/cpp05/ex00/Bureaucrat.o b/cpp05/ex00/Bureaucrat.o deleted file mode 100644 index b55510e..0000000 Binary files a/cpp05/ex00/Bureaucrat.o and /dev/null differ diff --git a/cpp05/ex00/main.cpp b/cpp05/ex00/main.cpp index 252fed9..ed32c1f 100644 --- a/cpp05/ex00/main.cpp +++ b/cpp05/ex00/main.cpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 13:28:49 by fgras-ca #+# #+# */ -/* Updated: 2024/02/14 14:37:10 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/16 16:48:36 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/cpp05/ex01/Bureaucrat.cpp b/cpp05/ex01/Bureaucrat.cpp index b8f3482..b1045fa 100644 --- a/cpp05/ex01/Bureaucrat.cpp +++ b/cpp05/ex01/Bureaucrat.cpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 13:16:26 by fgras-ca #+# #+# */ -/* Updated: 2024/02/14 14:38:10 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/16 17:30:32 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,7 @@ // Constructeur par défaut Bureaucrat::Bureaucrat() : name("Default"), grade(150) { - std::cout << GREEN << "Bureaucrat default constructor called!\n" << RESET << std::endl; + std::cout << GREEN << "Bureaucrat default constructor called!" << RESET << std::endl; } // Constructeur avec paramètres Bureaucrat::Bureaucrat(const std::string& name, int grade) :name(name), grade(grade) @@ -73,20 +73,34 @@ void Bureaucrat::incrementGrade() // Décrémente le grade void Bureaucrat::decrementGrade() { - if (grade >= 150) { + if (grade >= 150) + { throw GradeTooLowException(); } ++grade; } + +void Bureaucrat::signForm(Form& form) +{ + try + { + form.beSigned(*this); + std::cout << this->name << " signed " << form.getName() << std::endl; + } + catch (std::exception& e) + { + std::cout << this->name << " couldn’t sign " << form.getName() << " because " << e.what() << std::endl; + } +} // Méthodes pour les exceptions const char* Bureaucrat::GradeTooHighException::what() const throw() { - return "Grade too hight\n"; + return ("Grade too hight\n"); } const char* Bureaucrat::GradeTooLowException::what() const throw() { - return "Grade too low\n"; + return ("Grade too low\n"); } // Surcharge de l'opérateur << std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat) @@ -94,4 +108,3 @@ std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat) os << bureaucrat.getName() << " bureaucrat grade " << bureaucrat.getGrade(); return (os); } - diff --git a/cpp05/ex01/Bureaucrat.hpp b/cpp05/ex01/Bureaucrat.hpp index 8547078..99f03ed 100644 --- a/cpp05/ex01/Bureaucrat.hpp +++ b/cpp05/ex01/Bureaucrat.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 12:57:28 by fgras-ca #+# #+# */ -/* Updated: 2024/02/14 14:32:41 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/16 17:30:30 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,6 +16,7 @@ #include #include #include +#include "Form.hpp" #define RESET "\033[0m" #define BLACK "\033[30m" @@ -30,35 +31,35 @@ class Bureaucrat { public: - class GradeTooHighException : public std::exception + class GradeTooHighException : public std::exception { - public: - const char* what() const throw() override; - }; + public: + const char* what() const throw() override; + }; - class GradeTooLowException : public std::exception + class GradeTooLowException : public std::exception { - public: - const char* what() const throw() override; - }; + public: + const char* what() const throw() override; + }; - Bureaucrat(); - Bureaucrat(const std::string& name, int grade); - Bureaucrat(const Bureaucrat& other); - Bureaucrat& operator=(const Bureaucrat& other); - ~Bureaucrat(); + Bureaucrat(); + Bureaucrat(const std::string& name, int grade); + Bureaucrat(const Bureaucrat& other); + Bureaucrat& operator=(const Bureaucrat& other); + ~Bureaucrat(); - std::string getName() const; - int getGrade() const; - void incrementGrade(); - void decrementGrade(); + std::string getName() const; + int getGrade() const; + void incrementGrade(); + void decrementGrade(); + void signForm(Form& form); private: - const std::string name; - int grade; + const std::string name; + int grade; }; std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat); #endif - diff --git a/cpp05/ex01/Form.cpp b/cpp05/ex01/Form.cpp index 505f113..93a77cd 100644 --- a/cpp05/ex01/Form.cpp +++ b/cpp05/ex01/Form.cpp @@ -6,16 +6,17 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:39:51 by fgras-ca #+# #+# */ -/* Updated: 2024/02/11 16:05:55 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/16 18:19:00 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" #include "Form.hpp" -Form::Form(const std::string& name) +Form::Form() : name(name), isSigned(false), gradeRequiredToSign(1), gradeRequiredToExecute(1) { + std::cout << GREEN << "Form default constructor called!" << RESET << std::endl; } Form::Form(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute) @@ -34,15 +35,21 @@ Form::Form(const std::string &name, int gradeRequiredToSign, int gradeRequiredTo Form::Form(const Form& other) : name(other.name), isSigned(other.isSigned), gradeRequiredToSign(other.gradeRequiredToSign), gradeRequiredToExecute(other.gradeRequiredToExecute) { + std::cout << CYAN << "Copy constructor called for Form " << this->name << RESET << std::endl; } + Form& Form::operator=(const Form& other) { - (void)other; + if (this != &other) + { + this->isSigned = other.isSigned; + } return (*this); } Form::~Form() { + std::cout << RED << "Form " << this->name << " is destroyed!" << RESET << std::endl; } std::string Form::getName() const @@ -77,11 +84,21 @@ void Form::beSigned(const Bureaucrat& bureaucrat) } } +const char* Form::GradeTooHighException::what() const noexcept +{ + return ("Grade too hight\n"); +} + +const char* Form::GradeTooLowException::what() const noexcept +{ + return ("Grade too low\n"); +} + std::ostream& operator<<(std::ostream& os, const Form& form) { os << "Form: " << form.getName() << ", Status: " << (form.getIsSigned() ? "Signed" : "Not signed") << ", Grade Required to Sign: " << form.getGradeRequiredToSign() << ", Grade Required to Execute: " << form.getGradeRequiredToExecute(); - return os; + return (os); } diff --git a/cpp05/ex01/Form.hpp b/cpp05/ex01/Form.hpp index 28798e9..d9efcd9 100644 --- a/cpp05/ex01/Form.hpp +++ b/cpp05/ex01/Form.hpp @@ -6,7 +6,7 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:37:14 by fgras-ca #+# #+# */ -/* Updated: 2024/02/12 14:43:02 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/16 18:26:09 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,14 +23,13 @@ class Form { private: const std::string name; - const bool isSigned; const int gradeRequiredToSign; const int gradeRequiredToExecute; public: //constructueur - Form(const::std::string& name); + Form(); Form(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute); // Constructeur par copie Form(const Form& other); @@ -50,19 +49,13 @@ public: class GradeTooHighException : public std::exception { public: - const char* what() const noexcept override - { - return ("Grade too high"); - } + const char* what() const noexcept override; }; class GradeTooLowException : public std::exception { public: - const char* what() const noexcept override - { - return ("Grade too low"); - } + const char* what() const noexcept override; }; }; diff --git a/cpp05/ex02/AForm.cpp b/cpp05/ex02/AForm.cpp new file mode 100644 index 0000000..af28bce --- /dev/null +++ b/cpp05/ex02/AForm.cpp @@ -0,0 +1,104 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* AForm.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: fgras-ca +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/02/11 14:39:51 by fgras-ca #+# #+# */ +/* Updated: 2024/02/16 18:44:23 by fgras-ca ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Bureaucrat.hpp" +#include "AForm.hpp" + +AForm::AForm() + : name(name), isSigned(false), gradeRequiredToSign(1), gradeRequiredToExecute(1) +{ + std::cout << GREEN << "AForm default constructor called!" << RESET << std::endl; +} + +AForm::AForm(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute) + : name(name), isSigned(false), gradeRequiredToSign(gradeRequiredToSign), gradeRequiredToExecute(gradeRequiredToExecute) +{ + if (gradeRequiredToSign < 1 || gradeRequiredToExecute < 1) + { + throw GradeTooHighException(); + } + else if (gradeRequiredToSign > 150 || gradeRequiredToExecute > 150) + { + throw GradeTooLowException(); + } +} + +AForm::AForm(const AForm& other) + : name(other.name), isSigned(other.isSigned), gradeRequiredToSign(other.gradeRequiredToSign), gradeRequiredToExecute(other.gradeRequiredToExecute) +{ + std::cout << CYAN << "Copy constructor called for AForm " << this->name << RESET << std::endl; +} + +AForm& AForm::operator=(const AForm& other) +{ + if (this != &other) + { + this->isSigned = other.isSigned; + } + return (*this); +} + +AForm::~AForm() +{ + std::cout << RED << "AForm " << this->name << " is destroyed!" << RESET << std::endl; +} + +std::string AForm::getName() const +{ + return (name); +} + +bool AForm::getIsSigned() const +{ + return (isSigned); +} + +int AForm::getGradeRequiredToSign() const +{ + return (gradeRequiredToSign); +} + +int AForm::getGradeRequiredToExecute() const +{ + return (gradeRequiredToExecute); +} + +void AForm::beSigned(const Bureaucrat& bureaucrat) +{ + if (bureaucrat.getGrade() <= gradeRequiredToSign) + { + isSigned = true; + } + else + { + throw GradeTooLowException(); + } +} + +const char* AForm::GradeTooHighException::what() const noexcept +{ + return ("Grade too hight\n"); +} + +const char* AForm::GradeTooLowException::what() const noexcept +{ + return ("Grade too low\n"); +} + +std::ostream& operator<<(std::ostream& os, const AForm& aform) +{ + os << "AForm: " << aform.getName() + << ", Status: " << (aform.getIsSigned() ? "Signed" : "Not signed") + << ", Grade Required to Sign: " << aform.getGradeRequiredToSign() + << ", Grade Required to Execute: " << aform.getGradeRequiredToExecute(); + return (os); +} diff --git a/cpp05/ex02/Form.hpp b/cpp05/ex02/AForm.hpp similarity index 64% rename from cpp05/ex02/Form.hpp rename to cpp05/ex02/AForm.hpp index c2c1a20..ebd02ac 100644 --- a/cpp05/ex02/Form.hpp +++ b/cpp05/ex02/AForm.hpp @@ -1,17 +1,17 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* Form.hpp :+: :+: :+: */ +/* AForm.hpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 14:37:14 by fgras-ca #+# #+# */ -/* Updated: 2024/02/11 15:05:06 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/16 18:50:37 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ -#ifndef FORM_HPP -#define FORM_HPP +#ifndef AFORM_HPP +#define AFORM_HPP #include "Bureaucrat.hpp" // Assurez-vous que cette classe est bien définie #include @@ -19,7 +19,7 @@ class Bureaucrat; -class Form +class AForm { private: const std::string name; @@ -28,33 +28,38 @@ private: const int gradeRequiredToExecute; public: - Form(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute); + //constructueur + AForm(); + AForm(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute); + // Constructeur par copie + AForm(const AForm& other); + // Opérateur d'affectation + virtual AForm& operator=(const AForm& other); + // Destructeur + virtual ~AForm(); + + std::string getName() const; bool getIsSigned() const; int getGradeRequiredToSign() const; int getGradeRequiredToExecute() const; - void beSigned(const Bureaucrat& bureaucrat); + virtual void beSigned(const Bureaucrat& bureaucrat); class GradeTooHighException : public std::exception { public: - const char* what() const noexcept override - { - return ("Grade too high"); - } + const char* what() const noexcept override; }; class GradeTooLowException : public std::exception { public: - const char* what() const noexcept override - { - return ("Grade too low"); - } + const char* what() const noexcept override; }; }; -std::ostream& operator<<(std::ostream& os, const Form& form); +// Surcharge de l'opérateur d'insertion +std::ostream& operator<<(std::ostream& os, const AForm& aform); #endif diff --git a/cpp05/ex02/Bureaucrat.cpp b/cpp05/ex02/Bureaucrat.cpp index b6f86a0..b1045fa 100644 --- a/cpp05/ex02/Bureaucrat.cpp +++ b/cpp05/ex02/Bureaucrat.cpp @@ -6,14 +6,19 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 13:16:26 by fgras-ca #+# #+# */ -/* Updated: 2024/02/11 14:50:15 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/16 17:30:32 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #include "Bureaucrat.hpp" -#include "Form.hpp" -Bureaucrat::Bureaucrat(const std::string &nom, int grade) : name(nom) +// Constructeur par défaut +Bureaucrat::Bureaucrat() : name("Default"), grade(150) +{ + std::cout << GREEN << "Bureaucrat default constructor called!" << RESET << std::endl; +} +// Constructeur avec paramètres +Bureaucrat::Bureaucrat(const std::string& name, int grade) :name(name), grade(grade) { if (grade < 1) { @@ -24,18 +29,39 @@ Bureaucrat::Bureaucrat(const std::string &nom, int grade) : name(nom) throw GradeTooLowException(); } this->grade = grade; + std::cout << GREEN << "Bureaucrat " << this->name << " constructor called with grade " << this->grade << RESET << std::endl; } - +// Constructeur de copie +Bureaucrat::Bureaucrat(const Bureaucrat& other) : name(other.name), grade(other.grade) +{ + std::cout << CYAN << "Copy constructor called for Bureaucrat " << this->name << RESET << std::endl; +} +// Opérateur d'affectation +Bureaucrat& Bureaucrat::operator=(const Bureaucrat& other) +{ + if (this != &other) + { + // L'attribut name étant const, nous ne pouvons pas le modifier. Seul grade est copié. + this->grade = other.grade; + } + return (*this); +} +// Destructeur +Bureaucrat::~Bureaucrat() +{ + std::cout << RED << "Bureaucrat " << this->name << " is destroyed!" << RESET << std::endl; +} +// Getter pour le nom std::string Bureaucrat::getName() const { - return (name); + return (this->name); } - +// Getter pour le grade int Bureaucrat::getGrade() const { - return (grade); + return (this->grade); } - +// Incrémente le grade void Bureaucrat::incrementGrade() { if (grade <= 1) @@ -44,7 +70,7 @@ void Bureaucrat::incrementGrade() } --grade; } - +// Décrémente le grade void Bureaucrat::decrementGrade() { if (grade >= 150) @@ -60,14 +86,25 @@ void Bureaucrat::signForm(Form& form) { form.beSigned(*this); std::cout << this->name << " signed " << form.getName() << std::endl; - } catch (std::exception& e) + } + catch (std::exception& e) { std::cout << this->name << " couldn’t sign " << form.getName() << " because " << e.what() << std::endl; } } - -std::ostream& operator<<(std::ostream &os, const Bureaucrat &bureaucrat) +// Méthodes pour les exceptions +const char* Bureaucrat::GradeTooHighException::what() const throw() { - os << bureaucrat.getName() << MAGENTA << ", bureaucrat grade " << RESET << bureaucrat.getGrade(); + return ("Grade too hight\n"); +} + +const char* Bureaucrat::GradeTooLowException::what() const throw() +{ + return ("Grade too low\n"); +} +// Surcharge de l'opérateur << +std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat) +{ + os << bureaucrat.getName() << " bureaucrat grade " << bureaucrat.getGrade(); return (os); } diff --git a/cpp05/ex02/Bureaucrat.hpp b/cpp05/ex02/Bureaucrat.hpp index 350c481..34fca77 100644 --- a/cpp05/ex02/Bureaucrat.hpp +++ b/cpp05/ex02/Bureaucrat.hpp @@ -6,66 +6,60 @@ /* By: fgras-ca +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/02/11 12:57:28 by fgras-ca #+# #+# */ -/* Updated: 2024/02/11 14:59:51 by fgras-ca ### ########.fr */ +/* Updated: 2024/02/16 18:26:55 by fgras-ca ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef BUREAUCRAT_HPP #define BUREAUCRAT_HPP -#include "Form.hpp" #include #include #include +#include "AForm.hpp" -#define RESET "\033[0m" -#define BLACK "\033[30m" -#define RED "\033[31m" -#define GREEN "\033[32m" -#define YELLOW "\033[33m" -#define BLUE "\033[34m" -#define MAGENTA "\033[35m" -#define CYAN "\033[36m" -#define WHITE "\033[37m" +#define RESET "\033[0m" +#define BLACK "\033[30m" +#define RED "\033[31m" +#define GREEN "\033[32m" +#define YELLOW "\033[33m" +#define BLUE "\033[34m" +#define MAGENTA "\033[35m" +#define CYAN "\033[36m" +#define WHITE "\033[37m" class Bureaucrat { public: class GradeTooHighException : public std::exception { - public: - const char* what() const throw() override - { - return ("Grade trop élevé"); - } + public: + const char* what() const throw() override; }; class GradeTooLowException : public std::exception { - public: - const char* what() const throw() override - { - return ("Grade trop bas"); - } + public: + const char* what() const throw() override; }; -private: - const std::string name; - int grade; - -public: - Bureaucrat(const std::string &nom, int grade); // Constructeur - Bureaucrat(const Bureaucrat& other) = default; // Constructeur par copie - Bureaucrat& operator=(const Bureaucrat& other) = default; // Opérateur d'affectation - ~Bureaucrat() = default; // Destructeur + Bureaucrat(); + Bureaucrat(const std::string& name, int grade); + Bureaucrat(const Bureaucrat& other); + Bureaucrat& operator=(const Bureaucrat& other); + ~Bureaucrat(); std::string getName() const; int getGrade() const; void incrementGrade(); void decrementGrade(); void signForm(Form& form); + +private: + const std::string name; + int grade; }; -std::ostream& operator<<(std::ostream &os, const Bureaucrat &bureaucrat); +std::ostream& operator<<(std::ostream& os, const Bureaucrat& bureaucrat); #endif diff --git a/cpp05/ex02/Form.cpp b/cpp05/ex02/Form.cpp deleted file mode 100644 index a632799..0000000 --- a/cpp05/ex02/Form.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* Form.cpp :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: fgras-ca +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2024/02/11 14:39:51 by fgras-ca #+# #+# */ -/* Updated: 2024/02/11 15:03:38 by fgras-ca ### ########.fr */ -/* */ -/* ************************************************************************** */ - -#include "Bureaucrat.hpp" -#include "Form.hpp" - -Form::Form(const std::string &name, int gradeRequiredToSign, int gradeRequiredToExecute) -: name(name), isSigned(false), gradeRequiredToSign(gradeRequiredToSign), gradeRequiredToExecute(gradeRequiredToExecute) -{ - if (gradeRequiredToSign < 1 || gradeRequiredToExecute < 1) - { - throw GradeTooHighException(); - } - else if (gradeRequiredToSign > 150 || gradeRequiredToExecute > 150) - { - throw GradeTooLowException(); - } -} - -std::string Form::getName() const -{ - return (name); -} - -bool Form::getIsSigned() const -{ - return (isSigned); -} - -int Form::getGradeRequiredToSign() const -{ - return (gradeRequiredToSign); -} - -int Form::getGradeRequiredToExecute() const -{ - return (gradeRequiredToExecute); -} - -void Form::beSigned(const Bureaucrat& bureaucrat) -{ - if (bureaucrat.getGrade() <= gradeRequiredToSign) - { - isSigned = true; - } - else - { - throw GradeTooLowException(); - } -} - -std::ostream& operator<<(std::ostream& os, const Form& form) -{ - os << "Form: " << form.getName() - << ", Status: " << (form.getIsSigned() ? "Signed" : "Not signed") - << ", Grade Required to Sign: " << form.getGradeRequiredToSign() - << ", Grade Required to Execute: " << form.getGradeRequiredToExecute(); - return os; -} diff --git a/cpp05/ex02/Makefile b/cpp05/ex02/Makefile index d41a303..ca845c0 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/11 14:58:41 by fgras-ca ### ########.fr # +# Updated: 2024/02/16 18:36:25 by fgras-ca ### ########.fr # # # # **************************************************************************** # @@ -26,7 +26,7 @@ ORANGE = \033[38;5;214m NAME = Form SRC = Bureaucrat.cpp \ - Form.cpp \ + AForm.cpp \ main.cpp \ OBJS = ${SRC:.cpp=.o}