PhoenixGenerator  2.2.0
Set of tools to generate code
Loading...
Searching...
No Matches
NanobindTraitProperty Class Reference

Class generator for Nanobind property trait. More...

#include <NanobindTraitProperty.h>

+ Inheritance diagram for NanobindTraitProperty:
+ Collaboration diagram for NanobindTraitProperty:

Public Member Functions

virtual void headerExtraInclude (std::set< std::string > &includes, const PClassConfig &classConfig, const GeneratorMode &mode) const
 
virtual void headerTestInclude (std::ofstream &fs, const GeneratorMode &mode, const PString &baseFileName) const
 
 NanobindTraitProperty ()
 Constructor of NanobindTraitProperty.
 
virtual void registerConstructor (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 
virtual void registerMethod (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 
virtual void registerProperty (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 Registration of property.
 
virtual void registerStaticMethod (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 
virtual void testCallFunction (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
 
virtual void testFunction (std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode, const PString &baseFileName) const
 
virtual ~NanobindTraitProperty ()
 Destructor of NanobindTraitProperty.
 

Detailed Description

Class generator for Nanobind property trait.

Definition at line 15 of file NanobindTraitProperty.h.

Constructor & Destructor Documentation

◆ NanobindTraitProperty()

NanobindTraitProperty::NanobindTraitProperty ( )

Constructor of NanobindTraitProperty.

Definition at line 10 of file NanobindTraitProperty.cpp.

References PAbstractNanobindTraitBackend::PAbstractNanobindTraitBackend().

+ Here is the call graph for this function:

◆ ~NanobindTraitProperty()

NanobindTraitProperty::~NanobindTraitProperty ( )
virtual

Destructor of NanobindTraitProperty.

Definition at line 15 of file NanobindTraitProperty.cpp.

15{}

Member Function Documentation

◆ headerExtraInclude()

virtual void PAbstractNanobindTraitBackend::headerExtraInclude ( std::set< std::string > & includes,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
inlinevirtualinherited

Reimplemented in NanobindTraitInclude.

Definition at line 70 of file PAbstractTraitBackend.h.

70{}

◆ headerTestInclude()

virtual void PAbstractNanobindTraitBackend::headerTestInclude ( std::ofstream & fs,
const GeneratorMode & mode,
const PString & baseFileName ) const
inlinevirtualinherited

Reimplemented in NanobindTraitTestSetup.

Definition at line 71 of file PAbstractTraitBackend.h.

71{}

◆ registerConstructor()

virtual void PAbstractNanobindTraitBackend::registerConstructor ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
inlinevirtualinherited

Reimplemented in NanobindTraitMethod.

Definition at line 76 of file PAbstractTraitBackend.h.

76{}

◆ registerMethod()

virtual void PAbstractNanobindTraitBackend::registerMethod ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
inlinevirtualinherited

Reimplemented in NanobindTraitDataStream.

Definition at line 75 of file PAbstractTraitBackend.h.

75{}

◆ registerProperty()

void NanobindTraitProperty::registerProperty ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Registration of property.

Registration of property

Parameters
fsstream to write to
classConfigconfig of the class
modegenerator mode

Reimplemented from PAbstractNanobindTraitBackend.

Definition at line 37 of file NanobindTraitProperty.cpp.

37 {
38 if(!mode.enableSetter || !mode.enableGetter || classConfig.getIsEnum()){return;}
39
40 const PVecClassAttribute & listAttr(classConfig.getListAttribute());
41 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
42 fs << "\t\t.def_prop_rw(\"" << it->getName() << "\",";
43 fs << std::endl << "\t\t\t[]( " << classConfig.getName() << " &c) { return c." << createGetterMethodName(it->getName()) << "(); },";
44 fs << std::endl << "\t\t\t[]( " << classConfig.getName() << " &c, " << makeVarType(it->getType(), true, false, false, it->getIsPointer()) << " value) { c." << createSetterMethodName(it->getName()) << "(value); })";
45 if(it != listAttr.end() - 1){
46 fs << std::endl;
47 }
48 }
49}
PString createSetterMethodName(const PString &varName)
Creates a setter method name.
PString createGetterMethodName(const PString &varName)
Creates a getter method name.
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.
const PString & getName() const
Returns the class name.
bool getIsEnum() const
Say if the current PClassConfig is an enum.
bool enableGetter
True to enable getters trait generator.
bool enableSetter
True to enable setters trait generator.
PString makeVarType(const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
Makes the var type by taking account of the type.

References createGetterMethodName(), createSetterMethodName(), GeneratorMode::enableGetter, GeneratorMode::enableSetter, PClassConfig::getIsEnum(), PClassConfig::getListAttribute(), PClassConfig::getName(), and makeVarType().

+ Here is the call graph for this function:

◆ registerStaticMethod()

virtual void PAbstractNanobindTraitBackend::registerStaticMethod ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
inlinevirtualinherited

Reimplemented in NanobindTraitCheckStream, and NanobindTraitTypeStream.

Definition at line 74 of file PAbstractTraitBackend.h.

74{}

◆ testCallFunction()

void NanobindTraitProperty::testCallFunction ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode ) const
virtual

Call of the test function

Parameters
fsstream to write to
classConfigconfig of the class
modegenerator mode

Reimplemented from PAbstractNanobindTraitBackend.

Definition at line 79 of file NanobindTraitProperty.cpp.

79 {
80 if(!mode.enableSetter || !mode.enableSetter || classConfig.getIsEnum()){return;}
81
82 fs << "\ttest_attributes_setters_getters()" << std::endl;
83}

References GeneratorMode::enableSetter, and PClassConfig::getIsEnum().

+ Here is the call graph for this function:

◆ testFunction()

void NanobindTraitProperty::testFunction ( std::ofstream & fs,
const PClassConfig & classConfig,
const GeneratorMode & mode,
const PString & baseFileName ) const
virtual

Generate test function for property

Parameters
fsstream to write to
classConfigconfig of the class
modegenerator mode
baseFileName: base name of the configuration

Reimplemented from PAbstractNanobindTraitBackend.

Definition at line 56 of file NanobindTraitProperty.cpp.

56 {
57 if(!mode.enableSetter || !mode.enableSetter || classConfig.getIsEnum()){return;}
58 PString moduleName = baseFileName.toLower() + "_module";
59 PString className = classConfig.getName().toLower();
60 fs << "#Test getters and setters of the " << classConfig.getName() << " property trait" << std::endl;
61 fs << "def test_attributes_setters_getters():" << std::endl;
62 fs << "\t\"\"\"Test setters and getters of attributes generated by Nanobind\"\"\"" << std::endl;
63 fs << "\t" << "# Test default constructor" << std::endl;
64 fs << "\t" << className << " = " << moduleName << "." << classConfig.getName() << "()" << std::endl;
65 fs << "\t" << "# Test properties" << std::endl;
66 const PVecClassAttribute & listAttr(classConfig.getListAttribute());
67 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
68 PString defaultValue = getTestDefaultValueTypeInPython(it->getType());
69 fs << "\t" << className << "." << it->getName() << " = " << defaultValue << std::endl;
70 fs << "\t" << "assert " << className << "." << it->getName() << " == " << defaultValue << std::endl;
71 }
72 fs << std::endl;
73}
PString getTestDefaultValueTypeInPython(const PString &type)
Get default test value for a given type in Python.

References GeneratorMode::enableSetter, PClassConfig::getIsEnum(), PClassConfig::getListAttribute(), PClassConfig::getName(), and getTestDefaultValueTypeInPython().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: