[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gnuradio-discuss
Subject:    Re: [Discuss-gnuradio] Custom GRC block not accepting derived class objects
From:       "Perez, Tracie R" <tracie.perez () mavs ! uta ! edu>
Date:       2015-02-24 22:04:34
Message-ID: FF5695CB-8677-45C8-9FEA-D05488EABB04 () mavs ! uta ! edu
[Download RAW message or body]

[Attachment #2 (text/plain)]


On Feb 23, 2015, at 9:30 AM, Tom Rondeau <tom@trondeau.com<mailto:tom@trondeau.com>> \
wrote:

On Mon, Feb 23, 2015 at 4:06 AM, Perez, Tracie R \
<tracie.perez@mavs.uta.edu<mailto:tracie.perez@mavs.uta.edu>> wrote: I'm hoping for \
suggestions from the GRC and swig savvy folks on the list.

I am trying to add LDPC functionality to gr-fec [1]. I made a GRC block for a decoder \
class. The decoder class constructor accepts a base class called fec_mtrx. In GRC, I \
am trying to give the decoder block an input of an object of a class derived from \
fec_mtrx, called ldpc_R_U_mtrx. The issue is that swig is giving an error that it \
expects the base class as the argument.

From the swig documentation, this type of inheritance and type checking seems to be \
fully supported and handled by swig. Is there something else I need to consider in \
either the block's cheetah template for the make call, or the swig files?

The organization of the classes is like:

class FEC_API ldpc_R_U_mtrx : public fec_mtrx  {    };

class FEC_API ldpc_bit_flip_decoder_impl : public ldpc_bit_flip_decoder
{
public:
    ldpc_bit_flip_decoder_impl(fec_mtrx *mtrx_obj, unsigned int max_iter=100);
}

And then in variable_ldpc_bit_flip_decoder.xml I've got: self.$(id) = $(id) = \
fec.ldpc_bit_flip_decoder.make($matrix_object, $max_iterations)

In my flowgraph, I provide the decoder block an input of a ldpc_R_U_mtrx variable, \
                and swig throws:
TypeError: in method 'ldpc_bit_flip_decoder_make', argument 1 of type \
'gr::fec::code::fec_mtrx *

So to me, it seems like swig is not recognizing that the ldpc_R_U_mtrx class derives \
from fec_mtrx. Not sure what to do about that except to try and "un-inherit" the \
classes and overload the decoder constructor...

Thanks for any tips,
tracie


[1] github.com/tracierenea/gnuradio/tree/ldpc_mods<http://github.com/tracierenea/gnuradio/tree/ldpc_mods>


Hey Tracie,

Unfortunately, I don't have a good, easy answer for you. It does seem like this \
should work fine. I'm trying to think of examples where we've done this before. The \
closest that I know of is with the constellation objects and something like the \
constellation_receiver that takes in just the base class. All of the function calls \
required are implemented in that base class, but overloaded by the child class. It \
also has a function ".base()" that returns the pointer to the child object as the \
base class so we can pass it through.

Figuring out how to get swig to work with the child class would probably be the \
better solution, but maybe you can use the constellation class model to get things \
going.

Tom



Thanks very much Tom for the feedback. I spent many more hours trying to get swig to \
work directly with the child class and could never figure out how, or find any clues \
about this issue in the swig documentation. So as a workaround, I've added a \
get_base_ptr() function to the child classes as you described that the constellation \
objects do.

I updated the xml file for the decoder to call the make function as: self.$(id) = \
$(id) = fec.ldpc_bit_flip_decoder.make(${matrix_object}.get_base_ptr(), \
$max_iterations)

Now everything is swig'ing and working great.

Thanks again,
tracie


[Attachment #3 (text/html)]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: \
after-white-space;" class=""> <br class="">
<div>
<blockquote type="cite" class="">
<div class="">On Feb 23, 2015, at 9:30 AM, Tom Rondeau &lt;<a \
href="mailto:tom@trondeau.com" class="">tom@trondeau.com</a>&gt; wrote:</div> <br \
class="Apple-interchange-newline"> <div class="">
<div dir="ltr" class="">
<div class="gmail_extra">
<div class="gmail_quote">On Mon, Feb 23, 2015 at 4:06 AM, Perez, Tracie R <span \
dir="ltr" class=""> &lt;<a href="mailto:tracie.perez@mavs.uta.edu" target="_blank" \
class="">tracie.perez@mavs.uta.edu</a>&gt;</span> wrote:<br class=""> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> I'm hoping for suggestions from the GRC and swig savvy folks \
on the list.<br class=""> <br class="">
I am trying to add LDPC functionality to gr-fec [1]. I made a GRC block for a decoder \
class. The decoder class constructor accepts a base class called fec_mtrx. In GRC, I \
am trying to give the decoder block an input of an object of a class derived from \
fec_mtrx,  called ldpc_R_U_mtrx. The issue is that swig is giving an error that it \
expects the base class as the argument.<br class=""> <br class="">
From the swig documentation, this type of inheritance and type checking seems to be \
fully supported and handled by swig. Is there something else I need to consider in \
either the block's cheetah template for the make call, or the swig files?<br \
class=""> <br class="">
The organization of the classes is like:<br class="">
<br class="">
class FEC_API ldpc_R_U_mtrx : public fec_mtrx&nbsp; {&nbsp; &nbsp; };<br class="">
<br class="">
class FEC_API ldpc_bit_flip_decoder_impl : public ldpc_bit_flip_decoder<br class="">
{<br class="">
public:<br class="">
&nbsp; &nbsp; ldpc_bit_flip_decoder_impl(fec_mtrx *mtrx_obj, unsigned int \
max_iter=100);<br class=""> }<br class="">
<br class="">
And then in variable_ldpc_bit_flip_decoder.xml I've got: self.$(id) = $(id) = \
fec.ldpc_bit_flip_decoder.make($matrix_object, $max_iterations)<br class=""> <br \
class=""> In my flowgraph, I provide the decoder block an input of a ldpc_R_U_mtrx \
                variable, and swig throws:<br class="">
TypeError: in method 'ldpc_bit_flip_decoder_make', argument 1 of type \
'gr::fec::code::fec_mtrx *<br class=""> <br class="">
So to me, it seems like swig is not recognizing that the ldpc_R_U_mtrx class derives \
from fec_mtrx. Not sure what to do about that except to try and "un-inherit&quot; the \
classes and overload the decoder constructor...<br class=""> <br class="">
Thanks for any tips,<br class="">
tracie<br class="">
<br class="">
<br class="">
[1] <a href="http://github.com/tracierenea/gnuradio/tree/ldpc_mods" target="_blank" \
class=""> github.com/tracierenea/gnuradio/tree/ldpc_mods</a></blockquote>
<div class=""><br class="">
</div>
<div class="">Hey Tracie,</div>
<div class=""><br class="">
</div>
<div class="">Unfortunately, I don't have a good, easy answer for you. It does seem \
like this should work fine. I'm trying to think of examples where we've done this \
before. The closest that I know of is with the constellation objects and something \
like the  constellation_receiver that takes in just the base class. All of the \
function calls required are implemented in that base class, but overloaded by the \
child class. It also has a function &quot;.base()&quot; that returns the pointer to \
the child object as the base class  so we can pass it through.</div>
<div class=""><br class="">
</div>
<div class="">Figuring out how to get swig to work with the child class would \
probably be the better solution, but maybe you can use the constellation class model \
to get things going.</div> <div class=""><br class="">
</div>
<div class="">Tom</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
</div>
</div>
</div>
</div>
</blockquote>
<br class="">
</div>
<div>Thanks very much Tom for the feedback. I spent many more hours trying to get \
swig to work directly with the child class and could never figure out how, or find \
any clues about this issue in the swig documentation. So as a workaround, I've added \
a get_base_ptr()  function to the child classes as you described that the \
constellation objects do.</div> <div><br class="">
</div>
<div>I updated the xml file for the decoder to call the make function as: self.$(id) \
= $(id) = fec.ldpc_bit_flip_decoder.make($<span class="x x-first \
x-last">{</span>matrix_object<span class="x x-first x-last">}.get_base_ptr()</span>, \
$max_iterations)</div> <div><br class="">
</div>
<div>Now everything is swig'ing and working great.&nbsp;</div>
<div><br class="">
</div>
<div>Thanks again,</div>
<div>tracie</div>
<br class="">
</body>
</html>



_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio

--===============4337103210510926443==--


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic