Package pyplusplus :: Package decl_wrappers :: Module python_traits

Source Code for Module pyplusplus.decl_wrappers.python_traits

 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  """defines few "type traits" functions related to C++ Python bindings""" 
 7   
 8  from pygccxml import declarations 
 9   
10 -def is_immutable( type_ ):
11 """returns True, if type_ represents Python immutable type""" 12 return declarations.is_fundamental( type_ ) \ 13 or declarations.is_enum( type_ ) \ 14 or declarations.is_std_string( type_ ) \ 15 or declarations.is_std_wstring( type_ ) \ 16 or declarations.smart_pointer_traits.is_smart_pointer( type_ )
17 #todo is_complex, ... 18
19 -def call_traits( type_ ):
20 """http://boost.org/libs/utility/call_traits.htm""" 21 type_ = declarations.remove_alias( type_ ) 22 if is_immutable( type_ ): 23 return "%s" #pass by value 24 elif declarations.is_reference( type_ ): 25 no_ref = declarations.remove_reference( type_ ) 26 if is_immutable( no_ref ): 27 return "%s" #pass by value 28 else: 29 return "boost::ref(%s)" #pass by ref 30 elif declarations.is_pointer( type_ ) \ 31 and not is_immutable( type_.base ) \ 32 and not declarations.is_pointer( type_.base ): 33 return "boost::python::ptr(%s)" #pass by ptr 34 else: 35 return "%s" #pass by value
36