Last active
March 22, 2022 08:26
-
-
Save jkctech/7a7ddfe4b0e8ddd6ea122b74b49cf55c to your computer and use it in GitHub Desktop.
Automatic C++ class and header builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from sys import argv | |
if len(argv) != 2: | |
print("Syntax: python build.py <ClassName>") | |
exit(1) | |
classname = argv[1] | |
current = os.path.dirname(os.path.realpath(__file__)) | |
outfolder = os.getcwd() | |
files = ["Master.cpp", "Master.hpp"] | |
replacers = [ | |
["{ClassName}", classname], | |
["{VarName}", classname.lower()], | |
["{HeaderName}", classname.upper()] | |
] | |
for fname in files: | |
with open(current + "/" + fname, "r") as f: | |
lines = ''.join(f.readlines()) | |
for r in replacers: | |
lines = lines.replace(r[0], r[1]) | |
with open(outfolder + "/" + fname.replace("Master", classname), "w") as of: | |
of.write(lines) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ************************************************************************** */ | |
/* */ | |
/* :::::::: */ | |
/* Master.cpp :+: :+: */ | |
/* +:+ */ | |
/* By: JKCTech <[email protected]> +#+ */ | |
/* +#+ */ | |
/* Created: 2022/01/27 11:35:30 by JKCTech #+# #+# */ | |
/* Updated: 2022/03/21 10:01:43 by JKCTech ######## odam.nl */ | |
/* */ | |
/* ************************************************************************** */ | |
#include "{ClassName}.hpp" | |
#include <iostream> | |
// CONSTRUCTORS | |
{ClassName}::{ClassName}(void) | |
{ | |
std::cout << "{ClassName} constructor" << std::endl; | |
this->_priv = 69; | |
this->_prot = 420; | |
} | |
{ClassName}::{ClassName}(const {ClassName} &{VarName}) | |
{ | |
std::cout << "{ClassName} copy constructor" << std::endl; | |
this->_priv = {VarName}._priv; | |
this->_prot = {VarName}._prot; | |
} | |
{ClassName}::~{ClassName}(void) | |
{ | |
std::cout << "{ClassName} destructor" << std::endl; | |
} | |
// END CONSTRUCTORS | |
// Control operator | |
{ClassName} &{ClassName}::operator = (const {ClassName} &{VarName}) | |
{ | |
(void){VarName}; | |
return *this; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ************************************************************************** */ | |
/* */ | |
/* :::::::: */ | |
/* Master.hpp :+: :+: */ | |
/* +:+ */ | |
/* By: JKCTech <[email protected]> +#+ */ | |
/* +#+ */ | |
/* Created: 2022/02/10 09:21:17 by JKCTech #+# #+# */ | |
/* Updated: 2022/03/21 10:03:17 by JKCTech ######## odam.nl */ | |
/* */ | |
/* ************************************************************************** */ | |
#ifndef {HeaderName}_HPP | |
# define {HeaderName}_HPP | |
class {ClassName} | |
{ | |
private: | |
int _priv; | |
protected: | |
int _prot; | |
public: | |
// Constructors | |
{ClassName}(void); | |
{ClassName}(const {ClassName} &{VarName}); | |
~{ClassName}(void); | |
// Control operator | |
{ClassName} &operator = (const {ClassName} &{VarName}); | |
// Methods | |
void method(void); | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment