|
From: Marcelo M. <mm...@ac...> - 2006-01-17 17:23:41
|
Yes, grab the last cvs version and do
%extend {
void each() {
static swig_type_info *desc =3D SWIG_TypeQuery(#ELEM " *");
MyList<ELEM>::ConstIterator i;
for (i=3Dself->begin(); i!=3Dself->end(); ++i)
rb_yield(SWIG_NewPointerObj((void *) &(*i), desc, 0));
}
}
nerochiaro wrote:
>Hello,
>I'm rather new to SWIG and trying to write Ruby bindings for a C++ libra=
ry.
>I have a std::vector-like template class that I have successfully
>wrapped so far.
>The only problem comes when I try to extend it to create a function
>that implements the typical "each" ruby iterator method. For non-ruby
>programmers, what it does is to iterate across all elements of the
>vector and call the ruby API function rb_yield(item) for each one.
>The problem lies in the fact that rb_yield expects a ruby object as
>input parameter (type VALUE).
>The following code works, but has a problem (see below):
>
>template <class ELEM> class MyList
>{
>public:
> %extend {
> void each() {
> MyList<ELEM>::ConstIterator i;
> for (i=3Dself->begin(); i!=3Dself->end(); ++i)
> rb_yield(SWIG_NewPointerObj((void *) &(*i), $descriptor(ELEM *), 0)=
);
> }
> }
>}
>
>The problem is that if there are typemaps defined for the ELEM type
>they won't get applied by SWIG_NewPointerObj.
>=09
>I could simply provide a different implementation of each() for any
>specialization that have a typemap defined for, but that gets old very
>fast and kind of misses the point of using templates in the first
>place.
>
>So I was wondering if there was a more elegant (=3D=3D automated) way to=
do it.
>What I'm looking for is something that works like SWIG_NewPointerObj
>but that also applies typemaps.
>Does something like that exist ? If not, can anyone suggest alternatives=
?
>
>Thanks in advance.
>
>
>-------------------------------------------------------
>This SF.net email is sponsored by: Splunk Inc. Do you grep through log f=
iles
>for problems? Stop! Download the new AJAX search engine that makes
>searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
>http://sel.as-us.falkag.net/sel?cmd=FFk&kid=103432&bid#0486&dat=121642
>_______________________________________________
>Swig-user mailing list
>Swi...@li...
>https://lists.sourceforge.net/lists/listinfo/swig-user
>
> =20
>
|