7#include "openFileStream.h"
18 for(PVecClassConfig::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
20 std::string varName(it->getName()+
"EnumType");
21 fs <<
"\t//PyObject* "+varName+
" = (PyObject*)Py_TYPE(WP"+it->getName()+
"_newC(NULL, NULL, NULL));\t//1: A nice segmentation fault of python\n";
22 fs <<
"\tPyObject* "+varName+
" = WP"+it->getName()+
"_newC(NULL, NULL, NULL);\t//2: alone => SystemError: initialization of pystereodata raised unreported exception, while importing generated module\n";
23 fs <<
"\tif("+varName+
" == NULL){" << std::endl;
24 fs <<
"\t\tstd::cerr << \"Cannot create enum '"<<it->getName()<<
"'\" << std::endl;" << std::endl;
25 fs <<
"\t\treturn NULL;" << std::endl;
26 fs <<
"\t}" << std::endl;
29 fs <<
"\tif(PyType_Ready(&WP"+it->getName()+
"Type) < 0){return NULL;}\n";
39 for(PVecClassConfig::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
41 fs <<
"\t//Py_INCREF("+it->getName()+
"EnumType);\t//2: An other segmentation fault of python, when pytest is collecting tests\n";
43 fs <<
"\tPy_INCREF(&WP"+it->getName()+
"Type);\n";
53 for(PVecClassConfig::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
55 fs <<
"\tPyModule_AddObject(m, \""+it->getName()+
"\", "+it->getName()+
"EnumType);\n";
57 fs <<
"\tPyModule_AddObject(m, \""+it->getName()+
"\", (PyObject *)&WP"+it->getName()+
"Type);\n";
70 if(!openFileStream(fs, fileName)){
return false;}
78 fs <<
"#include <Python.h>\n";
79 fs <<
"#include \"structmember.h\"\n";
82 fs <<
"#include <string>\n";
83 fs <<
"#include <iostream>\n";
86 fs <<
"#include \"" << config.
getFileName().getFileName().eraseExtension() <<
"_wrapper.h\"\n";
91 fs <<
"static PyMethodDef _"+moduleName+
"_methods[] = {\n";
92 fs <<
"\t{NULL, NULL}\n";
95 fs <<
"static PyModuleDef _"+moduleName+
"_module = {\n";
96 fs <<
"\tPyModuleDef_HEAD_INIT,\n";
97 fs <<
"\t\""+moduleName+
"\",\n";
100 fs <<
"\t_"+moduleName+
"_methods,\n";
107 fs <<
"///Create the python module "+moduleName+
"\n";
108 fs <<
"/**\t@return python module "+moduleName+
"\n";
110 fs <<
"PyMODINIT_FUNC PyInit_"+moduleName+
"(void){\n";
117 fs <<
"\tPyObject * m = PyModule_Create(&_"+moduleName+
"_module);\n";
118 fs <<
"\tif(m == NULL){\n";
119 fs <<
"\t\treturn NULL;\n";
130 fs <<
"\treturn m;\n";
std::vector< PClassConfig > PVecClassConfig
Class to describe a basic class.
const PVecClassConfig & getVecClassConfig() const
Get the vector of all config class of the current pdata file.
const PPath & getFileName() const
Get the file name of the current PDataConfig.
PString moduleName
Name of the wrapper python module.
Set of parameters to generate a project.
GeneratorMode mode
Mode to be used to generate the project.
PVecDataConfig vecDataConfig
Configuration of classes to be generated.
void project_wrapper_modulePyTypeReady(std::ofstream &fs, const PVecClassConfig &vecClassConfig)
Create the PyType_Ready for all classes of the module.
bool project_wrapper_moduleGeneratorMain(const PPath &fileName, const ProjectParam &projectParam)
Create the main wrapper module.
void project_wrapper_moduleAddObject(std::ofstream &fs, const PVecClassConfig &vecClassConfig)
Create the Py_INCREF for all classes of the module.
void project_wrapper_modulePyIncref(std::ofstream &fs, const PVecClassConfig &vecClassConfig)
Create the Py_INCREF for all classes of the module.