Something went wrong. Try again.
Java--'s try/catch projects.intra.42.fr/projects/cpp-module-05
Something went wrong. Try again.
2.4 kB · 70 lines
C++
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071#include <ShrubberyCreationForm.hpp>#include <fstream>
ShrubberyCreationForm::ShrubberyCreationForm() : AForm("ShrubberyCreationForm", 145, 137), target("home") { std::cout << "ShrubberyCreationForm default constructor called" << std::endl;}
ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm& other) : AForm(other), target(other.target) { std::cout << "ShrubberyCreationForm copy constructor called" << std::endl;}
ShrubberyCreationForm::ShrubberyCreationForm(const std::string& target) : AForm("ShrubberyCreationForm", 145, 137), target(target) { std::cout << "ShrubberyCreationForm (target) constructor called" << std::endl;}
void ShrubberyCreationForm::executeAction() const { std::ofstream file((target + "_shrubbery").c_str());
if (!file.is_open()) throw FileCreationException();
file << " _-_ " << std::endl << " /~~ ~~\\ " << std::endl << " /~~ ~~\\ " << std::endl << "{ } " << std::endl << " \\ _- -_ / " << std::endl << " ~ \\\\ // ~ " << std::endl << "_- - | | _- _ " << std::endl << " _ - | | -_ " << std::endl << " // \\\\ " << std::endl << std::endl << " &&& && & && " << std::endl << " && &\\/&\\|& ()|/ @, &&" << std::endl << " &\\/(/&/&||/& /_/)_&/_&" << std::endl << " &() &\\/&|()|/&\\/ '%\" &" << std::endl << " &_\\_&&_\\ |& |&&/&__%_/_&" << std::endl << "& && & &| &| /& & % ()& " << std::endl << " ()&_---()&\\&\\|&&-&&--%---()~" << std::endl << " && \\||| " << std::endl << " ||| " << std::endl << " ||| " << std::endl << " ||| " << std::endl << " , -=-~ .-^- _ " << std::endl;
file.close();}
const std::string& ShrubberyCreationForm::getTarget() const { return target;}
ShrubberyCreationForm& ShrubberyCreationForm::operator=(const ShrubberyCreationForm& other) { std::cout << "ShrubberyCreationForm assignment operator called" << std::endl;
if (this != &other) { AForm::operator=(other); target = other.target; }
return *this;}
ShrubberyCreationForm::~ShrubberyCreationForm() { std::cout << "ShrubberyCreationForm destructor called" << std::endl;}
const char* ShrubberyCreationForm::FileCreationException::what() const throw() { return "Shrubbery file could not be created";}