From d49761106938ff99f9a7325ef9a194be52c9e0fc Mon Sep 17 00:00:00 2001 From: Bruno da Silva de Oliveira Date: Wed, 16 Apr 2003 22:35:09 +0000 Subject: [PATCH] - New code (more generic) for declaring the smart pointer converters [SVN r18269] --- pyste/NEWS | 3 +++ pyste/example/smart_ptr.h | 15 +++++++++++++++ pyste/example/smart_ptr.pyste | 7 +++++++ pyste/src/ClassExporter.py | 14 ++++++++++++-- pyste/src/pyste.py | 2 +- pyste/tests/example_smart_ptrUT.py | 2 ++ 6 files changed, 40 insertions(+), 3 deletions(-) diff --git a/pyste/NEWS b/pyste/NEWS index 018e02a6..1640ad29 100644 --- a/pyste/NEWS +++ b/pyste/NEWS @@ -1,3 +1,6 @@ +16 Apr 2003 +Added a more generic (but ugly) code to declare the smart pointer converters. + 07 Apr 2003 - Removed the warnings about forward declarations: it was not accurate enough. Another strategy must be thought of. diff --git a/pyste/example/smart_ptr.h b/pyste/example/smart_ptr.h index c8847cd8..05b9149c 100644 --- a/pyste/example/smart_ptr.h +++ b/pyste/example/smart_ptr.h @@ -24,6 +24,21 @@ private: inline std::auto_ptr NewD() { return std::auto_ptr( new D() ); } + +// test an abstract class +struct A +{ + virtual int f() = 0; +}; + +struct B: A +{ + virtual int f(){ return 1; } +}; + +inline boost::shared_ptr NewA() { return boost::shared_ptr(new B()); } +inline int GetA(boost::shared_ptr a) { return a->f(); } + } #endif diff --git a/pyste/example/smart_ptr.pyste b/pyste/example/smart_ptr.pyste index ace15fa5..cfbdd81a 100644 --- a/pyste/example/smart_ptr.pyste +++ b/pyste/example/smart_ptr.pyste @@ -1,6 +1,13 @@ C = Class('smart_ptr::C', 'smart_ptr.h') use_shared_ptr(C) + D = Class('smart_ptr::D', 'smart_ptr.h') use_auto_ptr(D) + +A = Class('smart_ptr::A', 'smart_ptr.h') +use_shared_ptr(A) + Function('smart_ptr::NewC', 'smart_ptr.h') Function('smart_ptr::NewD', 'smart_ptr.h') +Function('smart_ptr::NewA', 'smart_ptr.h') +Function('smart_ptr::GetA', 'smart_ptr.h') diff --git a/pyste/src/ClassExporter.py b/pyste/src/ClassExporter.py index 56f89313..9f02a413 100644 --- a/pyste/src/ClassExporter.py +++ b/pyste/src/ClassExporter.py @@ -560,8 +560,18 @@ class ClassExporter(Exporter): def ExportSmartPointer(self): smart_ptr = self.info.smart_ptr if smart_ptr: - self.Add('template', smart_ptr % self.class_.FullName()) - + class_name = self.class_.FullName() + smart_ptr = smart_ptr % class_name + #self.Add('template', smart_ptr) + + self.Add('scope', '// Temporary code for smart pointers') + self.Add('scope', namespaces.python + 'objects::class_value_wrapper< ') + self.Add('scope', ' %s, objects::make_ptr_instance< ' % smart_ptr) + self.Add('scope', ' %s, objects::pointer_holder< ' % class_name) + self.Add('scope', ' %s, %s >' % (smart_ptr, class_name)) + self.Add('scope', ' >') + self.Add('scope', '>();') + def ExportOpaquePointerPolicies(self): # check all methods for 'return_opaque_pointer' policies diff --git a/pyste/src/pyste.py b/pyste/src/pyste.py index 785bcebe..6c0b3a43 100644 --- a/pyste/src/pyste.py +++ b/pyste/src/pyste.py @@ -34,7 +34,7 @@ from policies import * from CppParser import CppParser, CppParserError import time -__VERSION__ = '0.7.3' +__VERSION__ = '0.7.4' def RecursiveIncludes(include): 'Return a list containg the include dir and all its subdirectories' diff --git a/pyste/tests/example_smart_ptrUT.py b/pyste/tests/example_smart_ptrUT.py index f55975bd..04fc9caa 100644 --- a/pyste/tests/example_smart_ptrUT.py +++ b/pyste/tests/example_smart_ptrUT.py @@ -11,6 +11,8 @@ class BasicExampleTest(unittest.TestCase): c1 = d.Get() c1.value = 6 self.assertEqual(c.value, 6) + a = NewA() + self.assertEqual(GetA(a), 1) if __name__ == '__main__': unittest.main()