add support of static and class methods in Python wrappers
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
<xs:attribute name="Name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="Const" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="Keyword" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="Class" type="xs:boolean" use="optional" default="false"/>
|
||||
<xs:attribute name="Static" type="xs:boolean" use="optional" default="false"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="Attribute" minOccurs="0" maxOccurs="unbounded">
|
||||
@@ -46,6 +48,7 @@
|
||||
</xs:element>
|
||||
<xs:element name="CustomAttributes" minOccurs="0"/>
|
||||
<xs:element name="ClassDeclarations" type="xs:string"/>
|
||||
<xs:element name="ForwardDeclarations" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="Name" type="xs:string" use="required"/>
|
||||
<xs:attribute name="PythonName" type="xs:string" use="optional"/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
#
|
||||
# Generated Mon Aug 21 13:00:21 2017 by generateDS.py.
|
||||
# Generated Tue Nov 12 21:18:34 2019 by generateDS.py.
|
||||
# Update it with: python generateDS.py -o generateModel_Module.py generateMetaModel_Module.xsd
|
||||
#
|
||||
# WARNING! All changes made in this file will be lost!
|
||||
@@ -221,7 +221,7 @@ class GenerateModel:
|
||||
|
||||
class PythonExport:
|
||||
subclass = None
|
||||
def __init__(self, FatherNamespace='', DisableNotify=0, RichCompare=0, Name='', Reference=0, FatherInclude='', Namespace='', Initialization=0, Father='', PythonName='', Twin='', Constructor=0, TwinPointer='', Include='', NumberProtocol=0, Delete=0, Documentation=None, Methode=None, Attribute=None, Sequence=None, CustomAttributes='', ClassDeclarations=''):
|
||||
def __init__(self, FatherNamespace='', DisableNotify=0, RichCompare=0, Name='', Reference=0, FatherInclude='', Namespace='', Initialization=0, Father='', PythonName='', Twin='', Constructor=0, TwinPointer='', Include='', NumberProtocol=0, Delete=0, Documentation=None, Methode=None, Attribute=None, Sequence=None, CustomAttributes='', ClassDeclarations='', ForwardDeclarations=''):
|
||||
self.FatherNamespace = FatherNamespace
|
||||
self.DisableNotify = DisableNotify
|
||||
self.RichCompare = RichCompare
|
||||
@@ -250,6 +250,7 @@ class PythonExport:
|
||||
self.Sequence = Sequence
|
||||
self.CustomAttributes = CustomAttributes
|
||||
self.ClassDeclarations = ClassDeclarations
|
||||
self.ForwardDeclarations = ForwardDeclarations
|
||||
def factory(*args_, **kwargs_):
|
||||
if PythonExport.subclass:
|
||||
return PythonExport.subclass(*args_, **kwargs_)
|
||||
@@ -272,6 +273,8 @@ class PythonExport:
|
||||
def setCustomattributes(self, CustomAttributes): self.CustomAttributes = CustomAttributes
|
||||
def getClassdeclarations(self): return self.ClassDeclarations
|
||||
def setClassdeclarations(self, ClassDeclarations): self.ClassDeclarations = ClassDeclarations
|
||||
def getForwarddeclarations(self): return self.ForwardDeclarations
|
||||
def setForwarddeclarations(self, ForwardDeclarations): self.ForwardDeclarations = ForwardDeclarations
|
||||
def getFathernamespace(self): return self.FatherNamespace
|
||||
def setFathernamespace(self, FatherNamespace): self.FatherNamespace = FatherNamespace
|
||||
def getDisablenotify(self): return self.DisableNotify
|
||||
@@ -350,6 +353,8 @@ class PythonExport:
|
||||
outfile.write('<CustomAttributes>%s</CustomAttributes>\n' % quote_xml(self.getCustomattributes()))
|
||||
showIndent(outfile, level)
|
||||
outfile.write('<ClassDeclarations>%s</ClassDeclarations>\n' % quote_xml(self.getClassdeclarations()))
|
||||
showIndent(outfile, level)
|
||||
outfile.write('<ForwardDeclarations>%s</ForwardDeclarations>\n' % quote_xml(self.getForwarddeclarations()))
|
||||
def exportLiteral(self, outfile, level, name_='PythonExport'):
|
||||
level += 1
|
||||
self.exportLiteralAttributes(outfile, level, name_)
|
||||
@@ -428,6 +433,8 @@ class PythonExport:
|
||||
outfile.write('CustomAttributes=%s,\n' % quote_python(self.getCustomattributes()))
|
||||
showIndent(outfile, level)
|
||||
outfile.write('ClassDeclarations=%s,\n' % quote_python(self.getClassdeclarations()))
|
||||
showIndent(outfile, level)
|
||||
outfile.write('ForwardDeclarations=%s,\n' % quote_python(self.getForwarddeclarations()))
|
||||
def build(self, node_):
|
||||
attrs = node_.attributes
|
||||
self.buildAttributes(attrs)
|
||||
@@ -535,15 +542,23 @@ class PythonExport:
|
||||
for text__content_ in child_.childNodes:
|
||||
ClassDeclarations_ += text__content_.nodeValue
|
||||
self.ClassDeclarations = ClassDeclarations_
|
||||
elif child_.nodeType == Node.ELEMENT_NODE and \
|
||||
nodeName_ == 'ForwardDeclarations':
|
||||
ForwardDeclarations_ = ''
|
||||
for text__content_ in child_.childNodes:
|
||||
ForwardDeclarations_ += text__content_.nodeValue
|
||||
self.ForwardDeclarations = ForwardDeclarations_
|
||||
# end class PythonExport
|
||||
|
||||
|
||||
class Methode:
|
||||
subclass = None
|
||||
def __init__(self, Const=0, Name='', Keyword=0, Documentation=None, Parameter=None):
|
||||
def __init__(self, Static=0, Const=0, Name='', Keyword=0, Class=0, Documentation=None, Parameter=None):
|
||||
self.Static = Static
|
||||
self.Const = Const
|
||||
self.Name = Name
|
||||
self.Keyword = Keyword
|
||||
self.Class = Class
|
||||
self.Documentation = Documentation
|
||||
if Parameter is None:
|
||||
self.Parameter = []
|
||||
@@ -561,12 +576,16 @@ class Methode:
|
||||
def setParameter(self, Parameter): self.Parameter = Parameter
|
||||
def addParameter(self, value): self.Parameter.append(value)
|
||||
def insertParameter(self, index, value): self.Parameter[index] = value
|
||||
def getStatic(self): return self.Static
|
||||
def setStatic(self, Static): self.Static = Static
|
||||
def getConst(self): return self.Const
|
||||
def setConst(self, Const): self.Const = Const
|
||||
def getName(self): return self.Name
|
||||
def setName(self, Name): self.Name = Name
|
||||
def getKeyword(self): return self.Keyword
|
||||
def setKeyword(self, Keyword): self.Keyword = Keyword
|
||||
def getClass(self): return self.Class
|
||||
def setClass(self, Class): self.Class = Class
|
||||
def export(self, outfile, level, name_='Methode'):
|
||||
showIndent(outfile, level)
|
||||
outfile.write('<%s' % (name_, ))
|
||||
@@ -576,11 +595,15 @@ class Methode:
|
||||
showIndent(outfile, level)
|
||||
outfile.write('</%s>\n' % name_)
|
||||
def exportAttributes(self, outfile, level, name_='Methode'):
|
||||
if self.getStatic() is not None:
|
||||
outfile.write(' Static="%s"' % (self.getStatic(), ))
|
||||
if self.getConst() is not None:
|
||||
outfile.write(' Const="%s"' % (self.getConst(), ))
|
||||
outfile.write(' Name="%s"' % (self.getName(), ))
|
||||
if self.getKeyword() is not None:
|
||||
outfile.write(' Keyword="%s"' % (self.getKeyword(), ))
|
||||
if self.getClass() is not None:
|
||||
outfile.write(' Class="%s"' % (self.getClass(), ))
|
||||
def exportChildren(self, outfile, level, name_='Methode'):
|
||||
if self.Documentation:
|
||||
self.Documentation.export(outfile, level)
|
||||
@@ -591,12 +614,16 @@ class Methode:
|
||||
self.exportLiteralAttributes(outfile, level, name_)
|
||||
self.exportLiteralChildren(outfile, level, name_)
|
||||
def exportLiteralAttributes(self, outfile, level, name_):
|
||||
showIndent(outfile, level)
|
||||
outfile.write('Static = "%s",\n' % (self.getStatic(),))
|
||||
showIndent(outfile, level)
|
||||
outfile.write('Const = "%s",\n' % (self.getConst(),))
|
||||
showIndent(outfile, level)
|
||||
outfile.write('Name = "%s",\n' % (self.getName(),))
|
||||
showIndent(outfile, level)
|
||||
outfile.write('Keyword = "%s",\n' % (self.getKeyword(),))
|
||||
showIndent(outfile, level)
|
||||
outfile.write('Class = "%s",\n' % (self.getClass(),))
|
||||
def exportLiteralChildren(self, outfile, level, name_):
|
||||
if self.Documentation:
|
||||
showIndent(outfile, level)
|
||||
@@ -623,6 +650,13 @@ class Methode:
|
||||
nodeName_ = child_.nodeName.split(':')[-1]
|
||||
self.buildChildren(child_, nodeName_)
|
||||
def buildAttributes(self, attrs):
|
||||
if attrs.get('Static'):
|
||||
if attrs.get('Static').value in ('true', '1'):
|
||||
self.Static = 1
|
||||
elif attrs.get('Static').value in ('false', '0'):
|
||||
self.Static = 0
|
||||
else:
|
||||
raise ValueError('Bad boolean attribute (Static)')
|
||||
if attrs.get('Const'):
|
||||
if attrs.get('Const').value in ('true', '1'):
|
||||
self.Const = 1
|
||||
@@ -639,6 +673,13 @@ class Methode:
|
||||
self.Keyword = 0
|
||||
else:
|
||||
raise ValueError('Bad boolean attribute (Keyword)')
|
||||
if attrs.get('Class'):
|
||||
if attrs.get('Class').value in ('true', '1'):
|
||||
self.Class = 1
|
||||
elif attrs.get('Class').value in ('false', '0'):
|
||||
self.Class = 0
|
||||
else:
|
||||
raise ValueError('Bad boolean attribute (Class)')
|
||||
def buildChildren(self, child_, nodeName_):
|
||||
if child_.nodeType == Node.ELEMENT_NODE and \
|
||||
nodeName_ == 'Documentation':
|
||||
@@ -1920,6 +1961,14 @@ class SaxGeneratemodelHandler(handler.ContentHandler):
|
||||
done = 1
|
||||
elif name == 'Methode':
|
||||
obj = Methode.factory()
|
||||
val = attrs.get('Static', None)
|
||||
if val is not None:
|
||||
if val in ('true', '1'):
|
||||
obj.setStatic(1)
|
||||
elif val in ('false', '0'):
|
||||
obj.setStatic(0)
|
||||
else:
|
||||
self.reportError('"Static" attribute must be boolean ("true", "1", "false", "0")')
|
||||
val = attrs.get('Const', None)
|
||||
if val is not None:
|
||||
if val in ('true', '1'):
|
||||
@@ -1939,6 +1988,14 @@ class SaxGeneratemodelHandler(handler.ContentHandler):
|
||||
obj.setKeyword(0)
|
||||
else:
|
||||
self.reportError('"Keyword" attribute must be boolean ("true", "1", "false", "0")')
|
||||
val = attrs.get('Class', None)
|
||||
if val is not None:
|
||||
if val in ('true', '1'):
|
||||
obj.setClass(1)
|
||||
elif val in ('false', '0'):
|
||||
obj.setClass(0)
|
||||
else:
|
||||
self.reportError('"Class" attribute must be boolean ("true", "1", "false", "0")')
|
||||
stackObj = SaxStackElement('Methode', obj)
|
||||
self.stack.append(stackObj)
|
||||
done = 1
|
||||
@@ -2062,6 +2119,10 @@ class SaxGeneratemodelHandler(handler.ContentHandler):
|
||||
stackObj = SaxStackElement('ClassDeclarations', None)
|
||||
self.stack.append(stackObj)
|
||||
done = 1
|
||||
elif name == 'ForwardDeclarations':
|
||||
stackObj = SaxStackElement('ForwardDeclarations', None)
|
||||
self.stack.append(stackObj)
|
||||
done = 1
|
||||
elif name == 'Dependencies':
|
||||
obj = Dependencies.factory()
|
||||
stackObj = SaxStackElement('Dependencies', obj)
|
||||
@@ -2185,6 +2246,12 @@ class SaxGeneratemodelHandler(handler.ContentHandler):
|
||||
self.stack[-2].obj.setClassdeclarations(content)
|
||||
self.stack.pop()
|
||||
done = 1
|
||||
elif name == 'ForwardDeclarations':
|
||||
if len(self.stack) >= 2:
|
||||
content = self.stack[-1].content
|
||||
self.stack[-2].obj.setForwarddeclarations(content)
|
||||
self.stack.pop()
|
||||
done = 1
|
||||
elif name == 'Dependencies':
|
||||
if len(self.stack) >= 2:
|
||||
self.stack[-2].obj.setDependencies(self.stack[-1].obj)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user