10#include "phoenix_color.h"
11#include "openFileStream.h"
24 if(baseFileName ==
""){
25 std::cerr << termRed() <<
"generator_class_cpp : baseFileName is empty" << termDefault() << std::endl;
29 if(!openFileStream(fs, sourceFile)){
return false;}
31 fs << std::endl <<
"#include \"" << headerFile.getFileName() <<
"\"" << std::endl << std::endl;
32 fs <<
"#include <nanobind/nanobind.h>" << std::endl;
33 std::set<std::string> extraIncludes;
34 for (std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
37 for (
const std::string & include : extraIncludes){
38 fs << include << std::endl;
40 fs <<
"\nnamespace nb = nanobind;" << std::endl << std::endl;
41 PString fileModuleName = baseFileName.toLower() +
"_module";
42 fs <<
"NB_MODULE(" << fileModuleName <<
", m) {" << std::endl;
43 fs <<
"\tm.doc() = \"Nanobind bindings for " << baseFileName <<
" classes\";\n" << std::endl;
45 for (std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
46 fs <<
"\tnb::class_<" << it->getName() <<
">(m, \"" << it->getName() <<
"\")" << std::endl;
47 fs <<
"\t\t//Attributes" << std::endl;
53 fs <<
";" << std::endl << std::endl;
56 fs <<
"}" << std::endl;
62 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
63 PString name = it->getName();
64 PPath outputCurrentTestDir(outputTestDir + PString(
"/TEST_") + name.toUpper() +
"_BINDINGS");
65 if(!outputCurrentTestDir.createDirectory()){
66 std::cerr <<
"generator_class_test : cannot create TEST directory '"<<outputCurrentTestDir<<
"'" << std::endl;
70 if(!openFileStream(fs, PPath(outputCurrentTestDir + PString(
"/test_") + name +
"_binding.py"))){
return false;}
91 const PVecPath & extraInclude = config.getVecInclude();
92 PPath baseFileName = config.getFileName().getFileName().eraseExtension();
93 PPath headerFile = projectParam.
outputSourceDir / PPath(baseFileName +
".h");
94 PPath sourceFile = projectParam.
outputSourceDir / PPath(baseFileName +
"_binding.cpp");
95 if(!
generator_nanobind_class(manager, baseFileName, sourceFile, headerFile, extraInclude, config.getVecClassConfig(), projectParam.
mode)){
96 std::cerr << termRed() <<
"generator_nanobind_full : cannot generate nanobind sources at '"<<projectParam.
outputSourceDir<<
"'" << termDefault() << std::endl;
99 PPath outputCurrentTestDir = projectParam.
outputTestDir / PPath(
"TEST_PYTHON_BINDINGS");
101 std::cerr << termRed() <<
"generator_nanobind_full : cannot generate nanobind tests at '"<<projectParam.
outputTestDir<<
"'" << termDefault() << std::endl;
std::vector< PDataConfig > PVecDataConfig
std::vector< PClassConfig > PVecClassConfig
Class to describe a basic class.
Manager of the Trait backends.
virtual void headerTestInclude(std::ofstream &fs, const GeneratorMode &mode, const PString &baseFileName) const
Add extra include on the test header.
virtual void registerStaticMethod(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Registration of static method.
virtual void headerExtraInclude(std::set< std::string > &setInclude, const PClassConfig &classConfig, const GeneratorMode &mode) const
Add extra include on the header.
virtual void registerProperty(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Registration of property.
virtual void testFunction(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode, const PString &baseFileName) const
Implementation of test function.
virtual void registerMethod(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Registration of method.
virtual void registerConstructor(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Registration of constructor.
bool generator_nanobind_test(const PNanobindTraitBackendManager &manager, const PPath &outputTestDir, const std::vector< PClassConfig > &vecClassConfig, const PString &projectName, const PPath &baseFileName, const GeneratorMode &mode)
bool generator_nanobind_full(const PNanobindTraitBackendManager &manager, const ProjectParam &projectParam)
Generate the full sources and related unit tests from configuration.
bool generator_nanobind_class(const PNanobindTraitBackendManager &manager, PPath &baseFileName, const PPath &sourceFile, const PPath &headerFile, const PVecPath &extraInclude, const PVecClassConfig &vecClassConfig, const GeneratorMode &mode)
Generate nanobind wrapper class.
Set of parameters to generate a project.
GeneratorMode mode
Mode to be used to generate the project.
PPath outputTestDir
Output path of the unit tests.
PVecDataConfig vecDataConfig
Configuration of classes to be generated.
PString name
Name of the project.
PPath outputSourceDir
Output path of the sources.