Re: [C++-sig] Pickle an enum from c++

2008-12-09 Thread Hans Meine
On Monday 08 December 2008 20:02:41 Roman Yakovenko wrote:
> 2008/12/8 Matthew Scouten (TT) <[EMAIL PROTECTED]>:
> > From the lack of response I assume that no one has any clever ideas to
> > make an enum pickleable.  Thank you to anyone who put thought into this.
> >
> :-).
>
> I thought about work around: you can define your enums in Python. May
> be youcan add this functionality from Python?
>
> Also did you see the following discussion?
> http://mail.python.org/pipermail/cplusplus-sig/2006-November/011372.html

Oh, this is continued here:
http://mail.python.org/pipermail/cplusplus-sig/2006-November/011376.html

Looks like there was a solution in 2006; Ralf even wanted to have a test case 
for check-in.  Ralf, did you receive stuff from Shashank back then?  (Or did 
you wait until today with committing the fix?)

Greetings,
  Hans
___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Pickle an enum from c++

2008-12-09 Thread Ralf W. Grosse-Kunstleve
Indeed (I had forgotten this already...):


r36256 | rwgk | 2006-12-03 12:43:48 -0800 (Sun, 03 Dec 2006) | 2 lines

fixes to support pickling of enums (by Shashank Bapat)




And there is this test (boost/libs/python/test/enum.py):

# pickling of enums only works with Python 2.3 or higher
exercise_pickling = '''
>>> import pickle
>>> p = pickle.dumps(color.green, pickle.HIGHEST_PROTOCOL)
>>> l = pickle.loads(p)
>>> identity(l)
enum_ext.color.green
'''

So this is supposed to work.



- Original Message 
From: Hans Meine <[EMAIL PROTECTED]>
To: Development of Python/C++ integration 
Cc: Ralf W. Grosse-Kunstleve <[EMAIL PROTECTED]>
Sent: Tuesday, December 9, 2008 4:40:17 AM
Subject: Re: [C++-sig] Pickle an enum from c++

On Monday 08 December 2008 20:02:41 Roman Yakovenko wrote:
> 2008/12/8 Matthew Scouten (TT) <[EMAIL PROTECTED]>:
> > From the lack of response I assume that no one has any clever ideas to
> > make an enum pickleable.  Thank you to anyone who put thought into this.
> >
> :-).
>
> I thought about work around: you can define your enums in Python. May
> be youcan add this functionality from Python?
>
> Also did you see the following discussion?
> http://mail.python.org/pipermail/cplusplus-sig/2006-November/011372.html

Oh, this is continued here:
http://mail.python.org/pipermail/cplusplus-sig/2006-November/011376.html

Looks like there was a solution in 2006; Ralf even wanted to have a test case 
for check-in.  Ralf, did you receive stuff from Shashank back then?  (Or did 
you wait until today with committing the fix?)

Greetings,
  Hans

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Custom from-python converter (almost working)

2008-12-09 Thread Paul Melis
Ralf W. Grosse-Kunstleve wrote:
>> In SWIG it is possible to simply define an extra class method that takes a
>> PyObject* and perform any conversion you want in that method (although
>> this means having to add that extra method for all cases where the
>> non-const pointer is used). Would something similar work in Boost.Python,
>> e.g.
>>
>> class C
>> {
>> public:
>> void set_data(data* d);
>> };
>>
>> void
>> extra_method(C& self, PyObject *obj)
>> {
>> // if obj is list of tuples, convert to
>> // data* and
>> // call self.set_data(d)
>> }
>>
>> class_("C")
>>   .def("set_data", &C::set_data)
>>   .def("set_data", &C::extra_method)
>> ;
>> 
>
> Yes, this should work if you use boost::python::object:
>
>   void
>   extra_method(C& self, boost::python::object obj)
>
> The conversion code in the body of this function will probably be
> similar to what you see in the container_conversion.h file.
>
> You could also use
>
>   void
>   extra_method(C& self, boost::python::list list_of_tuples)
>
> which will save you one manual conversion step.
>   
Hey, that's really nice! I'll try that...

Thanks,
Paul

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig


Re: [C++-sig] Getting address of wrapped instance?

2008-12-09 Thread Paul Melis
Roman Yakovenko wrote:
> On Mon, Dec 8, 2008 at 6:42 PM, Stefan Seefeld <[EMAIL PROTECTED]> wrote:
>   
>> Hans Meine wrote:
>> 
>>> How about adding an id() method (returning this) to the C++ class and
>>> exporting that?
>>>
>>>   
>> Well, this 'id' isn't really a property of the wrapped type / object, but
>> the wrapper. So, I think there is little sense in adding such a tautological
>> 'id' function to the class itself. A free-standing
>>
>> type const *id(type const *t) { return t;}
>>
>> function would be more clean, IMO.
>> 
>
> I think he wants size_t as return type:
>
> template< class type >
> size_t id( const type* t ){ return size_t( t ); }
>
> class_< XXX >()
> .def( "id", &id );
>
>   
This is indeed what I was looking for, thanks!

Paul
> Py++ has this and other functionality to allow better experience,
> while exposing "C" libraries:
>
> http://language-binding.net/pyplusplus/documentation/ctypes/ctypes_integration.html
> http://language-binding.net/pyplusplus/documentation/ctypes/this_and_sizeof.html
>
>   

___
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig