92 lines
2.6 KiB
C++
92 lines
2.6 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* Intern.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/02/21 12:14:13 by aortigos #+# #+# */
|
|
/* Updated: 2026/02/21 12:14:13 by aortigos ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "Intern.hpp"
|
|
|
|
//////////////////
|
|
// Constructors //
|
|
//////////////////
|
|
|
|
Intern::Intern()
|
|
{
|
|
// std::cout << "Intern default constructor called" << std::endl;
|
|
}
|
|
|
|
Intern::Intern(const Intern &other)
|
|
{
|
|
(void)other; // No atributes for copying
|
|
// std::cout << "Intern copy constructor called" << std::endl;
|
|
}
|
|
|
|
Intern& Intern::operator=(const Intern &other)
|
|
{
|
|
(void)other; // No atributes for copying
|
|
// std::cout << "Intern copy assignment operator called" << std::endl;
|
|
return (*this);
|
|
}
|
|
|
|
Intern::~Intern()
|
|
{
|
|
// std::cout << "Intern destructor called" << std::endl;
|
|
}
|
|
|
|
|
|
//////////////////
|
|
// Creators //
|
|
//////////////////
|
|
|
|
AForm* Intern::createShrubbery(const std::string &target)
|
|
{
|
|
return new ShrubberyCreationForm(target);
|
|
}
|
|
|
|
AForm* Intern::createRobotomy(const std::string &target)
|
|
{
|
|
return new RobotomyRequestForm(target);
|
|
}
|
|
|
|
AForm* Intern::createPardon(const std::string &target)
|
|
{
|
|
return new PresidentialPardonForm(target);
|
|
}
|
|
|
|
AForm* Intern::makeForm(const std::string &formName, const std::string &target)
|
|
{
|
|
std::string formNames[3] = {
|
|
"shrubbery creation",
|
|
"robotomy request",
|
|
"presidential pardon"
|
|
};
|
|
|
|
typedef AForm* (Intern::*FormCreator)(const std::string&);
|
|
FormCreator creators[3] = {
|
|
&Intern::createShrubbery,
|
|
&Intern::createShrubbery,
|
|
&Intern::createPardon
|
|
};
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
if (formName == formNames[i])
|
|
{
|
|
std::cout << "Intern creates "
|
|
<< formName
|
|
<< std::endl;
|
|
return (this->*creators[i])(target);
|
|
}
|
|
}
|
|
std::cout << "Intern cannot create \"" << formName
|
|
<< "\" because it doesn't exist"
|
|
<< std::endl;
|
|
return (NULL);
|
|
}
|