[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] Sub-classing a block defined in an _impl class
From: |
Marcus Müller |
Subject: |
Re: [Discuss-gnuradio] Sub-classing a block defined in an _impl class |
Date: |
Fri, 10 Oct 2014 16:54:04 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I think it might be more of a C++-inherent thing:
If you declare a method in a class:
class daniele_s_class {
public:
void my_method(int argument);
};
Then you'll have to either implement that method, or can't instantiate
the class -- which is kind of correct, if you think about it, because
that class is simply incomplete. But it's not too bad, either, because
noone ever should instantiate daniele_s_class, it's just meant to
define the interface. That's why we have the "make", which will return
a new instance of the _impl subclass. So, schematically, the GNU Radio
way of doing this is:
class daniele_s_class {
public:
virtual void my_method(int argument) = 0; //this tells the compiler
that there is a method that a instantiable subclass *must* implement
static sptr make();
};
daniele_s_class::sptr daniele_s_class::make(){
return sptr(new daniele_s_class_impl());
}
class daniele_s_class_impl{
public:
virtual void my_method(int argument);
};
void daniel_s_class_impl::my_method(int argument){
//do whatever here :)
}
Greetings,
Marcus
On 10.10.2014 15:24, Daniele Nicolodi wrote:
> On 10/10/14 14:29, Daniele Nicolodi wrote:
>> I copied the _impl definition, however, I would prefer to do not
>> copy the interface definition, therefore I defined my block as
>> follows:
>>
>> namespace gr { namespace baz {
>>
>> class BAZ_API pll_carriertracking_cc : public
>> gr::analog::pll_carriertracking_cc { public: typedef
>> boost::shared_ptr<pll_carriertracking_cc> sptr; static sptr
>> make(float loop_bw, float max_freq, float min_freq); };
>>
>> } // namespace baz } // namespace gr
>>
>> Then I copied the definition of the pll_carriertracking_cc_impl
>> class implementation into my project and changed it where I
>> wanted.
>>
>> However, in this way, swig is not happy:
>
> It seems to be a limitation of SWIG (which I don't know much, so I
> may still be doing something wrong). If I define a virtual method
> in the definition of my block interface, SWIG generates the correct
> C++ code.
>
> I ended up adding a definition for the work() virtual method to fix
> the issue. Again, not the most elegant thing to do, but it
> works...
>
> Cheers, Daniele
>
>
> _______________________________________________ Discuss-gnuradio
> mailing list address@hidden
> https://lists.gnu.org/mailman/listinfo/discuss-gnuradio
>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
iQEcBAEBAgAGBQJUN/MMAAoJEAFxB7BbsDrLE50H/3QvMRf996L3SA9UGAJ6mKIz
1Dd3mfrLN05kgm75UVr1HYwlbEMpZykL7g5sYyIgB7wOfiLKFWElUHQ03HwPFjFK
MAT7SS/l4Pd8DrSwJefqTARHWCaqSM2Y/rv8eu3eSh9/IvaZNZqDfeWMF5xxtuuD
2gbilF77Dh5jSiYMGjXuMpoGgYcdsLznAvSmLft2a6/k0mX1EcsbNu4VWD8++wzO
rcyv09Da+szs/SY/GwweLl+qFTQCLGMmQg36Ol4SmWpfeXpkMTE1IHaKh2OgzK63
ghNcRPSjZE2l4NKMk+bOSPq8gaLT+IQW2crLHxszVNEhScCPjlRx3IJ342DM+yY=
=51/2
-----END PGP SIGNATURE-----