-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript_cpp_class.sh
executable file
·101 lines (65 loc) · 2.11 KB
/
script_cpp_class.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
#!/bin/bash
read -p 'Nom de la classe: ' class
echo "#ifndef `echo $class | tr [a-z] [A-Z]`_HPP
# define `echo $class | tr [a-z] [A-Z]`_HPP
# include <string>
class $class {
public:
$class(void);
$class(std::string name, int const n);
$class($class const & src);
virtual ~$class();
$class & operator=($class const & rhs);
int get_n(void) const;
std::string get_name(void) const;
private:
std::string _name;
int _n;
};
std::ostream & operator<<(std::ostream & o, $class const & rhs);
#endif" > $class.hpp
echo "#include \"$class.hpp\"
#include <iostream>
/************************* CONSTRUCTORS *******************************/
$class::$class(void) {
std::cout << \"Default constructor called\" << std::endl;
return ;
}
$class::$class(std::string name, int const n) : _name(name), _n(n) {
return ;
}
$class::$class($class const & src) {
std::cout << \"Copy constructor called\" << std::endl;
*this = src;
return ;
}
/************************* DESTRUCTORS ********************************/
$class::~$class(void) {
std::cout << \"Destructor called\" << std::endl;
}
/************************* OPERATORS OVERLOAD *************************/
$class & $class::operator=($class const & rhs) {
std::cout << \"Assignation operator called\" << std::endl;
if (this != &rhs) {
this->_n = rhs.get_n();
this->_name = rhs.get_name();
}
return *this;
}
/************************* GETTERS ***********************************/
/************************* SETTERS ***********************************/
/************************* PUBLIC MEMBER FUNCTIONS *******************/
std::string $class::get_name(void) const {
return (this->_name);
}
int $class::get_n(void) const {
return (this->_n);
}
/************************* PRIVATE MEMBER FUNCTIONS *******************/
/************************* NON MEMBER FUNTIONS ************************/
/************************* EXTERNAL OVERLOADS *************************/
std::ostream & operator<<(std::ostream & o, $class const & rhs) {
o << rhs.get_name();
return (o);
}
" > $class.cpp