Re: [C++-sig] How to get items from a tuple

2009-01-16 Thread Ricardo Abreu
Thank you, but I had tried that and it doesn't seem to work... look: 
http://codepad.org/kA61P8r0


What am I doing wrong?

Thanks,
Ricardo Abreu

David Abrahams wrote:

on Thu Jan 15 2009, Ricardo Abreu  wrote:


Hello,

How do I extract elements from a tuple that I receive from python?
boost::python::tuple doesn't seem to have anything for that in its interface...


  t[n]

is the nth element of tuple t.



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


Re: [C++-sig] How to get items from a tuple

2009-01-16 Thread Stefan Seefeld

Ricardo Abreu wrote:
Thank you, but I had tried that and it doesn't seem to work... look: 
http://codepad.org/kA61P8r0


What am I doing wrong?


In the sake of understanding the code a little better you may write it a 
bit less compact. Then you will realize that the item extraction you 
were asking about is in fact working fine. However, as it returns an 
object, not an int, you still need to extract the C++ type properly. 
Just using C casts doesn't work. (Read the docs.)



Regards,
  Stefan


--

 ...ich hab' noch einen Koffer in Berlin...

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


Re: [C++-sig] How to get items from a tuple

2009-01-16 Thread Ricardo Abreu
Well, thank you. The problem was really that I didn't notice I had to 
extract the int explicitly.


About the code being too compact, I'm not sure I got what you mean, 
unless you would want me to have a variable in between the tuple and the 
print just to hold the result of the cast, in which case I don't agree 
you would gain on readability - you would see a cleaner print but you 
would have to track another variable, and I really don't think that 
(int)t[0] is that difficult to understand.


Anyway, thanks again,
Ricardo

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


Re: [C++-sig] How to get items from a tuple

2009-01-16 Thread Stefan Seefeld

Ricardo Abreu wrote:
Well, thank you. The problem was really that I didn't notice I had to 
extract the int explicitly.


About the code being too compact, I'm not sure I got what you mean, 
unless you would want me to have a variable in between the tuple and 
the print just to hold the result of the cast, in which case I don't 
agree you would gain on readability - you would see a cleaner print 
but you would have to track another variable, and I really don't think 
that (int)t[0] is that difficult to understand.
I'm not saying the code itself is too compact. My point was that often 
there is a lot going on in the evaluation of a single expression. As 
long as all works fine, that's good, but when something fails it might 
be a good idea to dissect the statement to see what is actually 
happening, step by step.


Regards,
  Stefan

--

 ...ich hab' noch einen Koffer in Berlin...

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


Re: [C++-sig] py++ with template member function of template class

2009-01-16 Thread Maik Beckmann
Roman Yakovenko  gmail.com> writes:
> > /
> > // test template member function in template class
> > // THIS WON'T WORK!
> > template 
> > class BFunc
> > {
> > public:
> > template 
> > T foo(const T& t) const;
> > };
> >
> > template  template 
> > T BFunc::foo(const T& t) const { return t + 1; };
> >
> 
> Unfortunately GCC-XML doesn't dump the information. I am also not
> aware of any workaround .
> 
> You will have to create the code by yourself. Py++ allows you to
> integrate your code easily(
> http://language-binding.net/pyplusplus/documentation/inserting_code.html
> )

In this mail
  http://www.mail-archive.com/gcc...@gccxml.org/msg00316.html
Brad King, author of gccxml, confirms that this isn't implemented.  

I hope as gccxml gets more and more popular (i.e. the CERN started using it to
get C++ reflection) someone will continue Brads good work.  He stated in the
mail that he is willing to help get people started.

-- Maik   


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


Re: [C++-sig] can boost::python class imlement buffer protocol?

2009-01-16 Thread Neal Becker
Neal Becker wrote:

> David Abrahams wrote:
> 
>> 
>> on Wed Jan 07 2009, Neal Becker  wrote:
>> 
>>> This would require filling in tp_as_buffer field in the PyTypeObject
>>> structure for the
>>> class.  Is this possible?  Any clue how/where this could be done?
>> 
>> I honestly don't know the answers to these questions, sorry.
>> 
> 
> As a workaround, I currently implemented an 'as_buffer' member function.
> For example:
> 
> template
> inline object as_buffer (ublas::vector & m) {
>   return object (handle<> (PyBuffer_FromReadWriteMemory
>   ((void*)(&m.data()[0]), m.size()*sizeof(T;
> }

Actually, this isn't all that useful.  The problem is, you want to use 
with_custodian_and_ward_postcall<0,1> on this.  But you can't because buffer 
object doesn't support weak references.  So while the above can provide a 
buffer interface, it has no idea of lifetime management.

I wonder whether python buffer object could be made to support weak refs?  Of 
course, if there was really a way to add a buffer interface to my 
boost::python object that would be even better.


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