Starting ex03
This commit is contained in:
109
ex03/ShrubberyCreationForm/ShrubberyCreationForm.cpp
Normal file
109
ex03/ShrubberyCreationForm/ShrubberyCreationForm.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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) const
|
||||
{
|
||||
if (!this->getIsSigned())
|
||||
throw FormNotSignedException();
|
||||
if (this->getGradeToExecute() < executor.getGrade())
|
||||
throw AForm::GradeTooLowException();
|
||||
|
||||
// ShrubberyCreation form action...
|
||||
|
||||
std::string filename = this->target + "_shrubbery";
|
||||
std::ofstream file(filename.c_str());
|
||||
|
||||
if (!file.is_open())
|
||||
{
|
||||
std::cerr << "Error: could not create file "
|
||||
<< filename << std::endl;
|
||||
return ;
|
||||
}
|
||||
|
||||
file << " _-_\n";
|
||||
file << " /~~ ~~\\\n";
|
||||
file << " /~~ ~~\\\n";
|
||||
file << "{ }\n";
|
||||
file << " \\ _- -_ /\n";
|
||||
file << " ~ \\ // ~\n";
|
||||
file << "_- - | | _- _\n";
|
||||
file << " _ - | | -_\n";
|
||||
file << " // \\";
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
//////////////////
|
||||
// Exceptions //
|
||||
//////////////////
|
||||
|
||||
const char* ShrubberyCreationForm::FormNotSignedException::what() const throw()
|
||||
{
|
||||
return ("form is not signed.");
|
||||
}
|
||||
Reference in New Issue
Block a user