Package pyplusplus :: Package code_creators :: Module smart_pointers

Source Code for Module pyplusplus.code_creators.smart_pointers

  1  # Copyright 2004-2008 Roman Yakovenko.
 
  2  # Distributed under the Boost Software License, Version 1.0. (See
 
  3  # accompanying file LICENSE_1_0.txt or copy at
 
  4  # http://www.boost.org/LICENSE_1_0.txt)
 
  5  
 
  6  import os 
  7  import algorithm 
  8  import declaration_based 
  9  import registration_based 
 10  from pygccxml import declarations 
 11  
 
 12  templates = declarations.templates 
 13  
 
14 -class held_type_t(object):
15 """ Helper class that can hold name of smart_ptr type and create 16 identifier for held type from that given a creator. 17 """
18 - def __init__( self, smart_ptr ):
19 """ smart_ptr: string of ptr type. Ex: 'boost::shared_ptr' """ 20 object.__init__( self ) 21 self._smart_ptr = smart_ptr
22
23 - def _get_smart_ptr( self ):
24 return self._smart_ptr
25 - def _set_smart_ptr( self, ptr ):
26 self._smart_ptr = ptr
27 smart_ptr = property( _get_smart_ptr, _set_smart_ptr ) 28
29 - def create( self, creator):
30 """ Return string of type to use for held type. 31 Ex: boost::shared_ptr<Class> 32 """ 33 smart_ptr = algorithm.create_identifier( creator, self.smart_ptr ) 34 arg = algorithm.create_identifier( creator, creator.declaration.decl_string ) 35 return templates.join( smart_ptr, [ arg ] )
36
37 -class smart_pointer_registrator_t( registration_based.registration_based_t 38 , declaration_based.declaration_based_t ):
39 """ Convertor for boost::python::register_ptr_to_python<PTR>. 40 Lets boost python know that it can use smart_ptr to hold a an object. 41 See: http://www.boost.org/libs/python/doc/v2/register_ptr_to_python.html 42 """
43 - def __init__( self, smart_ptr, class_creator ):
44 """ smart_ptr: string of ptr type. Ex: 'boost::shared_ptr' """ 45 registration_based.registration_based_t.__init__( self ) 46 declaration_based.declaration_based_t.