AForm.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* AForm.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/12/29 16:42:01 by bchanot #+# #+# */
  9. /* Updated: 2025/12/31 16:01:36 by bchanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "AForm.hpp"
  13. #include "Bureaucrat.hpp"
  14. /*
  15. ** ------------------------------- CONSTRUCTOR --------------------------------
  16. */
  17. AForm::AForm() : _target("DefautTarget"), _name("DefaultAFormName"), _signGrade(1), _executeGrade(1), _signed(false)
  18. {
  19. }
  20. AForm::AForm( const std::string name, uint8_t execGrade, uint8_t signGrade, std::string target) : _target(target), _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. AForm::AForm( const AForm & src ) : _target(src._target), _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. AForm::~AForm()
  38. {
  39. }
  40. /*
  41. ** --------------------------------- OVERLOAD ---------------------------------
  42. */
  43. AForm & AForm::operator=( AForm 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, AForm const & i )
  53. {
  54. i.print(o);
  55. return o;
  56. }
  57. void AForm::print(std::ostream & o) const {
  58. o << "AForm name : " << this->getName() << ", Minimum grade for sign : " << (int)this->getSignGrade() << ", Minimum exection grade : " << (int)this->getExecutionGrade() << ", Is signed : " << this->getSigned() << ", target : " << this->getTarget();
  59. }
  60. /*
  61. ** --------------------------------- METHODS ----------------------------------
  62. */
  63. void AForm::beSigned(const Bureaucrat &sch) {
  64. if (sch.getGrade() <= this->_signGrade)
  65. this->_signed = true;
  66. else
  67. throw AForm::GradeTooLowException();
  68. }
  69. void AForm::execute(Bureaucrat const & executor) const {
  70. if (this->_signed && executor.getGrade() <= this->_signGrade && executor.getGrade() <= this->_executeGrade)
  71. this->action();
  72. else
  73. throw AForm::GradeTooLowException();
  74. }
  75. /*
  76. ** --------------------------------- ACCESSOR ---------------------------------
  77. */
  78. std::string const AForm::getName(void) const {
  79. return this->_name;
  80. }
  81. std::string const AForm::getTarget(void) const {
  82. return this->_target;
  83. }
  84. uint8_t AForm::getSignGrade(void) const {
  85. return this->_signGrade;
  86. }
  87. uint8_t AForm::getExecutionGrade(void) const {
  88. return this->_executeGrade;
  89. }
  90. bool AForm::getSigned(void) const {
  91. return this->_signed;
  92. }
  93. /* ************************************************************************** */