aboutsummaryrefslogtreecommitdiff
path: root/cpp05
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-19 13:59:12 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-10-19 13:59:12 +0200
commitc426fe76ec5925e8c94aae3db04e5e1f1ce1585e (patch)
tree1cdbbe15c1ed92f0df3b7041550270690575f1a2 /cpp05
parent60c4c5309af87480fb32f3815bc02031eff43e9b (diff)
downloadpiscine_cpp-c426fe76ec5925e8c94aae3db04e5e1f1ce1585e.tar.gz
piscine_cpp-c426fe76ec5925e8c94aae3db04e5e1f1ce1585e.tar.bz2
piscine_cpp-c426fe76ec5925e8c94aae3db04e5e1f1ce1585e.zip
Adding boilerplate cpp05/ex02
Diffstat (limited to 'cpp05')
-rw-r--r--cpp05/ex00/Bureaucrat.cpp17
-rw-r--r--cpp05/ex00/Bureaucrat.hpp8
-rw-r--r--cpp05/ex01/Bureaucrat.cpp57
-rw-r--r--cpp05/ex01/Bureaucrat.hpp19
-rw-r--r--cpp05/ex01/Form.cpp70
-rw-r--r--cpp05/ex01/Form.hpp24
-rw-r--r--cpp05/ex02/Bureaucrat.cpp115
-rw-r--r--cpp05/ex02/Bureaucrat.hpp63
-rw-r--r--cpp05/ex02/Form.cpp108
-rw-r--r--cpp05/ex02/Form.hpp65
-rw-r--r--cpp05/ex02/PresidentialPardonFrom.cpp0
-rw-r--r--cpp05/ex02/PresidentialPardonFrom.hpp29
-rw-r--r--cpp05/ex02/RobotomyRequestForm.cpp0
-rw-r--r--cpp05/ex02/RobotomyRequestForm.hpp29
-rw-r--r--cpp05/ex02/ShrubberyCreationForm.cpp31
-rw-r--r--cpp05/ex02/ShrubberyCreationForm.hpp34
-rw-r--r--cpp05/ex02/main.cpp48
17 files changed, 627 insertions, 90 deletions
diff --git a/cpp05/ex00/Bureaucrat.cpp b/cpp05/ex00/Bureaucrat.cpp
index 69ca053..5737939 100644
--- a/cpp05/ex00/Bureaucrat.cpp
+++ b/cpp05/ex00/Bureaucrat.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 18:08:13 by charles #+# #+# */
-/* Updated: 2020/04/14 18:44:49 by charles ### ########.fr */
+/* Updated: 2020/10/19 13:26:35 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,9 +17,10 @@ Bureaucrat::Bureaucrat(Bureaucrat const& other)
*this = other;
}
-void Bureaucrat::operator=(Bureaucrat const& other)
+Bureaucrat& Bureaucrat::operator=(Bureaucrat const& other)
{
m_grade = other.m_grade;
+ return *this;
}
Bureaucrat::~Bureaucrat()
@@ -56,6 +57,10 @@ void Bureaucrat::decrementGrade()
m_grade++;
}
+///////////////////////////////////////////////////////////////////////////////
+// Exceptions
+///////////////////////////////////////////////////////////////////////////////
+
Bureaucrat::GradeTooHighException::GradeTooHighException() : std::exception()
{}
@@ -63,9 +68,11 @@ Bureaucrat::GradeTooHighException::GradeTooHighException(GradeTooHighException c
: std::exception(other)
{}
-void Bureaucrat::GradeTooHighException::operator=(GradeTooHighException const& other)
+Bureaucrat::GradeTooHighException&
+Bureaucrat::GradeTooHighException::operator=(GradeTooHighException const& other)
{
std::exception::operator=(other);
+ return *this;
}
Bureaucrat::GradeTooHighException::~GradeTooHighException()
@@ -83,9 +90,11 @@ Bureaucrat::GradeTooLowException::GradeTooLowException(GradeTooLowException cons
: std::exception(other)
{}
-void Bureaucrat::GradeTooLowException::operator=(GradeTooLowException const& other)
+Bureaucrat::GradeTooLowException&
+Bureaucrat::GradeTooLowException::operator=(GradeTooLowException const& other)
{
std::exception::operator=(other);
+ return *this;
}
Bureaucrat::GradeTooLowException::~GradeTooLowException()
diff --git a/cpp05/ex00/Bureaucrat.hpp b/cpp05/ex00/Bureaucrat.hpp
index 8cb328e..7734725 100644
--- a/cpp05/ex00/Bureaucrat.hpp
+++ b/cpp05/ex00/Bureaucrat.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 18:04:32 by charles #+# #+# */
-/* Updated: 2020/04/14 18:42:13 by charles ### ########.fr */
+/* Updated: 2020/10/19 13:26:06 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,7 +20,7 @@ class Bureaucrat
{
public:
Bureaucrat(Bureaucrat const& other);
- void operator=(Bureaucrat const& other);
+ Bureaucrat& operator=(Bureaucrat const& other);
~Bureaucrat();
Bureaucrat(std::string const& name, int grade);
@@ -34,7 +34,7 @@ public:
public:
GradeTooHighException();
GradeTooHighException(GradeTooHighException const& other);
- void operator=(GradeTooHighException const& other);
+ GradeTooHighException& operator=(GradeTooHighException const& other);
~GradeTooHighException();
virtual char const* what() const throw();
};
@@ -44,7 +44,7 @@ public:
public:
GradeTooLowException();
GradeTooLowException(GradeTooLowException const& other);
- void operator=(GradeTooLowException const& other);
+ GradeTooLowException& operator=(GradeTooLowException const& other);
~GradeTooLowException();
virtual char const* what() const throw();
};
diff --git a/cpp05/ex01/Bureaucrat.cpp b/cpp05/ex01/Bureaucrat.cpp
index 69ca053..c9c206b 100644
--- a/cpp05/ex01/Bureaucrat.cpp
+++ b/cpp05/ex01/Bureaucrat.cpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 18:08:13 by charles #+# #+# */
-/* Updated: 2020/04/14 18:44:49 by charles ### ########.fr */
+/* Updated: 2020/10/19 13:30:24 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,28 +17,21 @@ Bureaucrat::Bureaucrat(Bureaucrat const& other)
*this = other;
}
-void Bureaucrat::operator=(Bureaucrat const& other)
+Bureaucrat& Bureaucrat::operator=(Bureaucrat const& other)
{
m_grade = other.m_grade;
+ return *this;
}
-Bureaucrat::~Bureaucrat()
-{}
+Bureaucrat::~Bureaucrat() {}
Bureaucrat::Bureaucrat(std::string const& name, int grade)
: m_name(name), m_grade(grade)
-{
-}
+{}
-std::string const& Bureaucrat::getName() const
-{
- return m_name;
-}
+std::string const& Bureaucrat::getName() const { return m_name; }
-int Bureaucrat::getGrade() const
-{
- return m_grade;
-}
+int Bureaucrat::getGrade() const { return m_grade; }
void Bureaucrat::incrementGrade()
{
@@ -56,6 +49,22 @@ void Bureaucrat::decrementGrade()
m_grade++;
}
+void Bureaucrat::signForm(Form& form)
+{
+ try
+ {
+ form.beSigned();
+ std::cout << m_name << " signs " << form << std::endl;
+ }
+ catch (std::exception as &e)
+ std::cout << m_name << " cannot sign " << form
+ << " because " << e.what() << std::endl;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Exceptions
+///////////////////////////////////////////////////////////////////////////////
+
Bureaucrat::GradeTooHighException::GradeTooHighException() : std::exception()
{}
@@ -63,41 +72,41 @@ Bureaucrat::GradeTooHighException::GradeTooHighException(GradeTooHighException c
: std::exception(other)
{}
-void Bureaucrat::GradeTooHighException::operator=(GradeTooHighException const& other)
+Bureaucrat::GradeTooHighException&
+Bureaucrat::GradeTooHighException::operator=(GradeTooHighException const& other)
{
std::exception::operator=(other);
+ return *this;
}
-Bureaucrat::GradeTooHighException::~GradeTooHighException()
-{}
+Bureaucrat::GradeTooHighException::~GradeTooHighException() {}
char const* Bureaucrat::GradeTooHighException::what() const throw()
{
return "Grade is too high";
}
-Bureaucrat::GradeTooLowException::GradeTooLowException() : std::exception()
-{}
+Bureaucrat::GradeTooLowException::GradeTooLowException() : std::exception() {}
Bureaucrat::GradeTooLowException::GradeTooLowException(GradeTooLowException const& other)
: std::exception(other)
{}
-void Bureaucrat::GradeTooLowException::operator=(GradeTooLowException const& other)
+Bureaucrat::GradeTooLowException&
+Bureaucrat::GradeTooLowException::operator=(GradeTooLowException const& other)
{
std::exception::operator=(other);
+ return *this;
}
-Bureaucrat::GradeTooLowException::~GradeTooLowException()
-{}
+Bureaucrat::GradeTooLowException::~GradeTooLowException() {}
char const* Bureaucrat::GradeTooLowException::what() const throw()
{
return "Grade is too low";
}
-Bureaucrat::Bureaucrat()
-{}
+Bureaucrat::Bureaucrat() : m_name(""), m_grade(0) {}
std::ostream& operator<<(std::ostream& out, Bureaucrat const& b)
{
diff --git a/cpp05/ex01/Bureaucrat.hpp b/cpp05/ex01/Bureaucrat.hpp
index ff8bb2e..aabf557 100644
--- a/cpp05/ex01/Bureaucrat.hpp
+++ b/cpp05/ex01/Bureaucrat.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 18:04:32 by charles #+# #+# */
-/* Updated: 2020/04/14 19:37:05 by charles ### ########.fr */
+/* Updated: 2020/10/19 13:23:52 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -20,22 +20,23 @@ class Bureaucrat
{
public:
Bureaucrat(Bureaucrat const& other);
- void operator=(Bureaucrat const& other);
+ Bureaucrat& operator=(Bureaucrat const& other);
~Bureaucrat();
Bureaucrat(std::string const& name, int grade);
+
std::string const& getName() const;
- int getGrade() const;
- void incrementGrade();
- void decrementGrade();
- // signForm();
+ int getGrade() const;
+ void incrementGrade();
+ void decrementGrade();
+ void signForm(Form& form);
class GradeTooHighException : public std::exception
{
public:
GradeTooHighException();
GradeTooHighException(GradeTooHighException const& other);
- void operator=(GradeTooHighException const& other);
+ GradeTooHighException& operator=(GradeTooHighException const& other);
~GradeTooHighException();
virtual char const* what() const throw();
};
@@ -45,7 +46,7 @@ public:
public:
GradeTooLowException();
GradeTooLowException(GradeTooLowException const& other);
- void operator=(GradeTooLowException const& other);
+ GradeTooLowException& operator=(GradeTooLowException const& other);
~GradeTooLowException();
virtual char const* what() const throw();
};
@@ -54,7 +55,7 @@ private:
Bureaucrat();
std::string const m_name;
- int m_grade;
+ int m_grade;
};
std::ostream& operator<<(std::ostream& out, Bureaucrat const& b);
diff --git a/cpp05/ex01/Form.cpp b/cpp05/ex01/Form.cpp
index 8aafc94..12b0a95 100644
--- a/cpp05/ex01/Form.cpp
+++ b/cpp05/ex01/Form.cpp
@@ -6,51 +6,44 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 19:26:39 by charles #+# #+# */
-/* Updated: 2020/04/14 19:39:21 by charles ### ########.fr */
+/* Updated: 2020/10/19 13:20:29 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#include "Form.hpp"
+Form::Form()
+ : m_name(""),
+ m_gradeSign(1),
+ m_gradeExecute(1)
+{}
+
Form::Form(Form const& other)
: m_name(other.m_name),
+ m_signed(other.m_signed),
m_gradeSign(other.m_gradeSign),
m_gradeExecute(other.m_gradeExecute)
-{
- *this = other;
-}
+{}
-void Form::operator=(Form const& other)
+Form& Form::operator=(Form const& other)
{
m_signed = other.m_signed;
+ return *this;
}
-Form::~Form()
-{}
+Form::~Form() {}
Form::Form(std::string const& name)
- : m_name(name), m_signed(false), m_gradeSign(1), m_gradeExecute(1)
+ : m_name(name),
+ m_signed(false),
+ m_gradeSign(1),
+ m_gradeExecute(1)
{}
-std::string const& Form::getName() const
-{
- return m_name;
-}
-
-bool Form::getSigned() const
-{
- return m_signed;
-}
-
-int Form::getGradeSign() const
-{
- return m_gradeSign;
-}
-
-int Form::getGradeExecute() const
-{
- return m_gradeExecute;
-}
+std::string const& Form::getName() const { return m_name; }
+bool Form::getSigned() const { return m_signed; }
+int Form::getGradeSign() const { return m_gradeSign; }
+int Form::getGradeExecute() const { return m_gradeExecute; }
void Form::beSigned(Bureaucrat const& b)
{
@@ -58,16 +51,21 @@ void Form::beSigned(Bureaucrat const& b)
m_signed = true;
}
-Form::GradeTooHighException::GradeTooHighException() : std::exception()
-{}
+///////////////////////////////////////////////////////////////////////////////
+// Exceptions
+///////////////////////////////////////////////////////////////////////////////
+
+Form::GradeTooHighException::GradeTooHighException() : std::exception() {}
Form::GradeTooHighException::GradeTooHighException(GradeTooHighException const& other)
: std::exception(other)
{}
-void Form::GradeTooHighException::operator=(GradeTooHighException const& other)
+Form::GradeTooHighException&
+Form::GradeTooHighException::operator=(GradeTooHighException const& other)
{
std::exception::operator=(other);
+ return *this;
}
Form::GradeTooHighException::~GradeTooHighException()
@@ -85,9 +83,11 @@ Form::GradeTooLowException::GradeTooLowException(GradeTooLowException const& oth
: std::exception(other)
{}
-void Form::GradeTooLowException::operator=(GradeTooLowException const& other)
+Form::GradeTooLowException&
+Form::GradeTooLowException::operator=(GradeTooLowException const& other)
{
std::exception::operator=(other);
+ return *this;
}
Form::GradeTooLowException::~GradeTooLowException()
@@ -101,14 +101,8 @@ char const* Form::GradeTooLowException::what() const throw()
std::ostream& operator<<(std::ostream& out, Form const& f)
{
out << f.getName() << " is "
- << (f.getSigned() ? "" : "not") << "signed and needs at least"
+ << (f.getSigned() ? "" : "not ") << "signed and needs at least"
<< f.getGradeSign() << " to be signed and "
<< f.getGradeExecute() << " to be executed" << std::endl;
return out;
}
-
-Form::Form()
- : m_name(""),
- m_gradeSign(1),
- m_gradeExecute(1)
-{}
diff --git a/cpp05/ex01/Form.hpp b/cpp05/ex01/Form.hpp
index a2421bd..3be16f6 100644
--- a/cpp05/ex01/Form.hpp
+++ b/cpp05/ex01/Form.hpp
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/14 19:19:45 by charles #+# #+# */
-/* Updated: 2020/04/14 19:37:21 by charles ### ########.fr */
+/* Updated: 2020/10/19 13:16:01 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,18 +23,20 @@ public:
~Form();
Form(std::string const& name);
- std::string const& getName() const;
- bool getSigned() const;
- int getGradeSign() const;
- int getGradeExecute() const;
- void beSigned(Bureaucrat const& b);
+
+ std::string const& getName() const;
+ bool getSigned() const;
+ int getGradeSign() const;
+ int getGradeExecute() const;
+
+ void beSigned(Bureaucrat const& b);
class GradeTooHighException : public std::exception
{
public:
GradeTooHighException();
GradeTooHighException(GradeTooHighException const& other);
- void operator=(GradeTooHighException const& other);
+ GradeTooHighException& operator=(GradeTooHighException const& other);
~GradeTooHighException();
virtual char const* what() const throw();
};
@@ -44,7 +46,7 @@ public:
public:
GradeTooLowException();
GradeTooLowException(GradeTooLowException const& other);
- void operator=(GradeTooLowException const& other);
+ GradeTooLowException& operator=(GradeTooLowException const& other);
~GradeTooLowException();
virtual char const* what() const throw();
};
@@ -53,9 +55,9 @@ private:
Form();
std::string const m_name;
- bool m_signed;
- int const m_gradeSign;
- int const m_gradeExecute;
+ bool m_signed;
+ int const m_gradeSign;
+ int const m_gradeExecute;
};
std::ostream& operator<<(std::ostream& out, Form const& f);
diff --git a/cpp05/ex02/Bureaucrat.cpp b/cpp05/ex02/Bureaucrat.cpp
new file mode 100644
index 0000000..c9c206b
--- /dev/null
+++ b/cpp05/ex02/Bureaucrat.cpp
@@ -0,0 +1,115 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Bureaucrat.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 18:08:13 by charles #+# #+# */
+/* Updated: 2020/10/19 13:30:24 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Bureaucrat.hpp"
+
+Bureaucrat::Bureaucrat(Bureaucrat const& other)
+{
+ *this = other;
+}
+
+Bureaucrat& Bureaucrat::operator=(Bureaucrat const& other)
+{
+ m_grade = other.m_grade;
+ return *this;
+}
+
+Bureaucrat::~Bureaucrat() {}
+
+Bureaucrat::Bureaucrat(std::string const& name, int grade)
+ : m_name(name), m_grade(grade)
+{}
+
+std::string const& Bureaucrat::getName() const { return m_name; }
+
+int Bureaucrat::getGrade() const { return m_grade; }
+
+void Bureaucrat::incrementGrade()
+{
+ if (m_grade <= 1)
+ throw Bureaucrat::GradeTooHighException();
+ else
+ m_grade--;
+}
+
+void Bureaucrat::decrementGrade()
+{
+ if (m_grade >= 150)
+ throw Bureaucrat::GradeTooLowException();
+ else
+ m_grade++;
+}
+
+void Bureaucrat::signForm(Form& form)
+{
+ try
+ {
+ form.beSigned();
+ std::cout << m_name << " signs " << form << std::endl;
+ }
+ catch (std::exception as &e)
+ std::cout << m_name << " cannot sign " << form
+ << " because " << e.what() << std::endl;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Exceptions
+///////////////////////////////////////////////////////////////////////////////
+
+Bureaucrat::GradeTooHighException::GradeTooHighException() : std::exception()
+{}
+
+Bureaucrat::GradeTooHighException::GradeTooHighException(GradeTooHighException const& other)
+ : std::exception(other)
+{}
+
+Bureaucrat::GradeTooHighException&
+Bureaucrat::GradeTooHighException::operator=(GradeTooHighException const& other)
+{
+ std::exception::operator=(other);
+ return *this;
+}
+
+Bureaucrat::GradeTooHighException::~GradeTooHighException() {}
+
+char const* Bureaucrat::GradeTooHighException::what() const throw()
+{
+ return "Grade is too high";
+}
+
+Bureaucrat::GradeTooLowException::GradeTooLowException() : std::exception() {}
+
+Bureaucrat::GradeTooLowException::GradeTooLowException(GradeTooLowException const& other)
+ : std::exception(other)
+{}
+
+Bureaucrat::GradeTooLowException&
+Bureaucrat::GradeTooLowException::operator=(GradeTooLowException const& other)
+{
+ std::exception::operator=(other);
+ return *this;
+}
+
+Bureaucrat::GradeTooLowException::~GradeTooLowException() {}
+
+char const* Bureaucrat::GradeTooLowException::what() const throw()
+{
+ return "Grade is too low";
+}
+
+Bureaucrat::Bureaucrat() : m_name(""), m_grade(0) {}
+
+std::ostream& operator<<(std::ostream& out, Bureaucrat const& b)
+{
+ std::cout << b.getName() << ", bureaucrat grade " << b.getGrade() << std::endl;
+ return out;
+}
diff --git a/cpp05/ex02/Bureaucrat.hpp b/cpp05/ex02/Bureaucrat.hpp
new file mode 100644
index 0000000..aabf557
--- /dev/null
+++ b/cpp05/ex02/Bureaucrat.hpp
@@ -0,0 +1,63 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Bureaucrat.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 18:04:32 by charles #+# #+# */
+/* Updated: 2020/10/19 13:23:52 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef BUREAUCRAT_HPP
+# define BUREAUCRAT_HPP
+
+# include <iostream>
+# include <exception>
+
+class Bureaucrat
+{
+public:
+ Bureaucrat(Bureaucrat const& other);
+ Bureaucrat& operator=(Bureaucrat const& other);
+ ~Bureaucrat();
+
+ Bureaucrat(std::string const& name, int grade);
+
+ std::string const& getName() const;
+ int getGrade() const;
+ void incrementGrade();
+ void decrementGrade();
+ void signForm(Form& form);
+
+ class GradeTooHighException : public std::exception
+ {
+ public:
+ GradeTooHighException();
+ GradeTooHighException(GradeTooHighException const& other);
+ GradeTooHighException& operator=(GradeTooHighException const& other);
+ ~GradeTooHighException();
+ virtual char const* what() const throw();
+ };
+
+ class GradeTooLowException : public std::exception
+ {
+ public:
+ GradeTooLowException();
+ GradeTooLowException(GradeTooLowException const& other);
+ GradeTooLowException& operator=(GradeTooLowException const& other);
+ ~GradeTooLowException();
+ virtual char const* what() const throw();
+ };
+
+private:
+ Bureaucrat();
+
+ std::string const m_name;
+ int m_grade;
+};
+
+std::ostream& operator<<(std::ostream& out, Bureaucrat const& b);
+
+#endif
diff --git a/cpp05/ex02/Form.cpp b/cpp05/ex02/Form.cpp
new file mode 100644
index 0000000..12b0a95
--- /dev/null
+++ b/cpp05/ex02/Form.cpp
@@ -0,0 +1,108 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Form.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 19:26:39 by charles #+# #+# */
+/* Updated: 2020/10/19 13:20:29 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Form.hpp"
+
+Form::Form()
+ : m_name(""),
+ m_gradeSign(1),
+ m_gradeExecute(1)
+{}
+
+Form::Form(Form const& other)
+ : m_name(other.m_name),
+ m_signed(other.m_signed),
+ m_gradeSign(other.m_gradeSign),
+ m_gradeExecute(other.m_gradeExecute)
+{}
+
+Form& Form::operator=(Form const& other)
+{
+ m_signed = other.m_signed;
+ return *this;
+}
+
+Form::~Form() {}
+
+Form::Form(std::string const& name)
+ : m_name(name),
+ m_signed(false),
+ m_gradeSign(1),
+ m_gradeExecute(1)
+{}
+
+std::string const& Form::getName() const { return m_name; }
+bool Form::getSigned() const { return m_signed; }
+int Form::getGradeSign() const { return m_gradeSign; }
+int Form::getGradeExecute() const { return m_gradeExecute; }
+
+void Form::beSigned(Bureaucrat const& b)
+{
+ if (b.getGrade() >= m_gradeSign)
+ m_signed = true;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+// Exceptions
+///////////////////////////////////////////////////////////////////////////////
+
+Form::GradeTooHighException::GradeTooHighException() : std::exception() {}
+
+Form::GradeTooHighException::GradeTooHighException(GradeTooHighException const& other)
+ : std::exception(other)
+{}
+
+Form::GradeTooHighException&
+Form::GradeTooHighException::operator=(GradeTooHighException const& other)
+{
+ std::exception::operator=(other);
+ return *this;
+}
+
+Form::GradeTooHighException::~GradeTooHighException()
+{}
+
+char const* Form::GradeTooHighException::what() const throw()
+{
+ return "Grade is too high for form";
+}
+
+Form::GradeTooLowException::GradeTooLowException() : std::exception()
+{}
+
+Form::GradeTooLowException::GradeTooLowException(GradeTooLowException const& other)
+ : std::exception(other)
+{}
+
+Form::GradeTooLowException&
+Form::GradeTooLowException::operator=(GradeTooLowException const& other)
+{
+ std::exception::operator=(other);
+ return *this;
+}
+
+Form::GradeTooLowException::~GradeTooLowException()
+{}
+
+char const* Form::GradeTooLowException::what() const throw()
+{
+ return "Grade is too low for form";
+}
+
+std::ostream& operator<<(std::ostream& out, Form const& f)
+{
+ out << f.getName() << " is "
+ << (f.getSigned() ? "" : "not ") << "signed and needs at least"
+ << f.getGradeSign() << " to be signed and "
+ << f.getGradeExecute() << " to be executed" << std::endl;
+ return out;
+}
diff --git a/cpp05/ex02/Form.hpp b/cpp05/ex02/Form.hpp
new file mode 100644
index 0000000..3be16f6
--- /dev/null
+++ b/cpp05/ex02/Form.hpp
@@ -0,0 +1,65 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Form.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 19:19:45 by charles #+# #+# */
+/* Updated: 2020/10/19 13:16:01 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef FORM_HPP
+# define FORM_HPP
+
+# include "Bureaucrat.hpp"
+
+class Form
+{
+public:
+ Form(Form const& other);
+ void operator=(Form const& other);
+ ~Form();
+
+ Form(std::string const& name);
+
+ std::string const& getName() const;
+ bool getSigned() const;
+ int getGradeSign() const;
+ int getGradeExecute() const;
+
+ void beSigned(Bureaucrat const& b);
+
+ class GradeTooHighException : public std::exception
+ {
+ public:
+ GradeTooHighException();
+ GradeTooHighException(GradeTooHighException const& other);
+ GradeTooHighException& operator=(GradeTooHighException const& other);
+ ~GradeTooHighException();
+ virtual char const* what() const throw();
+ };
+
+ class GradeTooLowException : public std::exception
+ {
+ public:
+ GradeTooLowException();
+ GradeTooLowException(GradeTooLowException const& other);
+ GradeTooLowException& operator=(GradeTooLowException const& other);
+ ~GradeTooLowException();
+ virtual char const* what() const throw();
+ };
+
+private:
+ Form();
+
+ std::string const m_name;
+ bool m_signed;
+ int const m_gradeSign;
+ int const m_gradeExecute;
+};
+
+std::ostream& operator<<(std::ostream& out, Form const& f);
+
+#endif
diff --git a/cpp05/ex02/PresidentialPardonFrom.cpp b/cpp05/ex02/PresidentialPardonFrom.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cpp05/ex02/PresidentialPardonFrom.cpp
diff --git a/cpp05/ex02/PresidentialPardonFrom.hpp b/cpp05/ex02/PresidentialPardonFrom.hpp
new file mode 100644
index 0000000..7f86d29
--- /dev/null
+++ b/cpp05/ex02/PresidentialPardonFrom.hpp
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* PresidentialPardonFrom.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/10/19 13:42:46 by cacharle #+# #+# */
+/* Updated: 2020/10/19 13:44:33 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef PRESIDENTIALPARDONFROM_HPP
+# define PRESIDENTIALPARDONFROM_HPP
+
+# include "Form.hpp"
+
+class PresidentialPardonFrom : public Form
+{
+public:
+ PresidentialPardonFrom();
+ PresidentialPardonFrom(const PresidentialPardonFrom& other);
+ PresidentialPardonFrom& operator=(const PresidentialPardonFrom& other);
+ ~PresidentialPardonFrom();
+
+private:
+};
+
+#endif
diff --git a/cpp05/ex02/RobotomyRequestForm.cpp b/cpp05/ex02/RobotomyRequestForm.cpp
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/cpp05/ex02/RobotomyRequestForm.cpp
diff --git a/cpp05/ex02/RobotomyRequestForm.hpp b/cpp05/ex02/RobotomyRequestForm.hpp
new file mode 100644
index 0000000..5a722de
--- /dev/null
+++ b/cpp05/ex02/RobotomyRequestForm.hpp
@@ -0,0 +1,29 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* RobotomyRequestForm.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/10/19 13:43:37 by cacharle #+# #+# */
+/* Updated: 2020/10/19 13:44:17 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef ROBOTOMYREQUESTFORM_HPP
+# define ROBOTOMYREQUESTFORM_HPP
+
+# include "Form.hpp"
+
+class RobotomyRequestForm : public Form
+{
+public:
+ RobotomyRequestForm();
+ RobotomyRequestForm(const RobotomyRequestForm& other);
+ RobotomyRequestForm& operator=(const RobotomyRequestForm& other);
+ ~RobotomyRequestForm();
+
+private:
+};
+
+#endif
diff --git a/cpp05/ex02/ShrubberyCreationForm.cpp b/cpp05/ex02/ShrubberyCreationForm.cpp
new file mode 100644
index 0000000..e138824
--- /dev/null
+++ b/cpp05/ex02/ShrubberyCreationForm.cpp
@@ -0,0 +1,31 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ShrubberyCreationForm.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/10/19 13:45:45 by cacharle #+# #+# */
+/* Updated: 2020/10/19 13:55:53 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ShrubberyCreationForm.hpp"
+
+ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm& other)
+ : m_target(other.m_target)
+{}
+
+ShrubberyCreationForm& ShrubberyCreationForm::operator=(const ShrubberyCreationForm& other)
+{
+ Form::operator=(*this, other);
+ m_target = other.m_target;
+ return *this;
+}
+
+ShrubberyCreationForm::~ShrubberyCreationForm() {}
+
+ShrubberyCreationForm::ShrubberyCreationForm(std::string const& target)
+ m_target(target) {}
+
+ShrubberyCreationForm::ShrubberyCreationForm() : m_target("") {}
diff --git a/cpp05/ex02/ShrubberyCreationForm.hpp b/cpp05/ex02/ShrubberyCreationForm.hpp
new file mode 100644
index 0000000..54fe93c
--- /dev/null
+++ b/cpp05/ex02/ShrubberyCreationForm.hpp
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ShrubberyCreationForm.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/10/19 13:43:27 by cacharle #+# #+# */
+/* Updated: 2020/10/19 13:46:42 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef SHRUBBERYCREATIONFORM_HPP
+# define SHRUBBERYCREATIONFORM_HPP
+
+# include <string>
+# include "Form.hpp"
+
+class ShrubberyCreationForm : public Form
+{
+public:
+ ShrubberyCreationForm(const ShrubberyCreationForm& other);
+ ShrubberyCreationForm& operator=(const ShrubberyCreationForm& other);
+ ~ShrubberyCreationForm();
+
+ ShrubberyCreationForm(std::string const& target);
+
+private:
+ ShrubberyCreationForm();
+
+ std::string m_target;
+};
+
+#endif
diff --git a/cpp05/ex02/main.cpp b/cpp05/ex02/main.cpp
new file mode 100644
index 0000000..ebfed5a
--- /dev/null
+++ b/cpp05/ex02/main.cpp
@@ -0,0 +1,48 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 18:13:05 by charles #+# #+# */
+/* Updated: 2020/04/14 18:43:15 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Bureaucrat.hpp"
+
+int main()
+{
+ Bureaucrat a("jean", 140);
+ Bureaucrat b("didier", 10);
+
+ while (true)
+ {
+ try
+ {
+ a.decrementGrade();
+ std::cout << a;
+ }
+ catch (std::exception& e)
+ {
+ std::cout << e.what() << std::endl;
+ break;
+ }
+ }
+
+ while (true)
+ {
+ try
+ {
+ b.incrementGrade();
+ std::cout << b;
+ }
+ catch (std::exception& e)
+ {
+ std::cout << e.what() << std::endl;
+ break;
+ }
+ }
+ return 0;
+}