[C++-sig] Default arguments in pyplusplus

Niall Douglas s_sourceforge at nedprod.com
Tue Jun 20 04:22:30 CEST 2006


On 19 Jun 2006 at 8:17, Roman Yakovenko wrote:

> Why don't you resolve the issue with enums. I see few ways to go:
> 
> To find places where enum used as default arguments and enum still not exported
> >From here you have 2 solutions: to remove default arguments or to change default
> arguments to have integer type with value of enum. This should work.

I tried this one using the following:

    # Patch default args with enums to be number (to avoid undeclared 
enum problem)
    allfuncs = mb.calldefs()
    for func in allfuncs:
        print type(func), type(func.parent), func
        for arg in func.arguments:
            # Is it an argument with a default value?
            if arg.default_value:
                # Is it an enumeration?
                if isinstance( arg.type, 
declarations.cpptypes.declarated_t ) and isinstance( 
arg.type.declaration, declarations.enumeration.enumeration_t ):
                    # Is it an embedded enum rather than global?
                    scopecount = arg.default_value.count('::') - 
arg.default_value.startswith('::')
                    if scopecount>1:
                        # Be lazy, and just lookup the last part
                        value = arg.default_value[ 
arg.default_value.rfind('::')+2: ]
                        arg.default_value = 
arg.type.declaration.values[ value ] + '/*' + arg.default_value + 
'*/'

And this works fine. EXCEPT that class wrappers also take the int 
converted default parameter, which leads unfortunately to code like 
this:

    QBlkSocket_wrapper(::FX::QBlkSocket::Type 
type=0/*::FX::QBlkSocket::Stream*/, ::FX::FXushort port=0 )
    : FX::QBlkSocket( type, port )
      , bp::wrapper< FX::QBlkSocket >()
    {   // Normal constructor
    
    }

Of course, this won't compile. Any ideas?

Thanks for the enum idea. If I can get keyword parameters working I'd 
be very happy.

Cheers,
Niall




More information about the Cplusplus-sig mailing list