Policies |
Even thought Pyste can identify various elements in the C++ code, like virtual member functions, attributes, and so on, one thing that it can't do is to guess the semantics of functions that return pointers or references. In this case, the user must manually specify the policy. Policies are explained in the tutorial.
The policies in Pyste are named exactly as in Boost.Python, only the syntax is slightly different. For instance, this policy:
return_internal_reference<1, with_custodian_and_ward<1, 2> >()
becomes in Pyste:
return_internal_reference(1, with_custodian_and_ward(1, 2))
The user can specify policies for functions and virtual member functions with the set_policy function:
set_policy(f, return_internal_reference())
set_policy(C.foo, return_value_policy(manage_new_object))
What if a function or member function needs a policy and
the user doesn't set one? If a function needs a policy and one was not set, Pyste will issue a error. The user should then go in the interface file and set the policy for it, otherwise the generated cpp won't compile. |
Note that for functions that return const T&, the policy return_value_policy<copy_const_reference>() wil be used by default, because that's normally what you want. You can change it to something else if you need to, though. |
Copyright © 2003 Bruno da Silva de Oliveira
Copyright © 2002-2003 Joel de Guzman
Distributed under
the Boost Software License, Version 1.0. (See accompanying file
LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)