diff options
| author | Charles <sircharlesaze@gmail.com> | 2020-04-14 20:42:26 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2020-04-14 20:42:26 +0200 |
| commit | 7ac812044bfe771178752a52d70b18bb297c1891 (patch) | |
| tree | 5f5faf0d627304cdfe1f1f45194b3da76653fff8 /cpp05/ex01/Bureaucrat.cpp | |
| parent | efea8712aaf8169b1184cceb83705ca6b8783173 (diff) | |
| download | piscine_cpp-7ac812044bfe771178752a52d70b18bb297c1891.tar.gz piscine_cpp-7ac812044bfe771178752a52d70b18bb297c1891.tar.bz2 piscine_cpp-7ac812044bfe771178752a52d70b18bb297c1891.zip | |
cpp07 done, cpp06 ex00 and ex01 start
Diffstat (limited to 'cpp05/ex01/Bureaucrat.cpp')
| -rw-r--r-- | cpp05/ex01/Bureaucrat.cpp | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/cpp05/ex01/Bureaucrat.cpp b/cpp05/ex01/Bureaucrat.cpp new file mode 100644 index 0000000..69ca053 --- /dev/null +++ b/cpp05/ex01/Bureaucrat.cpp @@ -0,0 +1,106 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Bureaucrat.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* 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 */ +/* */ +/* ************************************************************************** */ + +#include "Bureaucrat.hpp" + +Bureaucrat::Bureaucrat(Bureaucrat const& other) +{ + *this = other; +} + +void Bureaucrat::operator=(Bureaucrat const& other) +{ + m_grade = other.m_grade; +} + +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++; +} + +Bureaucrat::GradeTooHighException::GradeTooHighException() : std::exception() +{} + +Bureaucrat::GradeTooHighException::GradeTooHighException(GradeTooHighException const& other) + : std::exception(other) +{} + +void Bureaucrat::GradeTooHighException::operator=(GradeTooHighException const& other) +{ + std::exception::operator=(other); +} + +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) +{} + +void Bureaucrat::GradeTooLowException::operator=(GradeTooLowException const& other) +{ + std::exception::operator=(other); +} + +Bureaucrat::GradeTooLowException::~GradeTooLowException() +{} + +char const* Bureaucrat::GradeTooLowException::what() const throw() +{ + return "Grade is too low"; +} + +Bureaucrat::Bureaucrat() +{} + +std::ostream& operator<<(std::ostream& out, Bureaucrat const& b) +{ + std::cout << b.getName() << ", bureaucrat grade " << b.getGrade() << std::endl; + return out; +} |
