Something went wrong. Try again.
Java--'s try/catch projects.intra.42.fr/projects/cpp-module-05
Something went wrong. Try again.
1.9 kB · 67 lines
C++
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768#include <Intern.hpp>#include <ShrubberyCreationForm.hpp>#include <RobotomyRequestForm.hpp>#include <PresidentialPardonForm.hpp>
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";}