cpp-partie-2/cpp05/ex02/Bureaucrat.cpp
2024-02-11 18:36:44 +01:00

74 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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 << " couldnt 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);
}