aboutsummaryrefslogtreecommitdiff
path: root/cpp05/ex03
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-12-12 12:33:39 +0100
committerCharles Cabergs <me@cacharle.xyz>2020-12-12 12:33:39 +0100
commit0071b1e944cbce91ff6ff8e235280c3955ce1d5b (patch)
treeaf908c41fc051002311f50e8f73b889769a5279e /cpp05/ex03
parentc10aa969c60cedef893146307fa319250901465a (diff)
downloadpiscine_cpp-0071b1e944cbce91ff6ff8e235280c3955ce1d5b.tar.gz
piscine_cpp-0071b1e944cbce91ff6ff8e235280c3955ce1d5b.tar.bz2
piscine_cpp-0071b1e944cbce91ff6ff8e235280c3955ce1d5b.zip
Fixing cpp05 small errors
Diffstat (limited to 'cpp05/ex03')
-rw-r--r--cpp05/ex03/Bureaucrat.cpp15
-rw-r--r--cpp05/ex03/Bureaucrat.hpp11
-rw-r--r--cpp05/ex03/Form.hpp5
-rw-r--r--cpp05/ex03/Intern.cpp9
-rw-r--r--cpp05/ex03/Intern.hpp2
-rw-r--r--cpp05/ex03/PresidentialPardonForm.hpp4
-rw-r--r--cpp05/ex03/RobotomyRequestForm.cpp3
-rw-r--r--cpp05/ex03/RobotomyRequestForm.hpp4
-rw-r--r--cpp05/ex03/ShrubberyCreationForm.hpp4
-rw-r--r--cpp05/ex03/main.cpp9
10 files changed, 37 insertions, 29 deletions
diff --git a/cpp05/ex03/Bureaucrat.cpp b/cpp05/ex03/Bureaucrat.cpp
index 64bbd25..7274f6b 100644
--- a/cpp05/ex03/Bureaucrat.cpp
+++ b/cpp05/ex03/Bureaucrat.cpp
@@ -6,17 +6,18 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 18:08:13 by charles #+# #+# */
-/* Updated: 2020/11/17 13:37:49 by cacharle ### ########.fr */
+/* Updated: 2020/12/12 12:21:27 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "Bureaucrat.hpp"
-Bureaucrat::Bureaucrat(Bureaucrat const& other) { *this = other; }
+Bureaucrat::Bureaucrat(Bureaucrat const& other)
+ : m_name(other.m_name) { *this = other; }
Bureaucrat& Bureaucrat::operator=(Bureaucrat const& other)
{
- m_name = other.m_name;
+ // m_name = other.m_name;
m_grade = other.m_grade;
return *this;
}
@@ -44,7 +45,7 @@ void Bureaucrat::decrementGrade()
checkGrade();
}
-void Bureaucrat::signForm(Form& form)
+void Bureaucrat::signForm(Form& form) const
{
try
{
@@ -53,11 +54,11 @@ void Bureaucrat::signForm(Form& form)
}
catch (std::exception &e)
{
- std::cout << m_name << " cannot sign " << form.getName() << " " << e.what() << std::endl;
+ std::cout << m_name << " cannot sign " << form.getName() << " because " << e.what() << std::endl;
}
}
-void Bureaucrat::executeForm(Form& form)
+void Bureaucrat::executeForm(Form const& form) const
{
try
{
@@ -66,7 +67,7 @@ void Bureaucrat::executeForm(Form& form)
}
catch (std::exception &e)
{
- std::cout << m_name << " cannot execute " << form.getName() << " " << e.what() << std::endl;
+ std::cout << m_name << " cannot execute " << form.getName() << " because " << e.what() << std::endl;
}
}
diff --git a/cpp05/ex03/Bureaucrat.hpp b/cpp05/ex03/Bureaucrat.hpp
index 8e44af0..1c7c565 100644
--- a/cpp05/ex03/Bureaucrat.hpp
+++ b/cpp05/ex03/Bureaucrat.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 18:04:32 by charles #+# #+# */
-/* Updated: 2020/11/17 13:36:56 by cacharle ### ########.fr */
+/* Updated: 2020/12/12 12:19:51 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -33,16 +33,15 @@ public:
void incrementGrade();
void decrementGrade();
- void signForm(Form& form);
-
- void executeForm(Form& form);
+ void signForm(Form& form) const;
+ void executeForm(Form const& form) const;
private:
Bureaucrat();
void checkGrade();
- std::string m_name;
- int m_grade;
+ std::string const m_name;
+ int m_grade;
class GradeTooHighException : public std::exception
{
diff --git a/cpp05/ex03/Form.hpp b/cpp05/ex03/Form.hpp
index 78828da..79e78fa 100644
--- a/cpp05/ex03/Form.hpp
+++ b/cpp05/ex03/Form.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 19:19:45 by charles #+# #+# */
-/* Updated: 2020/11/17 17:09:15 by charles ### ########.fr */
+/* Updated: 2020/12/12 12:20:25 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,7 +24,7 @@ class Form
public:
Form(Form const& other);
Form& operator=(Form const& other);
- ~Form();
+ virtual ~Form();
Form(std::string const& name, int gradeSign, int gradeExecute);
@@ -34,7 +34,6 @@ public:
int getGradeExecute() const;
void beSigned(Bureaucrat const& b);
-
void execute(Bureaucrat const& executor) const;
protected:
diff --git a/cpp05/ex03/Intern.cpp b/cpp05/ex03/Intern.cpp
index 3328957..b31c2b3 100644
--- a/cpp05/ex03/Intern.cpp
+++ b/cpp05/ex03/Intern.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/17 13:41:09 by cacharle #+# #+# */
-/* Updated: 2020/11/17 18:08:56 by charles ### ########.fr */
+/* Updated: 2020/12/12 12:32:15 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -37,6 +37,11 @@ Form *Intern::makeForm(std::string const& name, std::string const& target)
{
for (size_t i = 0; i < sizeof(Intern::makeFormDispatch) / sizeof(Intern::makeFormEntry); i++)
if ((this->makeFormDispatch[i]).name == name)
- return (this->*(makeFormDispatch[i].func))(target);
+ {
+ Form *form = (this->*(makeFormDispatch[i].func))(target);
+ std::cout << "Intern creates " << *form;
+ return form;
+ }
+ std::cout << "Intern cannot create form: " << name << " is not a known form name" << std::endl;
return NULL;
}
diff --git a/cpp05/ex03/Intern.hpp b/cpp05/ex03/Intern.hpp
index c27874a..1565118 100644
--- a/cpp05/ex03/Intern.hpp
+++ b/cpp05/ex03/Intern.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/17 13:39:59 by cacharle #+# #+# */
-/* Updated: 2020/11/17 17:58:02 by charles ### ########.fr */
+/* Updated: 2020/12/12 12:32:05 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
diff --git a/cpp05/ex03/PresidentialPardonForm.hpp b/cpp05/ex03/PresidentialPardonForm.hpp
index fcf8a70..36ab5ec 100644
--- a/cpp05/ex03/PresidentialPardonForm.hpp
+++ b/cpp05/ex03/PresidentialPardonForm.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/19 13:42:46 by cacharle #+# #+# */
-/* Updated: 2020/11/17 17:02:03 by charles ### ########.fr */
+/* Updated: 2020/12/12 12:20:41 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,7 +20,7 @@ class PresidentialPardonForm : public Form
public:
PresidentialPardonForm(const PresidentialPardonForm& other);
PresidentialPardonForm& operator=(const PresidentialPardonForm& other);
- ~PresidentialPardonForm();
+ virtual ~PresidentialPardonForm();
PresidentialPardonForm(std::string const& target);
diff --git a/cpp05/ex03/RobotomyRequestForm.cpp b/cpp05/ex03/RobotomyRequestForm.cpp
index ed05d5f..6ac13e5 100644
--- a/cpp05/ex03/RobotomyRequestForm.cpp
+++ b/cpp05/ex03/RobotomyRequestForm.cpp
@@ -6,7 +6,7 @@
/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/19 13:45:45 by cacharle #+# #+# */
-/* Updated: 2020/11/17 17:20:03 by charles ### ########.fr */
+/* Updated: 2020/12/12 12:22:02 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -29,6 +29,7 @@ RobotomyRequestForm::~RobotomyRequestForm() {}
void RobotomyRequestForm::executeUnsafe() const
{
+ std::cout << "DRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" << std::endl;
if (rand() % 100 <= 50)
std::cout << m_target << " has successfully been robotomized" << std::endl;
else
diff --git a/cpp05/ex03/RobotomyRequestForm.hpp b/cpp05/ex03/RobotomyRequestForm.hpp
index a851b04..f6cafd1 100644
--- a/cpp05/ex03/RobotomyRequestForm.hpp
+++ b/cpp05/ex03/RobotomyRequestForm.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/19 13:43:37 by cacharle #+# #+# */
-/* Updated: 2020/11/17 13:27:32 by cacharle ### ########.fr */
+/* Updated: 2020/12/12 12:20:48 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,7 +20,7 @@ class RobotomyRequestForm : public Form
public:
RobotomyRequestForm(const RobotomyRequestForm& other);
RobotomyRequestForm& operator=(const RobotomyRequestForm& other);
- ~RobotomyRequestForm();
+ virtual ~RobotomyRequestForm();
RobotomyRequestForm(std::string const& target);
diff --git a/cpp05/ex03/ShrubberyCreationForm.hpp b/cpp05/ex03/ShrubberyCreationForm.hpp
index 4799d9d..27e34a0 100644
--- a/cpp05/ex03/ShrubberyCreationForm.hpp
+++ b/cpp05/ex03/ShrubberyCreationForm.hpp
@@ -6,7 +6,7 @@
/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/10/19 13:43:27 by cacharle #+# #+# */
-/* Updated: 2020/11/17 16:37:56 by charles ### ########.fr */
+/* Updated: 2020/12/12 12:20:33 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -24,7 +24,7 @@ class ShrubberyCreationForm : public Form
public:
ShrubberyCreationForm(const ShrubberyCreationForm& other);
ShrubberyCreationForm& operator=(const ShrubberyCreationForm& other);
- ~ShrubberyCreationForm();
+ virtual ~ShrubberyCreationForm();
ShrubberyCreationForm(std::string const& target);
diff --git a/cpp05/ex03/main.cpp b/cpp05/ex03/main.cpp
index aceb722..827071a 100644
--- a/cpp05/ex03/main.cpp
+++ b/cpp05/ex03/main.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 18:13:05 by charles #+# #+# */
-/* Updated: 2020/11/17 19:02:02 by charles ### ########.fr */
+/* Updated: 2020/12/12 12:32:41 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -117,7 +117,7 @@ int main()
Bureaucrat c4("foo", 1); c4.executeForm(sh);
}
{
- std::cout << "############### PRESIDENTIAL SIGN FORM" << std::endl;
+ std::cout << "############### PRESIDENTIAL EXECUTE FORM" << std::endl;
PresidentialPardonForm pr("fu");
pr.beSigned(Bureaucrat("foo", 1));
Bureaucrat c1("foo", 150); c1.executeForm(pr);
@@ -126,7 +126,7 @@ int main()
Bureaucrat c4("foo", 1); c4.executeForm(pr);
}
{
- std::cout << "############### ROBOTOMY SIGN FORM" << std::endl;
+ std::cout << "############### ROBOTOMY EXECUTE FORM" << std::endl;
RobotomyRequestForm ro("mi");
ro.beSigned(Bureaucrat("foo", 1));
Bureaucrat c1("foo", 150); c1.executeForm(ro);
@@ -250,6 +250,9 @@ int main()
std::cout << *sh;
std::cout << *pr;
std::cout << *ro;
+ delete sh;
+ delete pr;
+ delete ro;
}
return 0;
}