58 lines
1.7 KiB
C++
58 lines
1.7 KiB
C++
|
/* ************************************************************************** */
|
||
|
/* */
|
||
|
/* ::: :::::::: */
|
||
|
/* Bureaucrat.cpp :+: :+: :+: */
|
||
|
/* +:+ +:+ +:+ */
|
||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||
|
/* +#+#+#+#+#+ +#+ */
|
||
|
/* Created: 2024/12/23 13:59:45 by adjoly #+# #+# */
|
||
|
/* Updated: 2025/03/08 20:00:23 by adjoly ### ########.fr */
|
||
|
/* */
|
||
|
/* ************************************************************************** */
|
||
|
|
||
|
#include "Bureaucrat.hpp"
|
||
|
|
||
|
Bureaucrat &Bureaucrat::operator=(Bureaucrat const &cpy) {
|
||
|
if (&cpy == this)
|
||
|
return *this;
|
||
|
_grade = cpy._grade;
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
Bureaucrat &Bureaucrat::operator++(void) {
|
||
|
_grade--;
|
||
|
if (_grade < MAXGRADE)
|
||
|
throw GradeTooHighException();
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
Bureaucrat &Bureaucrat::operator--(void) {
|
||
|
_grade++;
|
||
|
if (_grade > MINGRADE)
|
||
|
throw GradeTooLowException();
|
||
|
return *this;
|
||
|
}
|
||
|
|
||
|
Bureaucrat Bureaucrat::operator++(int) {
|
||
|
Bureaucrat old = *this;
|
||
|
|
||
|
_grade--;
|
||
|
if (_grade < MAXGRADE)
|
||
|
throw GradeTooHighException();
|
||
|
return (old);
|
||
|
}
|
||
|
|
||
|
Bureaucrat Bureaucrat::operator--(int) {
|
||
|
Bureaucrat old = *this;
|
||
|
|
||
|
_grade++;
|
||
|
if (_grade > MINGRADE)
|
||
|
throw GradeTooLowException();
|
||
|
return old;
|
||
|
}
|
||
|
|
||
|
std::ostream &operator<<(std::ostream &os, Bureaucrat &val) {
|
||
|
os << val.getName() << ", bureaucrat grade " << (int)val.getGrade();
|
||
|
return os;
|
||
|
}
|