add support of static and class methods in Python wrappers

This commit is contained in:
wmayer
2019-11-12 23:24:42 +01:00
parent 0c99d32dd4
commit 5c7bef0ad8
3 changed files with 103 additions and 4 deletions

View File

@@ -45,6 +45,11 @@ class TemplateClassPyExport (template.ModelTemplate):
#include <@self.export.Include@>
#include <string>
+ if(self.export.ForwardDeclarations != ""):
// Forward declarations
@self.export.ForwardDeclarations@
-
namespace @self.export.Namespace@
{
@@ -96,14 +101,18 @@ public:
+ if i.Keyword:
/// callback for the @i.Name@() method
static PyObject * staticCallback_@i.Name@ (PyObject *self, PyObject *args, PyObject *kwd);
+ if not i.Static and not i.Class:
/// implementer for the @i.Name@() method
PyObject* @i.Name@(PyObject *args, PyObject *kwd);
-
= else:
/// callback for the @i.Name@() method
static PyObject * staticCallback_@i.Name@ (PyObject *self, PyObject *args);
+ if not i.Static and not i.Class:
/// implementer for the @i.Name@() method
PyObject* @i.Name@(PyObject *args);
-
-
-
//@}
@@ -231,7 +240,7 @@ public:
/// getter for the object handled by this class
@self.export.TwinPointer@ *get@self.export.Twin@Ptr(void) const;
+ if(self.export.ClassDeclarations != None):
+ if(self.export.ClassDeclarations != ""):
/** @name additional declarations and methods for the wrapper class */
//@{
@self.export.ClassDeclarations@
@@ -352,8 +361,22 @@ PyMethodDef @self.export.Name@::Methods[] = {
+ for i in self.export.Methode:
{"@i.Name@",
+ if i.Keyword:
+ if i.Class:
reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) (void)>( staticCallback_@i.Name@ )),
METH_VARARGS|METH_KEYWORDS|METH_CLASS,
= elif i.Static:
reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) (void)>( staticCallback_@i.Name@ )),
METH_VARARGS|METH_KEYWORDS|METH_STATIC,
= else:
reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) (void)>( staticCallback_@i.Name@ )),
METH_VARARGS|METH_KEYWORDS,
-
= elif i.Class:
reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) (void)>( staticCallback_@i.Name@ )),
METH_VARARGS|METH_CLASS,
= elif i.Static:
reinterpret_cast<PyCFunction>(reinterpret_cast<void (*) (void)>( staticCallback_@i.Name@ )),
METH_VARARGS|METH_STATIC,
= else:
reinterpret_cast<PyCFunction>( staticCallback_@i.Name@ ),
METH_VARARGS,
@@ -510,6 +533,7 @@ PyGetSetDef @self.export.Name@::GetterSetter[] = {
// @i.Name@() callback and implementer
// PyObject* @self.export.Name@::@i.Name@(PyObject *args){};
// has to be implemented in @self.export.Name@Imp.cpp
+ if not i.Static and not i.Class:
+ if i.Keyword:
PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject *args, PyObject * kwd)
= else:
@@ -587,6 +611,7 @@ PyObject * @self.export.Name@::staticCallback_@i.Name@ (PyObject *self, PyObject
#endif
}
-
-
+ for i in self.export.Attribute:
// @i.Name@() callback and implementer
@@ -869,6 +894,7 @@ std::string @self.export.Name@::representation(void) const
}
+ for i in self.export.Methode:
+ if not i.Static and not i.Class:
+ if i.Keyword:
PyObject* @self.export.Name@::@i.Name@(PyObject *args, PyObject *kwds)
= else:
@@ -879,6 +905,7 @@ PyObject* @self.export.Name@::@i.Name@(PyObject *args)
return 0;
}
-
-
+ if (self.export.NumberProtocol):
PyObject* @self.export.Name@::number_add_handler(PyObject* /*self*/, PyObject* /*other*/)
@@ -1186,6 +1213,7 @@ int @self.export.Name@::finalization()
+ for i in self.export.Methode:
+ if not i.Static and not i.Class:
+ if i.Keyword:
PyObject* @self.export.Name@::@i.Name@(PyObject * /*args*/, PyObject * /*kwds*/)
= else:
@@ -1196,6 +1224,7 @@ PyObject* @self.export.Name@::@i.Name@(PyObject * /*args*/)
return 0;
}
-
-
+ if (self.export.NumberProtocol):
PyObject* @self.export.Name@::number_add_handler(PyObject *self, PyObject *other)