1
0
Files
CPP_Module_05/ex03/ShrubberyCreationForm.cpp
2025-04-03 16:07:05 +02:00

68 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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;
}