[C++-sig] [Py++] How to wrap default arg as enum with complicated scope?

Roman Yakovenko roman.yakovenko at gmail.com
Tue Oct 13 00:39:04 CEST 2009


On Mon, Oct 12, 2009 at 10:51 PM, Christopher Bruns
<cmbruns at stanford.edu> wrote:
> Below is a simplified example of a tricky wrapping problem I have
> encountered.  The example remains somewhat complicated, but further
> simplification results in a file that causes no trouble.
> I get a compile error when I try to build the boost python code
> generated by the following case:
>
> #### test_enum.h ####
> struct System {
>    struct ProjectOptions {
>        enum Option {
>            All = 1
>        };
>        ProjectOptions(Option);
>    };
>    void project(ProjectOptions = ProjectOptions::All);
> };
> #### end test_enum.h ####
>
> The trouble comes from the default value ('ProjectOptions::All') for
> the project() method.  Notice also the constructor for ProjectOptions
> from Options.  That is required for reproducing the trouble here.
>
> The resulting boost.python code is as follows:
> ...
> #### test_wrap_enum2.cpp ####
>
> The symbol "All" in the line ", ( bp::arg("arg0")=All ) );" is out of
> scope here.  If I change the line from
>
>  , ( bp::arg("arg0")=All ) ); // compile failure
>
> to
>
>  , ( bp::arg("arg0")=System::ProjectOptions::All ) ); // works
>
> it compiles fine.
>
> Is there any way to instruct pyplusplus to generate the default
> argument value for the project() method with the scope
> "System::ProjectOptions::All"?

Yes:

mb = module_builder_t(...)
project = mb.mem_fun( 'project' )
project.arguments[0].default_value = "System::ProjectOptions::All"

> Any enlightenment is much appreciated.

Basically this is GCCXML limitations. The default argument could be
full-blown C++ expression. GCCXML doesn't handles\dumps them. It do
writes something for default arguments and Py++(pygccxml) try to
decode what it is.

May be the following link could help you:
http://language-binding.net/pygccxml/upgrade_issues.html
http://language-binding.net/pyplusplus/documentation/functions/functions.html

Also try google, this problem was discussed on this, pygccxml and
gccxml mailing lists.

HTH

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/


More information about the Cplusplus-sig mailing list