[C++-sig] Py++ filter based on return type

Roman Yakovenko roman.yakovenko at gmail.com
Sat Mar 29 07:46:59 CET 2008

2008/3/28 Rolf Schlup <rschlup at highspeedcrow.ca>:
> Hi Roman,

Good morning

>   I'm trying to bind a relatively complex interface class of an IG control
> system and it has a lot of methods that return references to member which
> are classes in themselves.  I'm also working on a script that will
> automatically create a Py++ script from Rational Rose model.

Coool :-)

> I have become
> a little stuck in creating a Py++ that will create a module class that will
> build.
> Hopefully, you'll be able to answer the following questions so that I can
> get back to it
> 1)       Since there are a whole lot of methods, what is the best way to
> work with the call policies – especially with the member functions that
> return references to other classes using & and not pointers

Py++ & call policies documentation:
type_traits ( similar to Boost.TypeTraits ) functionality:

The usage example for your use case

from pygccxml import declarations
from pyplusplus.module_builder import call_policies

mb = module_builder_t(...)

def has_return_internal_reference_policy( f ):
    if not f.return_type: #constructor or destructor
        return False
    r_type = f.return_type
    if declarations.is_reference(r_type) and declarations.is_class(
declarations.remove_reference( r_type ):
        return True
    if declarations.is_pointer(r_type) and declarations.is_class(
declarations.remove_pointer( r_type ):
        return True
    #TODO: add const treatment
    return False

scope = mb.[namespace|class_](....) #select the appropriate scope
scope.calldefs( has_return_internal_reference_policy ).call_policies =

> 2)       Minimize the need for 20 or more include declarations.  Including
> only those files that are absolutely necessary for the class being bound

What version do you use? I worked hard to minimize the number of
included files. Can you create small example?

> 3)       I've been looking for examples for what I'm trying to do, but they
> are very scarce.  I think I'm past the whole hello_world thing.  Is there a
> place on the web that has what I'm looking for?

I don't exactly understand what you are trying to do, but here few
links that I hope will help you:

* few boost libraries wrapped by me:
* python-ogre - huge repository of modules wrapped with Py++ -
  take a look on "common_utils" directory

HTH, if not come back and ask more specific question :-)

Roman Yakovenko
C++ Python language binding

More information about the Cplusplus-sig mailing list