A simple code generator library
Project description
Code Generator
Simple and straightforward code generator for creating C++ code. It also could be used for generating code in any programming language.
Every C++ element could render its current state to a string that could be evaluated as a legal C++ construction. Some elements could be rendered to a pair of representations (C++ classes and functions declaration and implementation)
Usage examples
C++ Variables
Python code:
var_count = Variable(name='count', type='int').val(0)
var_pi = Variable(name='pi', type='float').val(3.14)
var_title = Variable(name='title', type='const char *').val('Title:')
source = Source('main.cpp').add(var_count).add(var_pi).add(var_title)
str(source)
Generated C++ code:
int count = 0;
float pi = 3.14;
const char * title = "Title:";
C++ Functions
Python code:
def factorial_definition():
return 'return n < 1 ? 1 : (n * factorial(n - 1));'
factorial_function = Function(name='factorial', type='int')
.arg('int n')
.impl(factorial_definition)
source = Source('main.cpp').add(factorial_function)
str(source)
Generated C++ code:
int factorial(int n)
{
return n <= 1 ? 1 : (n * factorial(n - 1));
}
C++ Classes and Structures
Python code:
var_name = Variable(name='name', type='std::string')
fn_getname = Function(name='GetName', type='std::string', qualifiers=['const']).impl('return name;')
fn_setname = Function(name='SetName').arg('std::string & new_name').impl('name = new_name;')
cls_person = Class(name='Person')
.member(var_name, scope='private')
.method(fn_getname, scope='public')
.method(fn_setname, scope='public')
header = Header('Person.h').add(cls_person)
source = Source('Person.cpp').include(header).add(cls_person)
str(header)
str(source)
Generated C++ code for Person.h:
class Person
{
public:
std::string GetName() const;
void SetName(std::string & name);
private:
std::string name;
};
Generated C++ code for Person.cpp:
std::string Person::GetName() const
{
return name;
}
void Person::SetName(std::string & new_name)
{
name = new_name;
}
Maintainers
See DEVELOPERS.md
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file erichschroeter_code_generator-0.1.0.tar.gz.
File metadata
- Download URL: erichschroeter_code_generator-0.1.0.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d054c47f35eac2d024f61f9e73e43ed0fc83803bc0e176b60513242cbf5fe0ac
|
|
| MD5 |
1d27bf6edb6c665579a815ceb7b58790
|
|
| BLAKE2b-256 |
dbb4db4ff448f4dfdfefaeb2fc26d734c0069f1bffc3ad334cf01e1aa62afb7c
|
File details
Details for the file erichschroeter.code_generator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: erichschroeter.code_generator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
823434292c87eecf4faa44f70503b968ad76ecc057d9333f6c00660e8de2473b
|
|
| MD5 |
0bc7fe7382e5fbaf8396c68a89afc7c5
|
|
| BLAKE2b-256 |
a0c82436cb94111f8e69b55fd60098a20a6eed6ada1bd4a7c158e417eb9dec2b
|