[C++-sig] Return policy for operator()
Grant Goodyear
grant at grantgoodyear.org
Mon Aug 22 23:53:37 CEST 2005
I have an image object that overloads operator() to handle array
subscripting of the object's image data by returning a float&. How do I
set the return policy for operator() in pyste?
I've attached some test fragments in case anybody wants to play along at
home.
Thanks,
Grant Goodyear
--
Grant Goodyear
web: http://www.grantgoodyear.org
e-mail: grant at grantgoodyear.org
-------------- next part --------------
class mymat {
int nx;
int ny;
float* data;
public:
mymat(int nx_, int ny_) : nx(nx_), ny(ny_) {
data = new float[nx*ny];
data[0] = 1.0f;
}
~mymat() { delete [] data; }
inline float& operator()(const int ix, const int iy) {
return *(data + ix + iy*nx);
}
};
-------------- next part --------------
Include("matobj.h")
mymat = Class("mymat", "matobj.h")
-------------- next part --------------
// Boost Includes ==============================================================
#include <boost/python.hpp>
#include <boost/cstdint.hpp>
// Includes ====================================================================
#include <matobj.h>
// Using =======================================================================
using namespace boost::python;
// Module ======================================================================
BOOST_PYTHON_MODULE(libpymatobj)
{
class_< mymat >("mymat", init< const mymat& >())
.def(init< int, int >())
.def("__call__", &mymat::operator ())
;
}
More information about the Cplusplus-sig
mailing list