Intern.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* Intern.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/12/31 15:40:42 by bchanot #+# #+# */
  9. /* Updated: 2025/12/31 17:59:26 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "Intern.hpp"
  13. /*
  14. ** ------------------------------- CONSTRUCTOR --------------------------------
  15. */
  16. Intern::Intern()
  17. {
  18. }
  19. Intern::Intern( const Intern & src )
  20. {
  21. (void)src;
  22. }
  23. /*
  24. ** -------------------------------- DESTRUCTOR --------------------------------
  25. */
  26. Intern::~Intern()
  27. {
  28. }
  29. /*
  30. ** --------------------------------- OVERLOAD ---------------------------------
  31. */
  32. Intern & Intern::operator=( Intern const & rhs )
  33. {
  34. (void)rhs;
  35. //if ( this != &rhs )
  36. //{
  37. //this->_value = rhs.getValue();
  38. //}
  39. return *this;
  40. }
  41. std::ostream & operator<<( std::ostream & o, Intern const & i )
  42. {
  43. (void)i;
  44. //o << "Value = " << i.getValue();
  45. return o;
  46. }
  47. /*
  48. ** --------------------------------- METHODS ----------------------------------
  49. */
  50. AForm *Intern::makePresidentialPardonForm(std::string const & target) const { return new PresidentialPardonForm(target); }
  51. AForm *Intern::makeRobotomyRequest(std::string const & target) const { return new RobotomyRequestForm(target); }
  52. AForm *Intern::makeShrubberyCreation(std::string const & target) const { return new ShrubberyCreationForm(target); }
  53. AForm *Intern::makeForm(std::string const & name, std::string const & target) {
  54. size_t size;
  55. typedef AForm *(Intern::*t_form)(std::string const & target) const;
  56. typedef struct {std::string name; t_form createForm;} nameForm;
  57. nameForm tab[] = {
  58. {"Presidential pardon", &Intern::makePresidentialPardonForm},
  59. {"Robotomy request", &Intern::makeRobotomyRequest},
  60. {"Shrubbery creation", &Intern::makeShrubberyCreation}
  61. };
  62. size = sizeof(tab)/sizeof(nameForm);
  63. for (size_t i = 0; i < size; i++) {
  64. if (name == tab[i].name) {
  65. std::cout << "Intern creates " << name << std::endl;
  66. return (this->*tab[i].createForm)(target);
  67. }
  68. }
  69. std::cout << "Cannot find the form " << name << std::endl;
  70. throw NotFoundException();
  71. }
  72. /*
  73. ** --------------------------------- ACCESSOR ---------------------------------
  74. */
  75. /* ************************************************************************** */