-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_class_cpp.sh
executable file
·153 lines (138 loc) · 3.13 KB
/
make_class_cpp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash
#Script to create .hh and .cpp
DIR=${PWD##*/}
NB_ARGS=$#
if [[ "$NB_ARGS" -ne "1" ]];
then
echo "Wrong Number of arguments!"
exit 1
fi
NAME="$1";
TEMP="${NAME,,}";
CLASS="${TEMP^}";
SUF_CPP=".cpp"
SUF_HPP=".hpp"
FILE_CPP="$CLASS$SUF_CPP"
FILE_HPP="$CLASS$SUF_HPP"
success()
{
echo -en '\033[0;32m'
echo -n "$1 sucessfully created!"
echo -e '\033[0m'
}
create_new()
{
if [[ $1 == "hpp" ]];
then
touch $FILE_HPP
echo "#ifndef ${CLASS^^}_HPP" >> $FILE_HPP
echo "# define ${CLASS^^}_HPP" >> $FILE_HPP
echo >> $FILE_HPP
echo "# include <iostream>" >> $FILE_HPP
echo >> $FILE_HPP
echo "class $CLASS">> $FILE_HPP
echo "{" >> $FILE_HPP
echo " private":>> $FILE_HPP
echo >> $FILE_HPP
echo " public:" >> $FILE_HPP
echo " $CLASS( void ); " >> $FILE_HPP
echo " $CLASS( const $CLASS © ); " >> $FILE_HPP
echo " ~$CLASS();" >> $FILE_HPP
echo " $CLASS &operator = ( const $CLASS &obj );" >> $FILE_HPP
echo "};" >> $FILE_HPP
echo >> $FILE_HPP
echo "#endif" >> $FILE_HPP
echo >> $FILE_HPP
elif [[ $1 == "cpp" ]];
then
touch $FILE_CPP
echo "#include \"$FILE_HPP\"" >> $FILE_CPP
echo >> $FILE_CPP
echo "$CLASS::$CLASS()" >> $FILE_CPP
echo "{" >> $FILE_CPP
echo -e "\tstd::cout << \"Constructor Called\\n\";" >> $FILE_CPP
echo "}" >> $FILE_CPP
echo >> $FILE_CPP
echo "$CLASS::$CLASS( const $CLASS © )" >> $FILE_CPP
echo "{" >> $FILE_CPP
echo -e "\t*this = copy;" >> $FILE_CPP
echo -e "\tstd::cout << \"Copy constructor called!\\n\";" >> $FILE_CPP
echo "}" >> $FILE_CPP
echo >> $FILE_CPP
echo "$CLASS &$CLASS::operator=( const $CLASS &obj )" >> $FILE_CPP
echo "{" >> $FILE_CPP
echo -e "\t( void )obj;" >> $FILE_CPP
echo -e "\tstd::cout << \"Copy assignment operator called!\\n\";" >> $FILE_CPP
echo >> $FILE_CPP
echo -e "\treturn *this;"
echo "}" >> $FILE_CPP
echo >> $FILE_CPP
echo "$CLASS::~$CLASS()" >> $FILE_CPP
echo "{" >> $FILE_CPP
echo -e "\tstd::cout << \"Destructor Called\\n\";" >> $FILE_CPP
echo "}" >> $FILE_CPP
echo >> $FILE_CPP
else
echo -e '\033[0;31mError: Creating New Files!\033[0m'
fi
}
create_main()
{
touch "main.cpp"
echo "#include \"$FILE_HPP\"" >> "main.cpp"
echo >> "main.cpp"
echo "int main( void )" >> "main.cpp"
echo "{" >> "main.cpp"
echo >> "main.cpp"
echo " return 0;" >> "main.cpp"
echo "}" >> "main.cpp"
echo >> "main.cpp"
}
check_exists()
{
if [[ -e $1 ]];
then
echo "$1 already exists!"
echo "Do you want to overwrite it? (y/n): "
read -r ans
if [[ "$ans" == "y" ]];
then
rm -rf $1
create_new ${1##*.}
success $1
else
exit 1
fi
else
create_new ${1##*.}
success $1
fi
}
check_main()
{
if [[ -e "main.cpp" ]];
then
echo "main.cpp already exists!"
echo "Do you want to overwrite it? (y/n): "
read -r ans
if [[ "$ans" == "y" ]];
then
rm -rf "main.cpp"
create_main
success "main.cpp"
else
exit 1
fi
else
create_main
success "main.cpp"
fi
}
check_exists $FILE_HPP
check_exists $FILE_CPP
check_main
##############
# by: jlebre #
#####################################
# Github: https://github.com/jlebre #
#####################################