22 return "get" + varName.firstToUpper();
30 return "set" + varName.firstToUpper();
41 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
42 fs <<
"\t\t.def_prop_rw(\"" << 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){
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;
67 for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){
69 fs <<
"\t" << className <<
"." << it->getName() <<
" = " << defaultValue << std::endl;
70 fs <<
"\t" <<
"assert " << className <<
"." << it->getName() <<
" == " << defaultValue << std::endl;
82 fs <<
"\ttest_attributes_setters_getters()" << std::endl;
PString createSetterMethodName(const PString &varName)
Creates a setter method name.
PString createGetterMethodName(const PString &varName)
Creates a getter method name.
std::vector< PClassAttribute > PVecClassAttribute
virtual ~NanobindTraitProperty()
Destructor of NanobindTraitProperty.
NanobindTraitProperty()
Constructor of NanobindTraitProperty.
virtual void testCallFunction(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 testFunction(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode, const PString &baseFileName) const
PAbstractNanobindTraitBackend()
Class to describe a basic class.
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 getTestDefaultValueTypeInPython(const PString &type)
Get default test value for a given type in Python.
PString makeVarType(const PString &varType, bool isSetter, bool isConst, bool isRef, bool isPtr)
Makes the var type by taking account of the type.