ajout ex03 et correction dump core

This commit is contained in:
Hugo LAMY
2022-03-17 11:12:31 +01:00
parent bac6161af8
commit 5f090531bc
20 changed files with 1053 additions and 4 deletions

View File

@@ -0,0 +1,54 @@
#ifndef AFORM_HPP
# define AFORM_HPP
# include "color.h"
# include <iostream>
# include <string>
class Bureaucrat;
# include "Bureaucrat.hpp"
class AForm {
public:
AForm( std::string name, std::string target, int signedGrade, int executeGrade );
AForm( AForm const & src );
virtual ~AForm() = 0;
AForm & operator=( AForm const & rhs );
std::string getName() const;
std::string getTarget() const;
bool getSigned() const;
int getSignedGrade() const;
int getExecuteGrade() const;
void beSigned( Bureaucrat const & b );
void execute(Bureaucrat const & executor) const;
virtual void formAction() const = 0;
private:
AForm();
protected:
class GradeTooHighException : public std::exception {
const char * what() const throw();};
class GradeTooLowException : public std::exception {
const char * what() const throw();};
class NotSignedException : public std::exception {
const char * what() const throw();};
std::string const _name;
std::string const _target;
bool _signed;
int const _signedGrade;
int const _executeGrade;
};
std::ostream & operator<<(std::ostream & o, AForm const & rhs);
#endif

View File

@@ -0,0 +1,48 @@
#ifndef BUREAUCRAT_HPP
# define BUREAUCRAT_HPP
# include "color.h"
# include <iostream>
# include <string>
# include <stdexcept>
class AForm;
# include "AForm.hpp"
class Bureaucrat {
public:
Bureaucrat(std::string name, int grade);
Bureaucrat( Bureaucrat const & src );
~Bureaucrat();
Bureaucrat & operator=( Bureaucrat const & rhs );
std::string getName() const;
int getGrade() const;
void gradeUp();
void gradeDown();
void signForm( AForm & f );
void executeForm( AForm const & form );
protected:
std::string const _name;
int _grade;
private:
Bureaucrat();
class GradeTooHighException : public std::exception {
const char * what() const throw();};
class GradeTooLowException : public std::exception {
const char * what() const throw();};
};
std::ostream & operator<<(std::ostream & o, Bureaucrat const & rhs);
#endif

View File

@@ -0,0 +1,40 @@
#ifndef INTERN_HPP
# define INTERN_HPP
# include "colors.h"
# include <iostream>
# include <string>
# include <AForm.hpp>
# include <ShrubberyCreationForm.hpp>
# include <PresidentialPardonForm.hpp>
# include <RobotomyRequestForm.hpp>
typedef AForm * (*t_func)(std::string const & target);
typedef struct s_formModel {
std::string const name;
t_func const create;
} t_formModel;
class Intern {
public:
Intern();
Intern( Intern const & src );
~Intern();
Intern & operator=( Intern const & rhs );
AForm * makeForm(std::string formName, std::string formTarget) const;
private:
static const t_formModel _chooseForm[];
static AForm * makeShrubbery(std::string const &target);
static AForm * makePresidential(std::string const &target);
static AForm * makeRobotomy(std::string const &target);
};
#endif

View File

@@ -0,0 +1,28 @@
#ifndef PRESIDENTIALPARDONFORM_HPP
# define PRESIDENTIALPARDONFORM_HPP
# include "color.h"
# include <iostream>
# include <string>
# include <cstdlib>
# include "AForm.hpp"
class PresidentialPardonForm : public AForm {
public:
PresidentialPardonForm( std::string target );
PresidentialPardonForm( PresidentialPardonForm const & src );
~PresidentialPardonForm();
PresidentialPardonForm & operator=( PresidentialPardonForm const & rhs );
void formAction() const;
private:
PresidentialPardonForm();
};
#endif

View File

@@ -0,0 +1,28 @@
#ifndef ROBOTOMYREQUESTFORM_HPP
# define ROBOTOMYREQUESTFORM_HPP
# include "color.h"
# include <iostream>
# include <string>
# include <cstdlib>
# include "AForm.hpp"
class RobotomyRequestForm : public AForm {
public:
RobotomyRequestForm( std::string target );
RobotomyRequestForm( RobotomyRequestForm const & src );
~RobotomyRequestForm();
RobotomyRequestForm & operator=( RobotomyRequestForm const & rhs );
void formAction() const;
private:
RobotomyRequestForm();
};
#endif

View File

@@ -0,0 +1,28 @@
#ifndef SHRUBBERYCREATIONFORM_HPP
# define SHRUBBERYCREATIONFORM_HPP
# include "color.h"
# include <iostream>
# include <string>
# include <fstream>
# include "AForm.hpp"
class ShrubberyCreationForm : public AForm {
public:
ShrubberyCreationForm( std::string target );
ShrubberyCreationForm( ShrubberyCreationForm const & src );
~ShrubberyCreationForm();
ShrubberyCreationForm & operator=( ShrubberyCreationForm const & rhs );
void formAction() const;
private:
ShrubberyCreationForm();
};
#endif

25
d05/ex03/headers/color.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef COLOR_H
# define COLOR_H
# define GRAY "\e[0;30m"
# define RED "\e[0;31m"
# define GREEN "\e[0;32m"
# define YELLOW "\e[0;33m"
# define BLUE "\e[0;34m"
# define PURPLE "\e[0;35m"
# define CYAN "\e[0;36m"
# define WHITE "\e[0;37m"
# define B_GRAY "\e[1;30m"
# define B_RED "\e[1;31m"
# define B_GREEN "\e[1;32m"
# define B_YELLOW "\e[1;33m"
# define B_BLUE "\e[1;34m"
# define B_PURPLE "\e[1;35m"
# define B_CYAN "\e[1;36m"
# define B_WHITE "\e[1;37m"
# define RESET "\e[0m"
#endif

25
d05/ex03/headers/colors.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef COLORS_H
# define COLORS_H
# define GRAY "\e[0;30m"
# define RED "\e[0;31m"
# define GREEN "\e[0;32m"
# define YELLOW "\e[0;33m"
# define BLUE "\e[0;34m"
# define PURPLE "\e[0;35m"
# define CYAN "\e[0;36m"
# define WHITE "\e[0;37m"
# define B_GRAY "\e[1;30m"
# define B_RED "\e[1;31m"
# define B_GREEN "\e[1;32m"
# define B_YELLOW "\e[1;33m"
# define B_BLUE "\e[1;34m"
# define B_PURPLE "\e[1;35m"
# define B_CYAN "\e[1;36m"
# define B_WHITE "\e[1;37m"
# define RESET "\e[0m"
#endif