[C++-sig] Type conversion problem
Randall Hopper
viznut at charter.net
Fri Nov 3 16:34:42 CET 2006
I'm trying to update the PyOSG wrappers to allow access to an array
type returned from a C++ class method.
All attempts to call a Python method on the returned array or it's
elements (even print it), result in a Boost.Python.ArgumentError (error msg
at bottom).
Here's the wrap of the array class (osg::Vec3Array):
namespace PyOSG {
void init_ArrayVec3()
{
TemplateCompArray<osg::Vec3Array, osg::Vec3> Vec3Array("Vec3Array");
}
}
and here's a piece of the referenced template:
using namespace boost::python;
template <typename T, typename BT>
class TemplateCompArray
{
public :
TemplateCompArray(const char * name) : _array(name, boost::python::no_init) {
_array
.def(init<>())
.def(init<int>())
.def("__init__", make_constructor(&create_from_tuple))
.def("getNumElements", &T::getNumElements)
.def("__getitem__", &getitem, return_internal_reference<>())
.def("__setitem__", &setitem, return_internal_reference<>())
.def("resize", &resize)
.def("__str__", &str)
...
static std::string str(T * self)
{
...
}
}
Any idea why printing (or calling a Python method of the wrapped Vec3Array
in Python should generate a type error? It's like boost.python doesn't
realize the TemplateCompArray instantiation "is" Vec3Array.
Thanks,
Randall
P.S. If you want to see the full source for context, check out:
http://mosca.caltech.edu/pyosg_downloads/pyosg_ads_15.tar.gz
and look in osg/ArrayVec3.cpp and include/TemplateCompArray.hpp.
------------------------------------------------------------------------------
Traceback (most recent call last):
...
File "osg_to_sgg.py", line 147, in setupGeode
print geom.getVertexArray()
Boost.Python.ArgumentError: Python argument types in
Vec3Array.__str__(Vec3Array)
did not match C++ signature:
__str__(osg::TemplateArray<osg::Vec3f, (osg::Array::Type)10, 3, 5126>*)
More information about the Cplusplus-sig
mailing list