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/Form.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/Form.cpp')
| -rw-r--r-- | cpp05/ex01/Form.cpp | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/cpp05/ex01/Form.cpp b/cpp05/ex01/Form.cpp new file mode 100644 index 0000000..8aafc94 --- /dev/null +++ b/cpp05/ex01/Form.cpp @@ -0,0 +1,114 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Form.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* 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 */ +/* */ +/* ************************************************************************** */ + +#include "Form.hpp" + +Form::Form(Form const& other) + : m_name(other.m_name), + m_gradeSign(other.m_gradeSign), + m_gradeExecute(other.m_gradeExecute) +{ + *this = other; +} + +void Form::operator=(Form const& other) +{ + m_signed = other.m_signed; +} + +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; +} + +Form::GradeTooHighException::GradeTooHighException() : std::exception() +{} + +Form::GradeTooHighException::GradeTooHighException(GradeTooHighException const& other) + : std::exception(other) +{} + +void Form::GradeTooHighException::operator=(GradeTooHighException const& other) +{ + std::exception::operator=(other); +} + +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) +{} + +void Form::GradeTooLowException::operator=(GradeTooLowException const& other) +{ + std::exception::operator=(other); +} + +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; +} + +Form::Form() + : m_name(""), + m_gradeSign(1), + m_gradeExecute(1) +{} |
