69 lines
1.6 KiB
C++
69 lines
1.6 KiB
C++
#include "Intern.hpp"
|
|
|
|
#include <string>
|
|
|
|
#include "AForm.hpp"
|
|
#include "PresidentialPardonForm.hpp"
|
|
#include "RobotomyRequestForm.hpp"
|
|
#include "ShrubberyCreationForm.hpp"
|
|
|
|
#include "colors.h"
|
|
|
|
Intern::Intern()
|
|
{
|
|
std::cout << INTERN CONSTRUCTOR << std::endl;
|
|
}
|
|
|
|
Intern::Intern(const Intern &other)
|
|
{
|
|
(void)other;
|
|
std::cout << INTERN COPY_CONSTRUCTOR << std::endl;
|
|
}
|
|
|
|
Intern &Intern::operator=(const Intern &other)
|
|
{
|
|
if (this != &other)
|
|
{
|
|
std::cout << INTERN ASSIGNMENT_OPERATOR << std::endl;
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
Intern::~Intern()
|
|
{
|
|
std::cout << INTERN DESTRUCTOR << std::endl;
|
|
}
|
|
|
|
AForm *Intern::createShrubberyForm(const std::string &target)
|
|
{
|
|
return new ShrubberyCreationForm(target);
|
|
}
|
|
|
|
AForm *Intern::createRobotomyForm(const std::string &target)
|
|
{
|
|
return new RobotomyRequestForm(target);
|
|
}
|
|
|
|
AForm *Intern::createPresidentialForm(const std::string &target)
|
|
{
|
|
return new PresidentialPardonForm(target);
|
|
}
|
|
|
|
AForm *Intern::makeForm(const std::string &formName, const std::string &target)
|
|
{
|
|
std::string formTypeStrs[3] = {"shrubbery creation", "robotomy request",
|
|
"presidential pardon"};
|
|
// Array of factory functions
|
|
AForm *(*formFactories[3])(const std::string &) = {
|
|
Intern::createShrubberyForm, Intern::createRobotomyForm,
|
|
Intern::createPresidentialForm};
|
|
|
|
for (int i = 0; i < 3; ++i)
|
|
{
|
|
if (formName == formTypeStrs[i])
|
|
return formFactories[i](target);
|
|
}
|
|
std::cout << "Unknown form type: " << formName << std::endl;
|
|
return nullptr;
|
|
}
|