CPP05
1.0
読み取り中…
検索中…
一致する文字列を見つけられません
ShrubberyCreationForm.cpp
[詳解]
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* ShrubberyCreationForm.cpp :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2025/06/30 12:13:15 by kamitsui #+# #+# */
9
/* Updated: 2025/07/02 17:10:36 by kamitsui ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
18
#include "
ShrubberyCreationForm.hpp
"
19
20
ShrubberyCreationForm::ShrubberyCreationForm(
const
std::string
&target)
21
:
AForm
(
"Shrubbery Creation"
, 145, 137, target) {}
22
23
ShrubberyCreationForm::ShrubberyCreationForm(
const
ShrubberyCreationForm
&other) :
AForm
(other) {}
24
25
ShrubberyCreationForm
&
ShrubberyCreationForm::operator=
(
const
ShrubberyCreationForm
&other) {
26
AForm::operator=
(other);
27
return
*
this
;
28
}
29
30
ShrubberyCreationForm::~ShrubberyCreationForm
() {}
31
35
void
ShrubberyCreationForm::performAction
()
const
{
36
std::string
filename =
getTarget
() +
"_shrubbery"
;
37
std::ofstream
outfile(filename.
c_str
());
38
39
if
(!outfile.
is_open
()) {
40
std::cerr
<<
"Error: Could not open file "
<< filename <<
std::endl
;
41
return
;
42
}
43
44
// out each line of ASCII art
45
for
(
int
i = 0; i <
ASCII_ART_HEIGHT
; ++i) {
46
outfile <<
ASCII_ART
[i] <<
std::endl
;
47
}
48
49
outfile.
close
();
50
std::cout
<<
"Created shrubbery file at "
<< filename <<
std::endl
;
51
}
std::ofstream
std::string
std::string::c_str
T c_str(T... args)
std::cerr
AForm
An abstract base class for forms.
Definition
AForm.hpp:34
AForm::getTarget
const std::string & getTarget() const
Definition
AForm.cpp:46
AForm::operator=
AForm & operator=(const AForm &other)
Definition
AForm.cpp:32
ShrubberyCreationForm
A concrete form that creates a file with ASCII trees.
Definition
ShrubberyCreationForm.hpp:28
ShrubberyCreationForm::operator=
ShrubberyCreationForm & operator=(const ShrubberyCreationForm &other)
Definition
ShrubberyCreationForm.cpp:25
ShrubberyCreationForm::performAction
virtual void performAction() const
Creates a file named "_target" + "_shrubbery" and writes ASCII trees to it.
Definition
ShrubberyCreationForm.cpp:35
ShrubberyCreationForm::~ShrubberyCreationForm
~ShrubberyCreationForm()
Definition
ShrubberyCreationForm.cpp:30
std::ofstream::close
T close(T... args)
std::cout
std::endl
T endl(T... args)
ShrubberyCreationForm.hpp
Defines the ShrubberyCreationForm class.
ASCII_ART
const char *const ASCII_ART[]
Definition
ShrubberyCreationForm.hpp:41
ASCII_ART_HEIGHT
const int ASCII_ART_HEIGHT
Definition
ShrubberyCreationForm.hpp:67
std::ofstream::is_open
T is_open(T... args)
ex02
ShrubberyCreationForm.cpp
構築:
1.9.8