mirror of
https://github.com/Ladebeze66/cpp-partie-2.git
synced 2025-12-16 05:57:57 +01:00
74 lines
1.9 KiB
C++
74 lines
1.9 KiB
C++
/* ************************************************************************** */
|
||
/* */
|
||
/* ::: :::::::: */
|
||
/* Bureaucrat.cpp :+: :+: :+: */
|
||
/* +:+ +:+ +:+ */
|
||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||
/* +#+#+#+#+#+ +#+ */
|
||
/* Created: 2024/02/11 13:16:26 by fgras-ca #+# #+# */
|
||
/* Updated: 2024/02/11 14:50:15 by fgras-ca ### ########.fr */
|
||
/* */
|
||
/* ************************************************************************** */
|
||
|
||
#include "Bureaucrat.hpp"
|
||
#include "Form.hpp"
|
||
|
||
Bureaucrat::Bureaucrat(const std::string &nom, int grade) : name(nom)
|
||
{
|
||
if (grade < 1)
|
||
{
|
||
throw GradeTooHighException();
|
||
}
|
||
else if (grade > 150)
|
||
{
|
||
throw GradeTooLowException();
|
||
}
|
||
this->grade = grade;
|
||
}
|
||
|
||
std::string Bureaucrat::getName() const
|
||
{
|
||
return (name);
|
||
}
|
||
|
||
int Bureaucrat::getGrade() const
|
||
{
|
||
return (grade);
|
||
}
|
||
|
||
void Bureaucrat::incrementGrade()
|
||
{
|
||
if (grade <= 1)
|
||
{
|
||
throw GradeTooHighException();
|
||
}
|
||
--grade;
|
||
}
|
||
|
||
void Bureaucrat::decrementGrade()
|
||
{
|
||
if (grade >= 150)
|
||
{
|
||
throw GradeTooLowException();
|
||
}
|
||
++grade;
|
||
}
|
||
|
||
void Bureaucrat::signForm(Form& form)
|
||
{
|
||
try
|
||
{
|
||
form.beSigned(*this);
|
||
std::cout << this->name << " signed " << form.getName() << std::endl;
|
||
} catch (std::exception& e)
|
||
{
|
||
std::cout << this->name << " couldn’t sign " << form.getName() << " because " << e.what() << std::endl;
|
||
}
|
||
}
|
||
|
||
std::ostream& operator<<(std::ostream &os, const Bureaucrat &bureaucrat)
|
||
{
|
||
os << bureaucrat.getName() << MAGENTA << ", bureaucrat grade " << RESET << bureaucrat.getGrade();
|
||
return (os);
|
||
}
|