[C++-sig] Re: yet another: TypeError: No to_python (by-value) converter found for C++ type:
tALSit de CoD
talsit at talsit.org
Tue Aug 24 04:22:32 CEST 2004
Thanks David....
I understand it more now, but, from what I've been trying to implement, it
still doesnt work.
Here's a simplification of the problem:
class A {
public:
const std::string & getName ();
private:
std::string m_name;
};
class B {
public:
const std::vector <A *> & getAs () { return m_listOfA; }
private:
std::vector <A *> m_listOfA;
};
Now, i try to export the classes:
boost::indirect_iterator <std::vector <A *>::iterator>
ABegin (std::vector <A *> & v) {
return boost::make_indirect_iterator (v.begin ());
};
boost::indirect_iterator <std::vector <A *>::iterator>
AEnd (std::vector <A *> & v) {
return boost::make_indirect_iterator (v.end ());
};
BOOST_PYTHON_MODULE (kikura) {
class_ <A> ("A")
.def ("getName", &A::getName, return_internal_reference <> ())
;
class_ <B> ("B")
.def ("getAs", &B::getAs, return_internal_reference <> ())
;
//----------------------------------------------------------------
class_ <std::vector <A *> > ("AList")
.def("__iter__", range (ABegin, AEnd))
;
}
Now, that will fail, and say that:
TypeError: No to_python (by-value) converter found for C++ type: class A
If I didn't use the range method, it would give me this:
TypeError: No to_python (by-value) converter found for C++ type: class A*
Any clues?
Thanks for all help...
> "tALSit de CoD" <talsit at talsit.org> writes:
>
>> Hmm... i've been trying to understand it, i've read the docs... but...
>> ummm... i can't quite understand it very well...
>>
>> Does this mean that when my class does:
>>
>> const std::vector <cNodeDescriptor *> cRegistry::getDescriptors ();
>>
>> i have to replace that with this:
>>
>> boost::indirect_iterator<std::vector<cNodeDescriptor*>::iterator>
>> cRegistry::getDescriptors ();
>
> I have no idea what getDescriptors is, so it's hard to comment.
>
>> Or am i just totally missing the point?
>>
>> Most of the template magic voodoo still baffels me... :D
>
> There's no template magic voodoo to understand this.
>
> Try using range
> (http://www.boost.org/libs/python/doc/v2/iterator.html#range-spec)
>
> Do you understand what range does?
>
> with functions that return
> boost::indirect_iterator<std::vector<cNodeDescriptor*>::iterator>
> wrapped around the vector's begin() and end().
> (http://www.boost.org/libs/iterator/doc/indirect_iterator.html)
>
> By this I mean
>
> boost::indirect_iterator<std::vector<cNodeDescriptor*>::iterator>
> my_begin(std::vector<cNodeDescriptor*>& v)
> {
> return boost::make_indirect_iterator(v.begin());
> };
>
> boost::indirect_iterator<std::vector<cNodeDescriptor*>::iterator>
> my_end(std::vector<cNodeDescriptor*>& v)
> {
> return boost::make_indirect_iterator(v.end());
> };
>
> so, something like:
>
> class_ <std::vector <cNodeDescriptor *> > ("cNodeDescriptorList")
> .def("__iter__", range(my_begin, my_end))
> ;
>
>
> HTH,
>
> --
> Dave Abrahams
> Boost Consulting
> http://www.boost-consulting.com
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
>
// talsit.org
More information about the Cplusplus-sig
mailing list