97 lines
3.0 KiB
C++
97 lines
3.0 KiB
C++
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* RobotomyRequestForm.cpp :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2026/02/21 12:12:55 by aortigos #+# #+# */
|
|
/* Updated: 2026/02/21 12:12:55 by aortigos ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "RobotomyRequestForm.hpp"
|
|
|
|
//////////////////
|
|
//Constructores //
|
|
//////////////////
|
|
|
|
RobotomyRequestForm::RobotomyRequestForm()
|
|
: AForm("RobotomyRequestForm", 72, 45),
|
|
target("NULL")
|
|
{
|
|
//std::cout << "RobotomyRequestForm default constructor called" << std::endl;
|
|
}
|
|
|
|
RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm &other)
|
|
: AForm(other),
|
|
target(other.getTarget())
|
|
{
|
|
//std::cout << "RobotomyRequestForm constructor with params called" << std::endl;
|
|
}
|
|
|
|
RobotomyRequestForm& RobotomyRequestForm::operator=(const RobotomyRequestForm &other)
|
|
{
|
|
if (this != &other)
|
|
{
|
|
AForm::operator=(other);
|
|
this->target = other.getTarget();
|
|
}
|
|
//std::cout << "AForm copy assigment operator called" << std::endl;
|
|
return (*this);
|
|
}
|
|
|
|
RobotomyRequestForm::~RobotomyRequestForm()
|
|
{
|
|
//std::cout << "Destructor called"
|
|
}
|
|
|
|
RobotomyRequestForm::RobotomyRequestForm(std::string target)
|
|
: AForm("RobotomyRequestForm", 72, 45),
|
|
target(target)
|
|
{
|
|
//std::cout << "AForm constructor with params called" << std::endl;
|
|
}
|
|
|
|
//////////////////
|
|
// Getters //
|
|
//////////////////
|
|
|
|
std::string RobotomyRequestForm::getTarget() const
|
|
{
|
|
return (this->target);
|
|
}
|
|
|
|
|
|
//////////////////
|
|
// Execute //
|
|
//////////////////
|
|
|
|
void RobotomyRequestForm::execute(Bureaucrat const &executor) const
|
|
{
|
|
if (!this->getIsSigned())
|
|
throw FormNotSignedException();
|
|
if (this->getGradeToExecute() < executor.getGrade())
|
|
throw AForm::GradeTooLowException();
|
|
|
|
// RobotomyRequestForm form action...
|
|
std::cout << "**bzzzzzzzzz --- **drilling noises*" << std::endl;
|
|
|
|
if (rand() % 2 == 0)
|
|
{
|
|
std::cout << this->target
|
|
<< " has been successfully robotomized" << std::endl;
|
|
} else {
|
|
std::cout << "Robotomization failed :(" << std::endl;
|
|
}
|
|
|
|
}
|
|
|
|
//////////////////
|
|
// Exceptions //
|
|
//////////////////
|
|
|
|
const char* RobotomyRequestForm::FormNotSignedException::what() const throw()
|
|
{
|
|
return ("form is not signed.");
|
|
} |