[C++-sig] pyplusplus tutorials & GUI wizard

Roman Yakovenko roman.yakovenko at gmail.com
Wed Feb 1 06:09:09 CET 2006


On 1/31/06, Matthias Baas <baas at ira.uka.de> wrote:
> >> Anyway, I'll continue my test and move on to the more complex classes
> >> that needed some manual intervention using Pyste....
>
> The next class I've added to the module has two methods that require a
> call policy. The methods just return a reference to its instance, so I
> want to specify the 'return_self' policy. How do I do that? (I've had a
> short glimpse at those examples you mentioned two mails ago, but didn't
> really spot a place where a policy was assigned)

You have 2 choices:

1. To create "callable" object that for a given declaration will
return call policies.
    For example py_easybmp uses this technique.

    See: http://tinyurl.com/crjzf

    In this case you also need to switch from module_creator.create
function to using
    class module_creator.creator_t. EasyBMP example will help you.

2. After you created extension module tree you can find relevant code creator
   and then set call policies.

   The relevant code for find functionality you can find in
pygccxml/declarations/algorithm.py
   and pyplusplus/code_creators/algorithm.py

   2.1 You also can iterate on all code creators:

        creators = code_creators.make_flatten( extmodule )
        fmfunctions = filter( lambda creator: isinstance( creator,
code_creators.function_t )
                              , creators )
        for creator in fmfunctions:
            if not creator.call_policies:
                print 'missing call policies: ',
declarations.full_name( creator.declaration )
                print '    function will not be exported'
                creator.parent.remove_creator( creator )

As for me the first way is better then other. It does not degrade performance.
Also 2.1 it useful to remove function with missing call policies, and
thus to see result
much faster.

Small hint: If the SDK you are wrapping has code convention, than you
can reuse it.
For example if all classes has method "clone" that returns raw pointer
to new object,
then you can set call policies base on function name only.
An other small hint: pygccxml has type_traits. The idea is similar as
in boost.type_traits.
You can analyze the return type of function, and only then to decide
what call policies you
will set.


> Then there's another class that has a private destructor. This class
> only has static methods and is not meant to be instantiated. So for the
> wrappers I'd like to add the 'noncopyable' and 'no_init' specifiers.
> Does pyplusplus allow that?

pyplusplus does not allows this right now. The main reason for this is:
pyplusplus checks whether class has private constructor (fixed yesterday)
or does not have accessible copy constructor and generates right code.

I forgot about public destructor. I will fix it. If you still need to
control those properties
just say it.

> Now I also noticed another thing that'll get more serious the more
> classes I wrap. Whenever I create the source code for the bindings
> (using the multiple_files feature) *all* files are recreated, even when
> the actual contents is the same than before. When I then compile the
> module (using distutils) *every* file is recompiled which will take
> quite some time once I've wrapped the entire SDK (which has about 300
> classes). Is there a way to tell pyplusplus to only generate a source
> file when the contents will be different from a previous run?

I will fix this.

> - Matthias -
>

I will post to the list when fixes are ready.

Thanks

Roman Yakovenko



More information about the Cplusplus-sig mailing list