fixing and starting ShrubberyCreationForm

This commit is contained in:
2026-02-17 17:49:39 +01:00
parent 838b97e98a
commit 5d62dbd20d
6 changed files with 159 additions and 4 deletions

View File

@@ -0,0 +1,86 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ShrubberyCreationForm.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/15 18:00:27 by aortigos #+# #+# */
/* Updated: 2026/02/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "ShrubberyCreationForm.hpp"
//////////////////
//Constructores //
//////////////////
ShrubberyCreationForm::ShrubberyCreationForm()
: AForm("ShrubberyCreationForm", 145, 137),
target("NULL")
{
//std::cout << "ShrubberyCreationForm default constructor called" << std::endl;
}
ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm &other)
: AForm(other),
target(other.getTarget())
{
//std::cout << "ShrubberyCreationForm constructor with params called" << std::endl;
}
ShrubberyCreationForm& ShrubberyCreationForm::operator=(const ShrubberyCreationForm &other)
{
if (this != &other)
{
AForm::operator=(other);
this->target = other.getTarget();
}
//std::cout << "AForm copy assigment operator called" << std::endl;
return (*this);
}
ShrubberyCreationForm::~ShrubberyCreationForm()
{
//std::cout << "Destructor called"
}
ShrubberyCreationForm::ShrubberyCreationForm(std::string target)
: AForm("ShrubberyCreationForm", 145, 137),
target(target)
{
//std::cout << "AForm constructor with params called" << std::endl;
}
//////////////////
// Getters //
//////////////////
std::string ShrubberyCreationForm::getTarget() const
{
return (this->target);
}
//////////////////
// Execute //
//////////////////
void ShrubberyCreationForm::execute(Bureaucrat const &executor)
{
if (!this->getIsSigned())
throw FormNotSignedException();
if (this->getGradeToExecute() < executor.getGrade())
throw AForm::GradeTooLowException();
// Other things...
}
//////////////////
// Exceptions //
//////////////////
const char* ShrubberyCreationForm::FormNotSignedException::what() const throw()
{
return ("form is not signed.");
}

View File

@@ -0,0 +1,44 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ShrubberyCreationForm.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/15 18:00:27 by aortigos #+# #+# */
/* Updated: 2026/02/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef SHRUBBERYCREATIONFORM_HPP
# define SHRUBBERYCREATIONFORM_HPP
# include <iostream>
# include "../AForm/AForm.hpp"
class ShrubberyCreationForm : public AForm
{
private:
std::string target;
public:
ShrubberyCreationForm();
ShrubberyCreationForm(const ShrubberyCreationForm &other);
ShrubberyCreationForm &operator=(const ShrubberyCreationForm &other);
~ShrubberyCreationForm();
ShrubberyCreationForm(std::string target);
std::string getTarget() const;
void execute(Bureaucrat const &executor);
class FormNotSignedException : public std::exception {
public:
virtual const char* what() const throw();
};
};
#endif