-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmkclass
More file actions
executable file
·66 lines (53 loc) · 1.11 KB
/
mkclass
File metadata and controls
executable file
·66 lines (53 loc) · 1.11 KB
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
#!/bin/bash
# author: github.com/0yech
# thank you !
if [ -z "$1" ]; then
echo "Usage: mkclass ClassName"
exit 1
fi
NAME=$1
# Header file
cat > ${NAME}.hpp <<EOF
#ifndef ${NAME^^}_HPP
#define ${NAME^^}_HPP
#include <iostream>
#include <string>
class ${NAME}
{
public:
${NAME}();
${NAME}(const ${NAME}& other);
${NAME}& operator=(const ${NAME}& other);
virtual ~${NAME}(); // remove virtual if needed
// Methods
};
#endif
EOF
# src file
cat > ${NAME}.cpp <<EOF
#include "${NAME}.hpp"
${NAME}::${NAME}()
{
std::cout << "${NAME} default constructor called" << std::endl;
}
${NAME}::${NAME}(const ${NAME}& other)
{
std::cout << "${NAME} copy constructor called" << std::endl;
*this = other;
}
${NAME}& ${NAME}::operator=(const ${NAME}& other)
{
std::cout << "${NAME} assignment operator called" << std::endl;
if (this != &other)
{
// copy fields/data
}
return *this;
}
${NAME}::~${NAME}()
{
std::cout << "${NAME} destructor called" << std::endl;
}
EOF
chmod 644 ${NAME}.hpp ${NAME}.cpp
echo "Created: ${NAME}.hpp and ${NAME}.cpp"