PhoenixGenerator  3.4.0
Generate code from template files and projects in C++, Rust, Python and wrapped C++ to Python
Loading...
Searching...
No Matches
nanobind_generator.h File Reference
#include "ProjectParam.h"
Include dependency graph for nanobind_generator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool generator_nanobind_class (const PNanobindTraitBackendManager &manager, const PPath &sourceFile, const PPath &headerFile, const PVecClassConfig &vecClassConfig, 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_test (const PNanobindTraitBackendManager &manager, const PPath &outputTestDir, const std::vector< PClassConfig > &vecClassConfig, const PString &projectName, const PPath &baseFileName, const GeneratorMode &mode)
 Generate test with nanobind.

Function Documentation

◆ generator_nanobind_class()

bool generator_nanobind_class ( const PNanobindTraitBackendManager & manager,
const PPath & sourceFile,
const PPath & headerFile,
const PVecClassConfig & vecClassConfig,
const GeneratorMode & mode )

References generator_nanobind_class(), generator_nanobind_full(), and generator_nanobind_test().

Here is the call graph for this function:

◆ generator_nanobind_full()

bool generator_nanobind_full ( const PNanobindTraitBackendManager & manager,
const ProjectParam & projectParam )

Generate the full sources and related unit tests from configuration.

Parameters
manager: PTraitBackendManager which handles all trait backend
projectParam: description of classes and how and where to generate sources and test
Returns
true on success, false otherwise

Definition at line 101 of file nanobind_generator.cpp.

102{
103 bool b(true);
104 b &= projectParam.outputSourceDir.createDirectory();
105 b &= projectParam.outputTestDir.createDirectory();
106 const PVecDataConfig & vecDataConfig = projectParam.vecDataConfig;
107
108 for(const PDataConfig & config : vecDataConfig){
109 const PVecPath & extraInclude = config.getVecInclude();
110 PPath baseFileName = config.getFileName().getFileName().eraseExtension();
111 PPath headerFile = projectParam.outputSourceDir / PPath(baseFileName + ".h");
112 PPath sourceFile = projectParam.outputSourceDir / PPath(baseFileName + "_binding.cpp");
113 if(!generator_nanobind_class(manager, baseFileName, sourceFile, headerFile, extraInclude, config.getVecClassConfig(), projectParam.mode)){
114 std::cerr << termRed() << "generator_nanobind_full : cannot generate nanobind sources at '"<<projectParam.outputSourceDir<<"'" << termDefault() << std::endl;
115 b = false; //best effort strategy
116 }
117 PPath outputCurrentTestDir = projectParam.outputTestDir / PPath("TEST_PYTHON_BINDINGS");
118 if(!generator_nanobind_test(manager, outputCurrentTestDir, config.getVecClassConfig(), projectParam.name, baseFileName, projectParam.mode)){
119 std::cerr << termRed() << "generator_nanobind_full : cannot generate nanobind tests at '"<<projectParam.outputTestDir<<"'" << termDefault() << std::endl;
120 b = false; //best effort strategy
121 }
122 }
123 return b;
124}
std::vector< PDataConfig > PVecDataConfig
Definition PDataConfig.h:48
Class to describe a basic class.
Definition PDataConfig.h:17
bool generator_nanobind_test(const PNanobindTraitBackendManager &manager, const PPath &outputTestDir, const std::vector< PClassConfig > &vecClassConfig, const PString &projectName, const PPath &baseFileName, const GeneratorMode &mode)
Generate test with nanobind.
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.
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.

References generator_nanobind_class(), generator_nanobind_full(), generator_nanobind_test(), ProjectParam::mode, ProjectParam::name, ProjectParam::outputSourceDir, ProjectParam::outputTestDir, and ProjectParam::vecDataConfig.

Referenced by generateNanobindClassesFull(), generator_nanobind_class(), and generator_nanobind_full().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generator_nanobind_test()

bool generator_nanobind_test ( const PNanobindTraitBackendManager & manager,
const PPath & outputTestDir,
const std::vector< PClassConfig > & vecClassConfig,
const PString & projectName,
const PPath & baseFileName,
const GeneratorMode & mode )

Generate test with nanobind.

Parameters
manager: PTraitBackendManager which handles all trait backend
outputTestDir: output test directory
vecClassConfig: configuration to be generated
projectName: name of the project
baseFileName: base file name to be used (without path and extension)
mode: mode of the generator
Returns
true on success, false otherwise

Definition at line 79 of file nanobind_generator.cpp.

79 {
80 for(std::vector<PClassConfig>::const_iterator it(vecClassConfig.begin()); it != vecClassConfig.end(); ++it){
81 PString name = it->getName();
82 PPath outputCurrentTestDir(outputTestDir + PString("/TEST_") + name.toUpper() + "_BINDINGS");
83 if(!outputCurrentTestDir.createDirectory()){
84 std::cerr << "generator_class_test : cannot create TEST directory '"<<outputCurrentTestDir<<"'" << std::endl;
85 return false;
86 }
87 std::ofstream fs;
88 if(!openFileStream(fs, PPath(outputCurrentTestDir + PString("/test_") + name + "_binding.py"))){return false;}
89 manager.headerTestInclude(fs, mode, baseFileName);
90 manager.testFunction(fs, *it, mode, baseFileName);
91 fs.close();
92 }
93 return true;
94}
virtual void headerTestInclude(std::ofstream &fs, const GeneratorMode &mode, const PString &baseFileName) const
Add extra include on the test header.
virtual void testFunction(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode, const PString &baseFileName) const
Implementation of test function.

References generator_nanobind_test(), PNanobindTraitBackendManager::headerTestInclude(), and PNanobindTraitBackendManager::testFunction().

Referenced by generator_nanobind_class(), generator_nanobind_full(), and generator_nanobind_test().

Here is the call graph for this function:
Here is the caller graph for this function: