Re: [C++-sig] [Py++] Indexing suite 2: missing methods
On Sat, Feb 13, 2010 at 8:05 PM, Roman Yakovenko
wrote:
> On Sat, Feb 13, 2010 at 5:41 PM, peoro wrote:
>> Hello,
>> I noticed that some Py++ traits for standard containers are missing a
>> few methods that I think would be needed.
>> For example `set_traits' (container traits for `std::set') is missing
>> `method_len' that, in my opinion, should be provided.
>
> It is provided.
>
>> Is this a feature or a bug? And in the former case, how would I be
>> supposed to get a set's size? explicitly exposing a `size' function
>> for it?
>
> Did you try len( x )?
>
Yes, I tried and it isn't working.
This is the C++ code I'm trying to expose using Py++:
#include
std::set f( ) {
return std::set();
}
Then, in python:
>>> from set_len_test import *
>>> x = f()
>>> len( x )
Traceback (most recent call last):
File "", line 1, in
TypeError: object of type 'set_less__int__greater_' has no len()
If I manually add `method_len' to `supported_methods' in
`indexing_suite/set.hpp', and compile again the module, everything
works as it should:
>>> from set_len_len import *
>>> x = f()
>>> len( x )
0
I've been trying with SVN revisions 1814 and 1824.
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/
> ___
> Cplusplus-sig mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/cplusplus-sig
>
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [Py++] Indexing suite 2: missing methods
On Sun, Feb 14, 2010 at 6:22 PM, peoro wrote: > On Sat, Feb 13, 2010 at 8:05 PM, Roman Yakovenko > wrote: >> Did you try len( x )? >> > > Yes, I tried and it isn't working. > ... > I've been trying with SVN revisions 1814 and 1824. Can you create small and complete example? ( C++ code, Py++ script and Py++ generated code )? Thanks -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
[C++-sig] [Boost.Python] Wrapping C library functions
Suppose I am attempting to use a C (not C++) library that has an .h file with things like this: extern PIX * pixCreate ( l_int32 width, l_int32 height, l_int32 depth ); extern void pixDestroy ( PIX **ppix ); extern PIX * pixClone ( PIX *pixs ); extern PIX * pixCopy ( PIX *pixd, PIX *pixs ); Is it possible to use Boost.Python to wrap such functions? In particular, note that pixDestroy() is going to want the address of the pointer returned by pixCreate(). (This is from the leptprotos.h file of the Leptonica Image Processing library at leptonica.com) ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [Boost.Python] Wrapping C library functions
If you want to wrap the library in C I believe you will have to use the standard python API, as boost requires C++ features. It sounds like you do not want to write a wrapper library and instead add code to leptonica to make it python import-able. I would not suggest this approach. If you want to write a wrapper around the C library in C++ you can use boost python, then in python you would import your wrapper which would allow you to use the C library in python using your C++ wrapper functions. If you just want to add code to this library and make it work in python immediately check out SWIG, although I am not sure if swig produces cpython code or boost python C++ code. On Sun, Feb 14, 2010 at 6:32 PM, TP wrote: > Suppose I am attempting to use a C (not C++) library that has an .h file > with things like this: > > extern PIX * pixCreate ( l_int32 width, l_int32 height, l_int32 depth ); > extern void pixDestroy ( PIX **ppix ); > > extern PIX * pixClone ( PIX *pixs ); > extern PIX * pixCopy ( PIX *pixd, PIX *pixs ); > > Is it possible to use Boost.Python to wrap such functions? > > In particular, note that pixDestroy() is going to want the address of the > pointer returned by pixCreate(). > > (This is from the leptprotos.h file of the Leptonica Image Processing > library at leptonica.com) > > > ___ > Cplusplus-sig mailing list > [email protected] > http://mail.python.org/mailman/listinfo/cplusplus-sig > ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [Boost.Python] Wrapping C library functions
On 02/14/2010 07:32 PM, TP wrote:
Suppose I am attempting to use a C (not C++) library that has an .h
file with things like this:
extern PIX * pixCreate ( l_int32 width, l_int32 height, l_int32 depth );
extern void pixDestroy ( PIX **ppix );
extern PIX * pixClone ( PIX *pixs );
extern PIX * pixCopy ( PIX *pixd, PIX *pixs );
Is it possible to use Boost.Python to wrap such functions?
Yes. Do you have the definition of PIX available ? In that case, you
could use that via class_
Otherwise, you may want to create a tiny wrapper class for it, such as
class PIXWrapper
{
public:
PIXWrapper(I_int32 w, I_int32 h, I_int32 d) : pix_(pixCreate(w, h, d) {}
~PIXWrapper() { pixDestroy(&pix_);}
...
private:
PIX *pix_;
};
and then use that in the way described in the docs.
HTH,
Stefan
--
...ich hab' noch einen Koffer in Berlin...
___
Cplusplus-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] [Boost.Python] Wrapping C library functions
On Mon, Feb 15, 2010 at 2:32 AM, TP wrote: > Suppose I am attempting to use a C (not C++) library that has an .h file > with things like this: > > extern PIX * pixCreate ( l_int32 width, l_int32 height, l_int32 depth ); > extern void pixDestroy ( PIX **ppix ); > > extern PIX * pixClone ( PIX *pixs ); > extern PIX * pixCopy ( PIX *pixd, PIX *pixs ); > > Is it possible to use Boost.Python to wrap such functions? Definitely, but the price will be too high. If the library coded in "C" only than you can use ctypes module to access the functionality. You will get pure-Python solution. There are even few code generators out there, that will happily generate initial ctypes code for you. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/cplusplus-sig
