diff --git a/d05/ex03/headers/Intern.hpp b/d05/ex03/headers/Intern.hpp index 59b03d5..44d462b 100644 --- a/d05/ex03/headers/Intern.hpp +++ b/d05/ex03/headers/Intern.hpp @@ -4,6 +4,8 @@ # include "colors.h" # include # include +# include // trasnform +# include // tolower # include # include @@ -34,6 +36,8 @@ private: static AForm * makePresidential(std::string const &target); static AForm * makeRobotomy(std::string const &target); + bool isValidForm(std::string name, unsigned int i) const; + }; #endif diff --git a/d05/ex03/interns b/d05/ex03/interns new file mode 100755 index 0000000..89553cc Binary files /dev/null and b/d05/ex03/interns differ diff --git a/d05/ex03/main.cpp b/d05/ex03/main.cpp index e91fc1d..efea552 100644 --- a/d05/ex03/main.cpp +++ b/d05/ex03/main.cpp @@ -142,39 +142,49 @@ int main() { AForm * f2; AForm * f3; AForm * f4; + AForm * f5; - std::cout << B_BLUE "intern tries to create a Shrubbery form" RESET "\n"; + std::cout << B_BLUE "\nintern tries to create a Shrubbery form" RESET "\n"; f1 = i.makeForm("Shrubbery", "smoking"); if (f1) std::cout << *f1 << '\n'; else - std::cout << "intern make an error and cannot create the form\n"; + std::cout << "intern makes an error and cannot create the form\n"; std::cout << B_BLUE "\nintern tries to create a Robotomy form" RESET "\n"; f2 = i.makeForm("Robotomy", "building"); if (f2) std::cout << *f2 << '\n'; else - std::cout << "intern make an error and cannot create the form\n"; + std::cout << "intern makes an error and cannot create the form\n"; std::cout << B_BLUE "\nintern tries to create a Presidential form" RESET "\n"; f3 = i.makeForm("Presidential", "building"); if (f3) std::cout << *f3 << '\n'; else - std::cout << "intern make an error and cannot create the form\n"; + std::cout << "intern makes an error and cannot create the form\n"; std::cout << B_BLUE "\nintern tries to create a blueberry form" RESET "\n"; f4 = i.makeForm("blueberry", "giv_me_gold"); if (f4) std::cout << *f4 << '\n'; else - std::cout << "intern make an error and cannot create the form\n"; + std::cout << "intern makes an error and cannot create the form\n"; + std::cout << B_BLUE "\nintern tries to create a \"robotomy request\" form" RESET "\n"; + f5 = i.makeForm("robotomy request", "try_hard"); + if (f5) + std::cout << *f5 << '\n'; + else + std::cout << "intern makes an error and cannot create the form\n"; + + std::cout << '\n'; delete f1; delete f2; delete f3; delete f4; + delete f5; } std::cout << "\n"; diff --git a/d05/ex03/sekoia_shrubbery b/d05/ex03/sekoia_shrubbery new file mode 100644 index 0000000..5a1591f --- /dev/null +++ b/d05/ex03/sekoia_shrubbery @@ -0,0 +1,17 @@ + * * + * * * + * * * * * + * * * * * + * * * * * * * + * * * * * .# * * + * * * #. .# * * + * "#. #: #" * * * + * * * "#. ##" * + * "### + "## + ##. + .##: + :### + ;### + ,####. + /\/\/\/\/\/.######.\/\/\/\/\ diff --git a/d05/ex03/srcs/Intern.cpp b/d05/ex03/srcs/Intern.cpp index ee5ebd1..90d0202 100644 --- a/d05/ex03/srcs/Intern.cpp +++ b/d05/ex03/srcs/Intern.cpp @@ -7,9 +7,9 @@ *********************************************/ const t_formModel Intern::_chooseForm[] = { - {"Shrubbery", Intern::makeShrubbery}, - {"Presidential", Intern::makePresidential}, - {"Robotomy", Intern::makeRobotomy} + {"shrubbery", Intern::makeShrubbery}, + {"presidential", Intern::makePresidential}, + {"robotomy", Intern::makeRobotomy} }; /********************************************* @@ -44,18 +44,6 @@ Intern & Intern::operator=( Intern const & rhs __attribute__((unused))) { return *this; } -//std::ostream & operator<<(std::ostream & o, Intern const & rhs) -//{ -// o << rhs.getFoo(); -// return (o); -//} - -/********************************************* - * ACCESSORS - *********************************************/ - -//std::string Intern::getFoo() const {return _foo;} - /********************************************* * PRIVATE MEMBER FUNCTIONS *********************************************/ @@ -64,7 +52,7 @@ AForm * Intern::makeForm(std::string formName, std::string formTarget) const { unsigned int len = sizeof _chooseForm / sizeof _chooseForm[0]; for (unsigned int i = 0; i < len; i++) - if (!formName.compare(_chooseForm[i].name)) + if (isValidForm(formName, i)) { std::cout << "Intern creates " << formName << "\n"; return _chooseForm[i].create(formTarget); @@ -73,6 +61,16 @@ AForm * Intern::makeForm(std::string formName, std::string formTarget) const { return NULL; } +bool Intern::isValidForm(std::string name, unsigned int i) const { + // to lowercase : + // https://stackoverflow.com/questions/313970/how-to-convert-an-instance-of-stdstring-to-lower-case + std::transform(name.begin(), name.end(), name.begin(), ::tolower); + + if (name.find(_chooseForm[i].name) == std::string::npos) + return false; + return true; +} + /********************************************* * PUBLIC MEMBER FUNCTIONS *********************************************/ @@ -84,10 +82,3 @@ AForm * Intern::makePresidential(std::string const &target) { AForm * Intern::makeRobotomy(std::string const &target) { return new RobotomyRequestForm(target);} -/********************************************* - * NESTED CLASS - *********************************************/ - -//void Intern::Class::function() {} - -