2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-27 07:02:15 +00:00

- Added MANUAL support for shared_ptr and auto_ptrs. In the future, support should be automatic.

[SVN r18041]
This commit is contained in:
Bruno da Silva de Oliveira
2003-03-21 14:24:20 +00:00
parent 6335716342
commit 12a4cc16be
5 changed files with 41 additions and 0 deletions

20
pyste/example/smart_ptr.h Normal file
View File

@@ -0,0 +1,20 @@
#include <memory>
#include <boost/shared_ptr.hpp>
namespace smart_ptr {
struct C
{
int value;
};
struct D
{
boost::shared_ptr<C> Get() { return ptr; }
void Set( boost::shared_ptr<C> c ) { ptr = c; }
private:
boost::shared_ptr<C> ptr;
};
std::auto_ptr<D> New() { return std::auto_ptr<D>( new D() ); }
}

View File

@@ -0,0 +1,5 @@
C = Class('smart_ptr::C', 'smart_ptr.h')
use_shared_ptr(C)
D = Class('smart_ptr::D', 'smart_ptr.h')
use_auto_ptr(D)
Function('smart_ptr::New', 'smart_ptr.h')

View File

@@ -90,6 +90,7 @@ class ClassExporter(Exporter):
self.ExportOperators()
self.ExportNestedClasses(exported_names)
self.ExportNestedEnums()
self.ExportSmartPointer()
self.Write(codeunit)
@@ -540,6 +541,12 @@ class ClassExporter(Exporter):
codeunit = CodeUnit(None)
exporter.Export(codeunit, None)
self.nested_codeunits.append(codeunit)
def ExportSmartPointer(self):
smart_ptr = self.info.smart_ptr
if smart_ptr:
self.Add('template', smart_ptr % self.class_.FullName())
#==============================================================================

View File

@@ -185,4 +185,11 @@ def instantiate(template, types, rename=None):
if isinstance(types, str):
types = types.split()
return template.Instantiate(types, rename)
def use_shared_ptr(option):
option._Attribute('smart_ptr', 'boost::shared_ptr< %s >')
def use_auto_ptr(option):
option._Attribute('smart_ptr', 'std::auto_ptr< %s >')

View File

@@ -89,6 +89,8 @@ def CreateContext():
context['set_policy'] = infos.set_policy
context['exclude'] = infos.exclude
context['set_wrapper'] = infos.set_wrapper
context['use_shared_ptr'] = infos.use_shared_ptr
context['use_auto_ptr'] = infos.use_auto_ptr
# policies
context['return_internal_reference'] = return_internal_reference
context['with_custodian_and_ward'] = with_custodian_and_ward