2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-19 04:22:16 +00:00

- Using the new Boost.Python facility for wrapping pure virtual functions

[SVN r19792]
This commit is contained in:
Bruno da Silva de Oliveira
2003-08-26 23:24:02 +00:00
parent 5fc5fce663
commit 10b249a162
5 changed files with 63 additions and 16 deletions

View File

@@ -711,16 +711,8 @@ class _VirtualWrapperGenerator(object):
wrapper = self.info[method.name].wrapper
if not wrapper:
# return the default implementation of the class
if method.abstract:
s = indent2 + 'PyErr_SetString(PyExc_RuntimeError, "pure virtual function called");\n' +\
indent2 + 'throw_error_already_set();\n'
params = ', '.join(param_names)
s += indent2 + '%s%s(%s);\n' % \
(return_str, method.name, params)
return s
else:
return indent2 + '%s%s(%s);\n' % \
(return_str, method.FullName(), ', '.join(param_names))
return indent2 + '%s%s(%s);\n' % \
(return_str, method.FullName(), ', '.join(param_names))
else:
if wrapper.code:
self.codeunit.Write('declaration-outside', wrapper.code)
@@ -728,7 +720,7 @@ class _VirtualWrapperGenerator(object):
params = ', '.join(['this'] + param_names)
return indent2 + '%s%s(%s);\n' % (return_str, wrapper.FullName(), params)
if method.visibility != Scope.private:
if not method.abstract and method.visibility != Scope.private:
minArgs = method.minArgs
maxArgs = method.maxArgs
impl_names = self.DefaultImplementationNames(method)
@@ -759,7 +751,9 @@ class _VirtualWrapperGenerator(object):
# create a list of default-impl pointers
minArgs = method.minArgs
maxArgs = method.maxArgs
if is_method_unique:
if method.abstract:
default_pointers = []
elif is_method_unique:
default_pointers = ['&%s::%s' % (wrapper_name, x) for x in default_names]
else:
default_pointers = []
@@ -772,6 +766,8 @@ class _VirtualWrapperGenerator(object):
# get the pointer of the method
pointer = method.PointerDeclaration()
if method.abstract:
pointer = namespaces.python + ('pure_virtual(%s)' % pointer)
# Add policy to overloaded methods also
policy = self.info[method.name].policy or ''
@@ -781,9 +777,12 @@ class _VirtualWrapperGenerator(object):
# generate the defs
definitions = []
# basic def
definitions.append('.def("%s", %s, %s%s)' % (rename, pointer, default_pointers[-1], policy))
for default_pointer in default_pointers[:-1]:
definitions.append('.def("%s", %s%s)' % (rename, default_pointer, policy))
if default_pointers:
definitions.append('.def("%s", %s, %s%s)' % (rename, pointer, default_pointers[-1], policy))
for default_pointer in default_pointers[:-1]:
definitions.append('.def("%s", %s%s)' % (rename, default_pointer, policy))
else:
definitions.append('.def("%s", %s%s)' % (rename, pointer, policy))
return definitions

View File

@@ -43,7 +43,7 @@ from CppParser import CppParser, CppParserError
import time
import declarations
__version__ = '0.9.21'
__version__ = '0.9.22'
def RecursiveIncludes(include):
'Return a list containg the include dir and all its subdirectories'

18
pyste/tests/inherit4.h Normal file
View File

@@ -0,0 +1,18 @@
namespace inherit4 {
struct A
{
int x;
};
struct B: A
{
int y;
};
struct C: B
{
int z;
};
}

View File

@@ -0,0 +1,3 @@
Class('inherit4::A', 'inherit4.h')
Class('inherit4::B', 'inherit4.h')
Class('inherit4::C', 'inherit4.h')

27
pyste/tests/inherit4UT.py Normal file
View File

@@ -0,0 +1,27 @@
import unittest
from _inherit4 import *
class TestInherit4(unittest.TestCase):
def testIt(self):
self.assert_(issubclass(B, A))
self.assert_(issubclass(C, A))
self.assert_(issubclass(C, B))
a = A()
a.x = 1
b = B()
b.x = 10
b.y = 20
c = C()
c.x = 100
c.y = 200
c.z = 300
self.assertEqual(a.x, 1)
self.assertEqual(b.x, 10)
self.assertEqual(b.y, 20)
self.assertEqual(c.x, 100)
self.assertEqual(c.y, 200)
self.assertEqual(c.z, 300)
if __name__ == '__main__':
unittest.main()