[C++-sig] Very New to Boost Python
Roman Yakovenko
roman.yakovenko at gmail.com
Fri May 11 21:14:20 CEST 2007
On 5/11/07, Ajay Murthy <ajay.murthy at philips.com> wrote:
>
> Hi All,
>
> I am very new to Boost.Python and I am facing the following problem.
>
> Here is my C++ class declaration:
>
> class Matrix
> {
> public:
> Matrix(int rows, int cols);
> Matrix(const Matrix& m);
> inline int GetCols() { return numCols;}
> inline int GetRows() { return numRows;}
> int** Get_Buffer();
> void SetStride(int x, int y);
> Matrix& operator*(const Matrix& m);
> Vector& operator[](int index);
> Matrix& operator=(const Matrix& m);
> private:
> void SetSize(int rows, int cols);
> int numCols, numRows;
> Vector* matrix;
> int ystride;
>
> };
>
> And the corresponding Boost.Python wrapper is
>
> BOOST_PYTHON_MODULE(DataTypes)
> {
> class_<Matrix>("Matrix", init<int, int>())
> .def("GetCols", &Matrix::GetCols)
> .def("GetRows", &Matrix::GetRows)
> .def("SetStride", &Matrix::SetStride)
> //.def("Get_Buffer", &Matrix::Get_Buffer)
> //.def(self * self)
> //.def(__getitem__(self, int)
> //.def(__setitem__(self, int, int)
> ;
> }
>
You have to expose class Vector too and may be to define call policies.
>
> As you might have already observed, I have commented out few lines in the
wrapper. If i uncomment it, bjam doesnt work.
> From the initial analysis it seems to be a problem with the methods which
accepts/returns arguments other than the primitive types. I may be wrong
here.
>
> Anyways, could anyone please explain me what the problem could be and the
solution for the same.
You cannot export Get_Buffer, cause Python doesn't expose its user to
low-level details such as int**, so does Boost.Python. The are few possible
solution, one of them is to use custom return policies. I needed to expose
the functionality similar to yours, so I create such call policy:
http://www.language-binding.net/pyplusplus/documentation/functions/call_policies.html#return-range
> Also, it would help if you could point me to some good documentation. The
documentation in the boost.python page is very helpful for basic
understanding but not after that.
http://www.language-binding.net/pyplusplus/links.html#help-resources
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20070511/84f5e39b/attachment.htm>
More information about the Cplusplus-sig
mailing list