| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- /* ************************************************************************** */
- /* */
- /* ::: :::::::: */
- /* Bureaucrat.cpp :+: :+: :+: */
- /* +:+ +:+ +:+ */
- /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
- /* +#+#+#+#+#+ +#+ */
- /* Created: 2025/12/26 17:51:13 by bchanot #+# #+# */
- /* Updated: 2025/12/29 16:35:46 by bchanot ### ########.fr */
- /* */
- /* ************************************************************************** */
- #include "Bureaucrat.hpp"
- /*
- ** ------------------------------- CONSTRUCTOR --------------------------------
- */
- Bureaucrat::Bureaucrat() : _name("DefaultName"), _grade(150)
- {
- }
- Bureaucrat::Bureaucrat( std::string const name, u_int8_t grade ) : _name(name), _grade(grade)
- {
- if (this->_grade > 150)
- throw Bureaucrat::GradeTooHighException();
- else if (this->_grade < 1)
- throw Bureaucrat::GradeTooLowException();
- }
- Bureaucrat::Bureaucrat( const Bureaucrat & src ) : _name(src._name), _grade(src._grade)
- {
- if (this->_grade > 150)
- throw Bureaucrat::GradeTooHighException();
- else if (this->_grade < 1)
- throw Bureaucrat::GradeTooLowException();
- }
- /*
- ** -------------------------------- DESTRUCTOR --------------------------------
- */
- Bureaucrat::~Bureaucrat()
- {
- }
- /*
- ** --------------------------------- OVERLOAD ---------------------------------
- */
- Bureaucrat & Bureaucrat::operator=( Bureaucrat const & rhs )
- {
- (void)rhs;
- //if ( this != &rhs )
- //{
- //this->_value = rhs.getValue();
- //}
- return *this;
- }
- std::ostream & operator<<( std::ostream & o, Bureaucrat const & i )
- {
- o << i.getName() << ", bureaucrat grade " << (int)i.getGrade();
- return o;
- }
- Bureaucrat &Bureaucrat::operator++(void) {
- if (this->_grade > 1)
- this->_grade--;
- else
- throw Bureaucrat::GradeTooHighException();
- return *this;
- }
- Bureaucrat &Bureaucrat::operator--(void) {
- if (this->_grade < 150)
- this->_grade++;
- else
- throw Bureaucrat::GradeTooLowException();
- return *this;
- }
- /*
- ** --------------------------------- METHODS ----------------------------------
- */
- void Bureaucrat::decrementGrade(void)
- {
- if (this->_grade < 150)
- this->_grade++;
- else
- throw Bureaucrat::GradeTooHighException();
- }
- void Bureaucrat::incrementGrade(void) {
- if (this->_grade > 1)
- this->_grade--;
- else
- throw Bureaucrat::GradeTooLowException();
- }
- /*
- ** --------------------------------- ACCESSOR ---------------------------------
- */
- uint8_t Bureaucrat::getGrade(void) const {
- return this->_grade;
- }
- std::string Bureaucrat::getName(void) const {
- return this->_name;
- }
- /* ************************************************************************** */
|