PhoenixGenerator  2.0.4
Set of tools to generate code
Loading...
Searching...
No Matches
WrapperTraitGetterSetter.cpp
Go to the documentation of this file.
1
2/***************************************
3 Auteur : Pierre Aubert
4 Mail : pierre.aubert@lapp.in2p3.fr
5 Licence : CeCILL-C
6****************************************/
7
9
14
17
19
22void WrapperTraitGetterSetter::headerExtraInclude(std::ofstream & fs, const GeneratorMode & mode) const{
23 if(!mode.enableSetter || !mode.enableGetter){return;}
24
25}
26
28
32void WrapperTraitGetterSetter::classMethodDeclaration(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
33 if(!mode.enableSetter || !mode.enableGetter || classConfig.getIsEnum()){return;}
34 PString className(wrapper_getClassName(classConfig));
35 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
36 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
37 //If the type is simple, we do not need getter, setter and other methods
38 if(getIsSimpleType(it->getType())){continue;}
39 fs << "int "+className+"_set"+it->getName()+"("+className+" * self, PyObject * value, void * closure);\n";
40 fs << "PyObject * "+className+"_get"+it->getName()+"("+className+" * self, void * closure);\n";
41 }
42}
43
45
49void WrapperTraitGetterSetter::classMethodImplementation(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
50 if(!mode.enableSetter || !mode.enableGetter || classConfig.getIsEnum()){return;}
51 PString body, className(wrapper_getClassName(classConfig));
52 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
53 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
54 if(getIsSimpleType(it->getType())){continue;}
55 PString attrName(it->getName()), attrDoc(it->getDocumentation());
56 fs << "///Setter of the "+attrName+"\n";
57 fs << "/**\t@param self : object "+className+"\n";
58 fs << " * \t@param value : "+attrDoc+"\n";
59 fs << " * \t@param closure : object closure for python API (it is a wrapper python grosse bidouille)\n";
60 fs << " * \t@return 0 on success, -1 otherwise\n";
61 fs << "*/\n";
62 fs << "int "+className+"_set"+attrName+"("+className+" * self, PyObject * value, void * closure){\n";
63 fs << "\tif(value == NULL){\n";
64 fs << "\t\tPyErr_SetString(PyExc_TypeError, \"Cannot delete the "+className+"."+attrName+" attribute\");\n";
65 fs << "\t\treturn -1;\n";
66 fs << "\t}\n";
67 fs << "\tPy_DECREF(self->"+attrName+");\n";
68 fs << "\tPy_INCREF(value);\n";
69 fs << "\tself->"+attrName+" = value;\n";
70 fs << "\treturn 0;\n";
71 fs << "}\n\n";
72
73 fs << "///Setter of the "+attrName+"\n";
74 fs << "/**\t@param self : object "+className+"\n";
75 fs << " * \t@param closure : object closure for python API (it is a wrapper python grosse bidouille)\n";
76 fs << " * \t@return "+attrDoc+"\n";
77 fs << "*/\n";
78 fs << "PyObject * "+className+"_get"+attrName+"("+className+" * self, void * closure){\n";
79 fs << "\tPy_INCREF(self->"+attrName+");\n";
80 fs << "\treturn self->"+attrName+";\n";
81 fs << "}\n\n";
82
83 }
84}
85
87
91void WrapperTraitGetterSetter::registerClassMember(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
92 if(!mode.enableSetter || !mode.enableGetter){return;}
93 PString className(wrapper_getClassName(classConfig));
94 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
95 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
96 if(!getIsSimpleType(it->getType())){
97 continue;
98 }
99 fs << "\t{(char*)\""<<it->getName()<<"\", "+getPythonStrForPythonApiType(it->getType())<<", offsetof("<<className<<", "<<it->getName()<<"), 0, (char*)\"Doc : "<<it->getDocumentation().replace("///", "")<<"\"},\n";
100 }
101}
102
104
108void WrapperTraitGetterSetter::registerClassGetterSetter(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
109 if(!mode.enableSetter || !mode.enableGetter){return;}
110 PString className(wrapper_getClassName(classConfig));
111 const PVecClassAttribute & vecAttr = classConfig.getListAttribute();
112 for(PVecClassAttribute::const_iterator it(vecAttr.begin()); it != vecAttr.end(); ++it){
113 if(getIsSimpleType(it->getType())){
114 continue;
115 }
116 fs << "\t{(char*)\""<<it->getName()+"\", (getter)"<<className+"_get"<<it->getName()<<", (setter)"<<className+"_set"+it->getName()<<", (char*)\""+it->getDocumentation().replace("///", "")+"\", NULL},\n";
117 }
118}
119
121
125void WrapperTraitGetterSetter::registerClassMethod(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
126 if(!mode.enableSetter || !mode.enableGetter){return;}
127
128}
129
131
135void WrapperTraitGetterSetter::testFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
136 if(!mode.enableSetter || !mode.enableGetter){return;}
137
138}
139
141
145void WrapperTraitGetterSetter::testCallFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{
146 if(!mode.enableSetter || !mode.enableGetter){return;}
147
148}
149
150
151
std::vector< PClassAttribute > PVecClassAttribute
Definition PDataConfig.h:13
Class to describe a basic class.
const std::vector< PClassAttribute > & getListAttribute() const
Returns the list of attributes of the class.
bool getIsEnum() const
Say if the current PClassConfig is an enum.
virtual void classMethodImplementation(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of class method.
virtual void classMethodDeclaration(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Declaration of class method.
virtual void registerClassGetterSetter(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Register class getter and setter.
virtual void registerClassMethod(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Register class method.
virtual void testFunction(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Implementation of test function.
virtual ~WrapperTraitGetterSetter()
Desctructor of WrapperTraitGetterSetter.
virtual void headerExtraInclude(std::ofstream &fs, const GeneratorMode &mode) const
Add extra include on the header.
virtual void registerClassMember(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Register class member.
virtual void testCallFunction(std::ofstream &fs, const PClassConfig &classConfig, const GeneratorMode &mode) const
Call of the test function.
WrapperTraitGetterSetter()
Consctructor of WrapperTraitGetterSetter.
All the genertor modes.
bool enableGetter
True to enable getters trait generator.
bool enableSetter
True to enable setters trait generator.
bool getIsSimpleType(const PString &varType)
Check if the given type is a simple type.
PString getPythonStrForPythonApiType(const PString &typeStr)
Gets the python API str type of the correcponding numpy C/C++ type.
PString wrapper_getClassName(const PClassConfig &classConfig)
Get the corresponding wrapper class name.