🇫🇷 French documentation available here
💡 You can check your bash version with
bash --version
- Your bash version is >= 4.0 : you can run using the following command
bash <(curl -fsSL --connect-timeout 10 https://raw.githubusercontent.com/nsainton/classcreator/main/classcreator.sh) Classname header_dir sources_dir
- Your bash version is < 4.0 : you can run using the following command
curl -fsSL --connect-timeout 10 https://raw.githubusercontent.com/nsainton/classcreator/main/classcreator.sh -o /tmp/classcreator.sh && sh /tmp/classcreator.sh Classname header_dir sources_dir
This script can create a .cpp file and a .h file for a C++ class with the name "Classname" (quotes omitted).
This class will contain :
- A default constructor
Classname::Classname()
- A copy constructor
Classname::Classname( const Classname & other )
- A copy assignment operator
Classname & Classname::Classname( const Classname & other )
- A virtual destructor
Classname::~Classname()
It is designed to comply with the Orthodox canonical form and is such that the file outputed by the Script will compile right away with all the compiler warnings enabled.
Although they do absolutely nothing apart from writting the functions that are called to std::clog ostream object.
This script can be executed in 3 distinct ways :
- sh classcreator.sh Classname -> creates a Classname.cpp and Classname.h class file in the current directory
- sh classcreator.sh Classname dir -> creates a dir/Classname.cpp and a dir/Classname.h file in the specified directory
- sh classcreator.sh Classname header_dir class_dir -> creates a header_dir/classname.h and a class_dir/classname.cpp file in the specified directories and source files
💡 Any non-existent directory will be created by the script
Let's run the command : sh classcreator.sh Test includes sources
in an empty directory
We will get two new files : sources/Test.cpp and includes/Test.h
💡 Both files are also available in the "examples" folder
This is what the Test.h file looks like :
#ifndef __TEST_H__
# define __TEST_H__
class Test{
public:
Test();
Test( const Test & );
Test& operator=( const Test & );
virtual ~Test();
};
#endif
This is what the Test.cpp file looks like :
#include "Test.h"
Test::Test(){
}
Test::Test( const Test & other ){
(void)other;
}
Test& Test::operator=( const Test & other ){
(void)other;
return (*this);
}
Test::~Test(){
}
The Test.cpp source file can be compiled right away without raising any warning.
Run the script without any argument :
sh classcreator.sh
To get a help message about how to run the script.
There are two ways to contribute to this project
- Send me a message on discord (for 42 students) or to the following email
- Pull requests that are currently closed but are going to be oppened soon for you to add all your amazing features to the project