68 lines
2.4 KiB
C++
68 lines
2.4 KiB
C++
/* ************************************************************************** */
|
||
/* */
|
||
/* ::: :::::::: */
|
||
/* ShrubberyCreationForm.cpp :+: :+: :+: */
|
||
/* +:+ +:+ +:+ */
|
||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||
/* +#+#+#+#+#+ +#+ */
|
||
/* Created: 2025/04/01 09:25:06 by adjoly #+# #+# */
|
||
/* Updated: 2025/04/03 14:33:50 by adjoly ### ########.fr */
|
||
/* */
|
||
/* ************************************************************************** */
|
||
|
||
#include "ShrubberyCreationForm.hpp"
|
||
#include "AForm.hpp"
|
||
#include <fstream>
|
||
#include <stdexcept>
|
||
#include <string>
|
||
|
||
ShrubberyCreationForm::ShrubberyCreationForm(void)
|
||
: AForm("ShrubberyCreationForm", 145, 137) {
|
||
_log("➕", "ShrubberyCreationForm", "", "default constructor called");
|
||
}
|
||
|
||
ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm &cpy) : AForm(cpy) {
|
||
_log("➕", "ShrubberyCreationForm", "", "copy constructor called");
|
||
if (this != &cpy)
|
||
*this = cpy;
|
||
}
|
||
|
||
ShrubberyCreationForm::ShrubberyCreationForm(std::string &target)
|
||
: AForm(target, 72, 45) {
|
||
_log("➕", "ShrubberyCreationForm", "", "target constructor called");
|
||
}
|
||
|
||
ShrubberyCreationForm::~ShrubberyCreationForm(void) {
|
||
_log("➖", "ShrubberyCreationForm", "", "destructor called");
|
||
}
|
||
|
||
ShrubberyCreationForm &ShrubberyCreationForm::operator=(const ShrubberyCreationForm &cpy) {
|
||
_log("➕", "ShrubberyCreationForm", "", "copy assignement constructor called");
|
||
(void)cpy;
|
||
return (*this);
|
||
}
|
||
|
||
void ShrubberyCreationForm::_exec(const Bureaucrat &b) const {
|
||
std::ofstream file;
|
||
|
||
file.open(std::string(b.getName() + "_shruberry").c_str());
|
||
if (!file.is_open())
|
||
throw std::runtime_error("Could not write to " + b.getName() +
|
||
"_shruberry");
|
||
|
||
file << " _-_\n"
|
||
" /~~ ~~\\\n"
|
||
" /~~ ~~\\\n"
|
||
"{ }\n"
|
||
" \\ _- -_ /\n"
|
||
" ~ \\ // ~\n"
|
||
"_- - | | _- _\n"
|
||
" _ - | | -_\n"
|
||
" // \\\n";
|
||
|
||
file.close();
|
||
|
||
std::cout << "ASCII tree created in : " + b.getName() + "_shruberry"
|
||
<< std::endl;
|
||
}
|