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

Roman Yakovenko roman.yakovenko at gmail.com
Fri Feb 10 17:53:01 CET 2006

On 2/9/06, Matthias Baas <baas at ira.uka.de> wrote:
> But the argument names are correct in my original code and do appear in
> the generated bindings...? Do you know under what circumstances gccxml
> drops the argument names?

No, I don't. In an other post in this thread Niall writes, that this
problem has been fixed
in CVS version of GCC-XML. You can try it. pygccxml works well with
CVS version of GCC-XML. On Linux I running GCC-XML CVS + gcc 4.1

> Meanwhile I have a few cases where I need to reject some particular
> class methods. For example, I have a class with methods of the following
> kind:
> class Foo
> {
>    ...
>    float& spam(int i);
>    float  spam(int i) const;
>    ...
> };
> The spam() method returns a float value that is stored inside the class.
> For the Python bindings I'd like to ignore the first version that
> returns the reference. What is the recommended way to do this?

pygccxml.declarations package has type traits. Their functionality is
very similar to

#f is declaration of function spam

if pygccxml.declarations.is_reference( f.return_type ):
    if pygccxml.declarations.is_floating_point( f.return_type.base ):
        pass#do your things

Take a look on pygccxml type traits. It worth it.

> Is there a convenience function that can easily check if a declaration
> actually represents a method "float& Foo::spam(int)" or do I really have
> to inspect every little detail myself (i.e. check if the name of the
> declaration matches "spam", check if the parent declaration is a class
> declaration called "Foo", check if it has one single argument of type
> int, check if it has a return type of type float&, etc.)? I found the
> function find_first_declaration() that looked closest to what I want to
> accomplish when used with the 'fullname' argument. But this only takes
> the class and the method name into account, but not the arguments and
> return type.

There is no such convenience method :-(. But you don't have to check
every little detail.
For example all member function declarations derived from
member_function_t class.
I think that in your case you will need to right your own match
method. I thought
to add an other set of find_* functions that will take as argument
some callable
object. But it will take some time.

> Then I have two more questions:
> - How do you add new methods to a (Python) class? In my case, I want to
> wrap a class whose Python version should have an additional static
> method (which I'd like to implement as a C++ function).

Best way is to use custom_text_t code creator. Just put it somewhere
within relevant code creator. Take a look on boost.date_time
pyplusplus example. I use it there.

> - Is there already a way to specify doc strings?

No, but I do plan to add such functionality in future.

> - Matthias -
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig

Roman Yakovenko
C++ Python language binding

More information about the Cplusplus-sig mailing list