[pygccxml-development] Wrapping C++ methods with std::vector<> arguments
Brought to you by:
mbaas,
roman_yakovenko
From: Norma Z. <nzi...@is...> - 2008-02-13 23:23:09
|
I am having trouble wrapping C++ functions that have vectors as an argument. Ultimately, I want to be able to wrap functions with a signature similar to: UserDefinedReturnValue getDevice(std::vector<UserDefinedClass> & device) At the present time, I cannot correctly wrap the function getTimeVector from the following class. #include <string> #include <iostream> #include <vector> using namespace std; class ISS { public: ISS(); void getTimeVector( std::vector<int> &); protected: int hour; int minute; int second; }; In my generate_ISS.py module, I am adding nothing for the vector and am using the default import os from pyplusplus import module_builder from pyplusplus import function_transformers as FT #Creating an instance of class that will help you to expose your declarations mb = module_builder.module_builder_t( [r"C:/NJZsBoost/userAgent/real/ISS.h"] , gccxml_path=r"C:/gccxml/build/bin/debug/gccxml.exe" , working_directory=r"C:/NJZsBoost/userAgent/real" , include_paths=['C:/NJZsBoost/userAgent/real'] , define_symbols=[] ) #Well, don't you want to see what is going on? mb.print_declarations() #Creating code creator. After this step you should not modify/customize declarations. mb.build_code_creator( module_name='py_ISS' ) #Writing code to file. mb.write_module( './py_ISS.cpp' ) My generated file contains the following. // This file has been generated by Py++. #include "boost/python.hpp" #include "__convenience.pypp.hpp" #include "__call_policies.pypp.hpp" #include "boost/python/suite/indexing/vector_indexing_suite.hpp" #include "c:/njzsboost/useragent/real/iss.h" namespace bp = boost::python; BOOST_PYTHON_MODULE(py_ISS){ bp::class_< std::vector< int > >("vector_less__int__grate_") .def( bp::vector_indexing_suite< ::std::vector< int >, true >() ); bp::class_< ISS >( "ISS" ) .def( bp::init< >() .def( "getTimeVector" , &::ISS::getTimeVector , ( bp::arg("arg0") ) } When I attempt to use the output from this, I get the following error message. >>> my_iss.getTimeVector() Traceback (most recent call last): File "<stdin>", line 1, in <module> Boost.Python.ArgumentError: Python argument types in ISS.getTimeVector(ISS) did not match C++ signature: getTimeVector(class ISS {lvalue}, class std::vector<int, class std::allocator<int> > {lvalue} arg0) I would appreciate it if you would show me an example similar to this. I would like to see: 1. what I should have in the pyplusplus.py file (my generate_ISS.py file) 2. what I should expect to see in the generated cpp file (my py_ISS.cpp file) 3. how I use the wrapped function from python I am sorry for the chopped up examples but when I tried to send you a zipped folder containing a complete set of files, it was rejected because it was zipped. When I tried to attach the files, it was rejected because it was too large. I do have many things working in the class. I was able to get all the function transformations working. I have stripped all these from the files to save space. I am using Pyplusplus-0.9.5 and pygccxml-0.9.5. Thanks for any help you can give me. Norma |