64 lines
2.2 KiB
C++
64 lines
2.2 KiB
C++
/* ************************************************************************** */
|
||
/* */
|
||
/* ::: :::::::: */
|
||
/* Intern.cpp :+: :+: :+: */
|
||
/* +:+ +:+ +:+ */
|
||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||
/* +#+#+#+#+#+ +#+ */
|
||
/* Created: 2025/04/03 15:24:46 by adjoly #+# #+# */
|
||
/* Updated: 2025/04/03 15:57:18 by adjoly ### ########.fr */
|
||
/* */
|
||
/* ************************************************************************** */
|
||
|
||
#include "Intern.hpp"
|
||
#include "Bureaucrat.hpp"
|
||
#include "PresidentialPardonForm.hpp"
|
||
#include "RobotomyRequestForm.hpp"
|
||
#include "ShrubberyCreationForm.hpp"
|
||
#include <cstddef>
|
||
|
||
Intern::Intern(void) {
|
||
_log("➕", "Intern", "", "default constructor called");
|
||
}
|
||
|
||
Intern::Intern(const Intern &cpy) {
|
||
_log("➕", "Intern", "", "copy constructor called");
|
||
*this = cpy;
|
||
}
|
||
|
||
Intern::~Intern(void) {
|
||
_log("➖", "Intern", "", "destructor called");
|
||
}
|
||
|
||
Intern &Intern::operator=(const Intern &) {
|
||
_log("➕", "Intern", "", "copy assignement constructor called");
|
||
return *this;
|
||
}
|
||
|
||
AForm *newShrubbery(std::string &target) {
|
||
return new ShrubberyCreationForm(target);
|
||
}
|
||
|
||
AForm *newPresidential(std::string &target) {
|
||
return new PresidentialPardonForm(target);
|
||
}
|
||
|
||
AForm *newRobotomy(std::string &target) {
|
||
return new RobotomyRequestForm(target);
|
||
}
|
||
|
||
AForm *Intern::makeForm(std::string name, std::string target) const {
|
||
std::string formName[] = {"robotomy request", "shrubbery request", "presidential pardon request"};
|
||
AForm *(*newForm[])(std::string &) = {&newRobotomy, &newShrubbery, &newPresidential};
|
||
|
||
for (size_t i = 0; i < 3; i++) {
|
||
if (formName[i] == name) {
|
||
AForm *n = newForm[i](target);
|
||
std::cout << "Intern creates " << name << std::endl;
|
||
return n;
|
||
}
|
||
}
|
||
std::cerr << "Intern doesn't know " << name << std::endl;
|
||
return NULL;
|
||
}
|