#include #include #include #include Intern::Intern() { std::cout << "Intern default constructor called" << std::endl; } Intern::Intern(const Intern& other) { (void)other; std::cout << "Intern copy constructor called" << std::endl; } AForm* Intern::makeForm(const std::string& formName, const std::string& target) const { typedef AForm* (Intern::*FormCreator)(const std::string& target) const; struct FormEntry { const char* name; FormCreator creator; }; static const FormEntry entries[] = { { "shrubbery creation", &Intern::createShrubberyCreationForm }, { "robotomy request", &Intern::createRobotomyRequestForm }, { "presidential pardon", &Intern::createPresidentialPardonForm } }; for (size_t i = 0; i < sizeof(entries) / sizeof(entries[0]); i++) { if (formName == entries[i].name) { AForm* form = (this->*entries[i].creator)(target); std::cout << "Intern creates " << form->getName() << std::endl; return form; } } std::cout << "Intern couldn't create " << formName << " because the form does not exist" << std::endl; throw UnknownFormException(); } AForm* Intern::createShrubberyCreationForm(const std::string& target) const { return new ShrubberyCreationForm(target); } AForm* Intern::createRobotomyRequestForm(const std::string& target) const { return new RobotomyRequestForm(target); } AForm* Intern::createPresidentialPardonForm(const std::string& target) const { return new PresidentialPardonForm(target); } Intern& Intern::operator=(const Intern& other) { std::cout << "Intern assignment operator called" << std::endl; (void)other; return *this; } Intern::~Intern() { std::cout << "Intern destructor called" << std::endl; } const char* Intern::UnknownFormException::what() const throw() { return "Form does not exist"; }