ex03 finished
This commit is contained in:
@@ -23,16 +23,13 @@ Intern::Intern()
|
|||||||
|
|
||||||
Intern::Intern(const Intern &other)
|
Intern::Intern(const Intern &other)
|
||||||
{
|
{
|
||||||
*this = other;
|
(void)other; // No atributes for copying
|
||||||
// std::cout << "Intern copy constructor called" << std::endl;
|
// std::cout << "Intern copy constructor called" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Intern& Intern::operator=(const Intern &other)
|
Intern& Intern::operator=(const Intern &other)
|
||||||
{
|
{
|
||||||
if (this != &other)
|
(void)other; // No atributes for copying
|
||||||
{
|
|
||||||
// Copy attributes here
|
|
||||||
}
|
|
||||||
// std::cout << "Intern copy assignment operator called" << std::endl;
|
// std::cout << "Intern copy assignment operator called" << std::endl;
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
@@ -41,3 +38,54 @@ Intern::~Intern()
|
|||||||
{
|
{
|
||||||
// std::cout << "Intern destructor called" << std::endl;
|
// std::cout << "Intern destructor called" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////
|
||||||
|
// Creators //
|
||||||
|
//////////////////
|
||||||
|
|
||||||
|
AForm* Intern::createShrubbery(const std::string &target)
|
||||||
|
{
|
||||||
|
return new ShrubberyCreationForm(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm* Intern::createRobotomy(const std::string &target)
|
||||||
|
{
|
||||||
|
return new RobotomyRequestForm(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm* Intern::createPardon(const std::string &target)
|
||||||
|
{
|
||||||
|
return new PresidentialPardonForm(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
AForm* Intern::makeForm(const std::string &formName, const std::string &target)
|
||||||
|
{
|
||||||
|
std::string formNames[3] = {
|
||||||
|
"shrubbery creation",
|
||||||
|
"robotomy request",
|
||||||
|
"presidential pardon"
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef AForm* (Intern::*FormCreator)(const std::string&);
|
||||||
|
FormCreator creators[3] = {
|
||||||
|
&Intern::createShrubbery,
|
||||||
|
&Intern::createShrubbery,
|
||||||
|
&Intern::createPardon
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
if (formName == formNames[i])
|
||||||
|
{
|
||||||
|
std::cout << "Intern creates "
|
||||||
|
<< formName
|
||||||
|
<< std::endl;
|
||||||
|
return (this->*creators[i])(target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "Intern cannot create \"" << formName
|
||||||
|
<< "\" because it doesn't exist"
|
||||||
|
<< std::endl;
|
||||||
|
return (NULL);
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,16 +14,26 @@
|
|||||||
# define INTERN_HPP
|
# define INTERN_HPP
|
||||||
|
|
||||||
# include <iostream>
|
# include <iostream>
|
||||||
|
# include <string>
|
||||||
|
# include "../AForm/AForm.hpp"
|
||||||
|
# include "../ShrubberyCreationForm/ShrubberyCreationForm.hpp"
|
||||||
|
# include "../RobotomyRequestForm/RobotomyRequestForm.hpp"
|
||||||
|
# include "../PresidentialPardonForm/PresidentialPardonForm.hpp"
|
||||||
|
|
||||||
class Intern
|
class Intern
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
AForm* createShrubbery(const std::string &target);
|
||||||
|
AForm* createRobotomy(const std::string &target);
|
||||||
|
AForm* createPardon(const std::string &target);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Intern();
|
Intern();
|
||||||
Intern(const Intern &other);
|
Intern(const Intern &other);
|
||||||
Intern& operator=(const Intern &other);
|
Intern& operator=(const Intern &other);
|
||||||
~Intern();
|
~Intern();
|
||||||
|
|
||||||
|
AForm* makeForm(const std::string &formName, const std::string &target);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
#include "Bureaucrat/Bureaucrat.hpp"
|
#include "Bureaucrat/Bureaucrat.hpp"
|
||||||
#include "AForm/AForm.hpp"
|
#include "AForm/AForm.hpp"
|
||||||
|
#include "Intern/Intern.hpp"
|
||||||
#include "ShrubberyCreationForm/ShrubberyCreationForm.hpp"
|
#include "ShrubberyCreationForm/ShrubberyCreationForm.hpp"
|
||||||
#include "RobotomyRequestForm/RobotomyRequestForm.hpp"
|
#include "RobotomyRequestForm/RobotomyRequestForm.hpp"
|
||||||
#include "PresidentialPardonForm/PresidentialPardonForm.hpp"
|
#include "PresidentialPardonForm/PresidentialPardonForm.hpp"
|
||||||
@@ -22,15 +23,18 @@ int main()
|
|||||||
// RobotomyRequestForm
|
// RobotomyRequestForm
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
std::cout << "---- ex01 tests ----" << std::endl;
|
std::cout << "---- ex03 tests ----" << std::endl;
|
||||||
RobotomyRequestForm form("home");
|
Bureaucrat angel("Angel", 1);
|
||||||
|
Intern intern;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Bureaucrat angel("Angel", 1);
|
AForm* form = intern.makeForm("shrubbery creation", "home");
|
||||||
|
|
||||||
angel.executeForm(form);
|
angel.executeForm(*form);
|
||||||
angel.signForm(form);
|
angel.signForm(*form);
|
||||||
angel.executeForm(form);
|
angel.executeForm(*form);
|
||||||
|
|
||||||
|
delete form;
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
std::cout << e.what() << std::endl;
|
std::cout << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user