Bureaucrat.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* Bureaucrat.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/12/26 17:51:13 by bchanot #+# #+# */
  9. /* Updated: 2025/12/29 16:35:46 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "Bureaucrat.hpp"
  13. /*
  14. ** ------------------------------- CONSTRUCTOR --------------------------------
  15. */
  16. Bureaucrat::Bureaucrat() : _name("DefaultName"), _grade(150)
  17. {
  18. }
  19. Bureaucrat::Bureaucrat( std::string const name, u_int8_t grade ) : _name(name), _grade(grade)
  20. {
  21. if (this->_grade > 150)
  22. throw Bureaucrat::GradeTooHighException();
  23. else if (this->_grade < 1)
  24. throw Bureaucrat::GradeTooLowException();
  25. }
  26. Bureaucrat::Bureaucrat( const Bureaucrat & src ) : _name(src._name), _grade(src._grade)
  27. {
  28. if (this->_grade > 150)
  29. throw Bureaucrat::GradeTooHighException();
  30. else if (this->_grade < 1)
  31. throw Bureaucrat::GradeTooLowException();
  32. }
  33. /*
  34. ** -------------------------------- DESTRUCTOR --------------------------------
  35. */
  36. Bureaucrat::~Bureaucrat()
  37. {
  38. }
  39. /*
  40. ** --------------------------------- OVERLOAD ---------------------------------
  41. */
  42. Bureaucrat & Bureaucrat::operator=( Bureaucrat const & rhs )
  43. {
  44. (void)rhs;
  45. //if ( this != &rhs )
  46. //{
  47. //this->_value = rhs.getValue();
  48. //}
  49. return *this;
  50. }
  51. std::ostream & operator<<( std::ostream & o, Bureaucrat const & i )
  52. {
  53. o << i.getName() << ", bureaucrat grade " << (int)i.getGrade();
  54. return o;
  55. }
  56. Bureaucrat &Bureaucrat::operator++(void) {
  57. if (this->_grade > 1)
  58. this->_grade--;
  59. else
  60. throw Bureaucrat::GradeTooHighException();
  61. return *this;
  62. }
  63. Bureaucrat &Bureaucrat::operator--(void) {
  64. if (this->_grade < 150)
  65. this->_grade++;
  66. else
  67. throw Bureaucrat::GradeTooLowException();
  68. return *this;
  69. }
  70. /*
  71. ** --------------------------------- METHODS ----------------------------------
  72. */
  73. void Bureaucrat::decrementGrade(void)
  74. {
  75. if (this->_grade < 150)
  76. this->_grade++;
  77. else
  78. throw Bureaucrat::GradeTooHighException();
  79. }
  80. void Bureaucrat::incrementGrade(void) {
  81. if (this->_grade > 1)
  82. this->_grade--;
  83. else
  84. throw Bureaucrat::GradeTooLowException();
  85. }
  86. /*
  87. ** --------------------------------- ACCESSOR ---------------------------------
  88. */
  89. uint8_t Bureaucrat::getGrade(void) const {
  90. return this->_grade;
  91. }
  92. std::string Bureaucrat::getName(void) const {
  93. return this->_name;
  94. }
  95. /* ************************************************************************** */