diff options
Diffstat (limited to 'cpp05/ex01')
| -rw-r--r-- | cpp05/ex01/Bureaucrat.cpp | 57 | ||||
| -rw-r--r-- | cpp05/ex01/Bureaucrat.hpp | 19 | ||||
| -rw-r--r-- | cpp05/ex01/Form.cpp | 70 | ||||
| -rw-r--r-- | cpp05/ex01/Form.hpp | 24 |
4 files changed, 88 insertions, 82 deletions
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); |
