|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
[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@... http://mail.python.org/mailman/listinfo/cplusplus-sig |
|
|
Re: [Py++] How to wrap default arg as enum with complicated scope?On Mon, Oct 12, 2009 at 10:51 PM, Christopher Bruns
<cmbruns@...> 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/ _______________________________________________ Cplusplus-sig mailing list Cplusplus-sig@... http://mail.python.org/mailman/listinfo/cplusplus-sig |
| Free embeddable forum powered by Nabble | Forum Help |