From c426fe76ec5925e8c94aae3db04e5e1f1ce1585e Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Mon, 19 Oct 2020 13:59:12 +0200 Subject: Adding boilerplate cpp05/ex02 --- cpp05/ex01/Bureaucrat.cpp | 57 +++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'cpp05/ex01/Bureaucrat.cpp') 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 +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* 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) { -- cgit