On Thu, Feb 14, 2008 at 1:23 AM, Norma Zimmerman <nzi...@is...> wrote:
> 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)
>
getTimeVector expects 1 argument, if you don't count self, try
times_vector = py_ISS.vector_less__int__grate_()
my_iss.getTimeVector( times_vector )
This should work
>
> 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)
Nothing, the problem was in your Python code. I suggest you to read
this document:
http://language-binding.net/pyplusplus/documentation/how_to/hints.html#class-template-instantiation-alias
> 2. what I should expect to see in the generated cpp file (my py_ISS.cpp
> file)
Nothing :-), the generated code works. Py++ has excellent unit tests (
http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/
)
> 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.
>
As for me this post is a good example of how the problems should be presented.
>
> Thanks for any help you can give me.
HTH
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
|