Form.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* Form.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/12/29 16:42:01 by bchanot #+# #+# */
  9. /* Updated: 2025/12/29 19:29:17 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "Form.hpp"
  13. #include "Bureaucrat.hpp"
  14. /*
  15. ** ------------------------------- CONSTRUCTOR --------------------------------
  16. */
  17. Form::Form() : _name("DefaultFormName"), _signGrade(1), _executeGrade(1), _signed(false)
  18. {
  19. }
  20. Form::Form( const std::string name, uint8_t execGrade, uint8_t signGrade ) : _name(name), _signGrade(signGrade), _executeGrade(execGrade), _signed(false)
  21. {
  22. if (this->_executeGrade > 150 || this->_signGrade > 150)
  23. throw Bureaucrat::GradeTooHighException();
  24. else if (this->_executeGrade < 1 || this->_signGrade < 1)
  25. throw Bureaucrat::GradeTooLowException();
  26. }
  27. Form::Form( const Form & src ) : _name(src._name), _signGrade(src._signGrade), _executeGrade(src._executeGrade), _signed(false)
  28. {
  29. if (this->_executeGrade > 150 || this->_signGrade > 150)
  30. throw Bureaucrat::GradeTooHighException();
  31. else if (this->_executeGrade < 1 || this->_signGrade < 1)
  32. throw Bureaucrat::GradeTooLowException();
  33. }
  34. /*
  35. ** -------------------------------- DESTRUCTOR --------------------------------
  36. */
  37. Form::~Form()
  38. {
  39. }
  40. /*
  41. ** --------------------------------- OVERLOAD ---------------------------------
  42. */
  43. Form & Form::operator=( Form const & rhs )
  44. {
  45. (void)rhs;
  46. //if ( this != &rhs )
  47. //{
  48. //this->_value = rhs.getValue();
  49. //}
  50. return *this;
  51. }
  52. std::ostream & operator<<( std::ostream & o, Form const & i )
  53. {
  54. o << "Form name : " << i.getName() << ", Minimum grade for sign : " << (int)i.getSignGrade() << ", Minimum exection grade : " << (int)i.getExecutionGrade() << ", Is signed : " << i.getSigned();
  55. return o;
  56. }
  57. /*
  58. ** --------------------------------- METHODS ----------------------------------
  59. */
  60. void Form::beSigned(const Bureaucrat &sch) {
  61. if (sch.getGrade() <= this->_signGrade)
  62. this->_signed = true;
  63. else
  64. throw Form::GradeTooLowException();
  65. }
  66. /*
  67. ** --------------------------------- ACCESSOR ---------------------------------
  68. */
  69. std::string const Form::getName(void) const {
  70. return this->_name;
  71. }
  72. uint8_t Form::getSignGrade(void) const {
  73. return this->_signGrade;
  74. }
  75. uint8_t Form::getExecutionGrade(void) const {
  76. return this->_executeGrade;
  77. }
  78. bool Form::getSigned(void) const {
  79. return this->_signed;
  80. }
  81. /* ************************************************************************** */