| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* Intern.cpp :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2025/12/31 15:40:42 by bchanot #+# #+# */
- /* Updated: 2025/12/31 17:59:26 by bchanot ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include "Intern.hpp"
- /*
- ** ------------------------------- CONSTRUCTOR --------------------------------
- */
- Intern::Intern()
- {
- }
- Intern::Intern( const Intern & src )
- {
- (void)src;
- }
- /*
- ** -------------------------------- DESTRUCTOR --------------------------------
- */
- Intern::~Intern()
- {
- }
- /*
- ** --------------------------------- OVERLOAD ---------------------------------
- */
- Intern & Intern::operator=( Intern const & rhs )
- {
- (void)rhs;
- //if ( this != &rhs )
- //{
- //this->_value = rhs.getValue();
- //}
- return *this;
- }
- std::ostream & operator<<( std::ostream & o, Intern const & i )
- {
- (void)i;
- //o << "Value = " << i.getValue();
- return o;
- }
- /*
- ** --------------------------------- METHODS ----------------------------------
- */
- AForm *Intern::makePresidentialPardonForm(std::string const & target) const { return new PresidentialPardonForm(target); }
- AForm *Intern::makeRobotomyRequest(std::string const & target) const { return new RobotomyRequestForm(target); }
- AForm *Intern::makeShrubberyCreation(std::string const & target) const { return new ShrubberyCreationForm(target); }
- AForm *Intern::makeForm(std::string const & name, std::string const & target) {
- size_t size;
- typedef AForm *(Intern::*t_form)(std::string const & target) const;
- typedef struct {std::string name; t_form createForm;} nameForm;
-
- nameForm tab[] = {
- {"Presidential pardon", &Intern::makePresidentialPardonForm},
- {"Robotomy request", &Intern::makeRobotomyRequest},
- {"Shrubbery creation", &Intern::makeShrubberyCreation}
- };
- size = sizeof(tab)/sizeof(nameForm);
- for (size_t i = 0; i < size; i++) {
- if (name == tab[i].name) {
- std::cout << "Intern creates " << name << std::endl;
- return (this->*tab[i].createForm)(target);
- }
- }
- std::cout << "Cannot find the form " << name << std::endl;
- throw NotFoundException();
- }
- /*
- ** --------------------------------- ACCESSOR ---------------------------------
- */
- /* ************************************************************************** */
|