ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> cpp-sig
cpp-sig
[C++-sig] [Py++] How to wrap default arg as enum with complicated scope?
by Christopher Bruns other posts by this author
Oct 12 2009 2:18PM messages near this date
Re: [C++-sig] Cplusplus-sig Digest, Vol 13, Issue 11 | Re: [C++-sig] [Py++] How to wrap default arg as enum with complicated scope?
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:

#### wrap_enum2.py ####
from pyplusplus import module_builder

mb = module_builder.module_builder_t(["test_enum2.h"]
    , gccxml_path = "gccxml.exe")
mb.build_code_creator( module_name='test' )
mb.write_module( 'test_wrap_enum2.cpp' )
#### end wrap_enum2.py ####

#### test_wrap_enum2.cpp ####
// This file has been generated by Py++.

#include "boost/python.hpp"

#include "test_enum2.h"

namespace bp = boost::python;

BOOST_PYTHON_MODULE(test){
    { //::System
        typedef bp::class_< System >  System_exposer_t;
        System_exposer_t System_exposer = System_exposer_t( "System" );
        bp::scope System_scope( System_exposer );
        { //::System::ProjectOptions
            typedef bp::class_< System::ProjectOptions > 
ProjectOptions_exposer_t;
            ProjectOptions_exposer_t ProjectOptions_exposer =
ProjectOptions_exposer_t( "ProjectOptions", bp::init<
System::ProjectOptions::Option > (( bp::arg("arg0") )) );
            bp::scope ProjectOptions_scope( ProjectOptions_exposer );
            bp::enum_< System::ProjectOptions::Option> ("Option")
                .value("All", System::ProjectOptions::All)
                .export_values()
                ;
            bp::implicitly_convertible<
System::ProjectOptions::Option, System::ProjectOptions > ();
        }
        { //::System::project

            typedef void ( ::System::*project_function_type )(
::System::ProjectOptions ) ;

            System_exposer.def(
                "project"
                , project_function_type( &::System::project )
                , ( bp::arg("arg0")=All ) );
        }
    }
}
#### 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"?

Any enlightenment is much appreciated.

--Chris Bruns
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@[...].org
http://mail.python.org/mailman/listinfo/cplusplus-sig
Thread:
Christopher Bruns
Roman Yakovenko

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved